~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/mail/sendmail.py

  • Committer: William Grant
  • Date: 2011-09-24 02:32:44 UTC
  • mto: (14022.3.12 death-of-ztm)
  • mto: This revision was merged to the branch mainline in revision 14029.
  • Revision ID: william.grant@canonical.com-20110924023244-a8vo0fo2f6nxpan5
sendmail no longer depends on ZopelessTransactionManager. It uses a module global instead of a class member, and ZTM sets that global.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
from zope.sendmail.interfaces import IMailDelivery
52
52
 
53
53
from canonical.config import config
54
 
from canonical.database.sqlbase import ZopelessTransactionManager
55
54
from lp.app import versioninfo
56
55
from lp.services.encoding import is_ascii_only
57
56
from lp.services.mail.stub import TestMailer
64
63
Charset.add_charset('utf-8', Charset.SHORTEST, Charset.QP, 'utf-8')
65
64
Charset.add_alias('utf8', 'utf-8')
66
65
 
 
66
 
67
67
def do_paranoid_email_content_validation(from_addr, to_addrs, subject, body):
68
68
    """Validate various bits of the email.
69
69
 
161
161
    return format_address(person.displayname, email_address)
162
162
 
163
163
 
 
164
_immediate_mail_delivery = False
 
165
 
 
166
 
 
167
def set_immediate_mail_delivery(enabled):
 
168
    """Enable or disable immediate mail delivery.
 
169
 
 
170
    Mail is by default queued until the transaction is committed. But if
 
171
    a script requires that mail violate transactions, immediate mail
 
172
    delivery can be enabled.
 
173
    """
 
174
    global _immediate_mail_delivery
 
175
    _immediate_mail_delivery = enabled
 
176
 
 
177
 
164
178
def simple_sendmail(from_addr, to_addrs, subject, body, headers=None,
165
179
                    bulk=True):
166
180
    """Send an email from from_addr to to_addrs with the subject and body
422
436
 
423
437
    raw_message = message.as_string()
424
438
    message_detail = message['Subject']
425
 
    if ZopelessTransactionManager._installed is not None:
 
439
    if _immediate_mail_delivery:
426
440
        # Zopeless email sending is not unit tested, and won't be.
427
441
        # The zopeless specific stuff is pretty simple though so this
428
442
        # should be fine.