diff options
| -rw-r--r-- | Mailman/Utils.py | 213 |
1 files changed, 0 insertions, 213 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py index 889ce3366..f67bdc6b2 100644 --- a/Mailman/Utils.py +++ b/Mailman/Utils.py @@ -132,210 +132,6 @@ def wrap(text, column=70): -def SendTextToUser(subject, text, recipient, sender, add_headers=[]): - import Message - msg = Message.OutgoingMessage() - msg['From'] = sender - msg['Subject'] = subject - msg.body = QuotePeriods(text) - DeliverToUser(msg, recipient, add_headers=add_headers) - - - -_children = [] - -def DeliverToUser(msg, recipient, add_headers=[]): - """Use smtplib to deliver message. - - Optional argument add_headers should be a list of headers to be added - to the message, e.g. for Errors-To and X-No-Archive.""" - # HM: I don't think the deadlock comment below really applies - # anymore (because we now send mail with SMTP, not by invoking some - # binary). Thus the forking should probably go away (eventually, - # i.e. when we're sure that won't break stuff). For now, trying to - # approach 1.0, I've only moved the forking down a bit. - # - # We fork to ensure no deadlock. Otherwise, even if sendmail is - # invoked in forking mode, if it eg detects a bad address before - # forking, then it will try deliver to the errorsto addr *in the - # foreground*. If the errorsto happens to be the list owner for a list - # that is doing the send - and holding a lock - then the delivery will - # hang pending release of the lock - deadlock. - global _children - sender = msg.GetSender() - try: - msg.headers.remove('\n') - except ValueError: - pass - if not msg.getheader('to'): - msg.headers.append('To: %s\n' % recipient) - for i in add_headers: - if i and i[-1] != '\n': - i = i + '\n' - msg.headers.append(i) - text = string.join(msg.headers, '') + '\n' + QuotePeriods(msg.body) - import OutgoingQueue - queue_id = OutgoingQueue.enqueueMessage(sender, recipient, text) - # If the fork (or anything the child does) fails and raises an - # exception, e.g. due to memory exhaustion, the queue runner - # will pick up the queue file. - try: - pid = os.fork() - if pid: - # in the parent - _children.append(pid) - else: - # in the child - try: - TrySMTPDelivery(recipient,sender,text,queue_id) - finally: - os._exit(0) - except: - OutgoingQueue.deferMessage(queue_id) - - -def Reap(): - global _children - try: - pid, sts = os.waitpid(-1, os.WNOHANG) - try: - _children.remove(pid) - except ValueError: - pass - except os.error: - pass - return len(_children) - - - -def TrySMTPDelivery(recipient, sender, text, queue_entry): - import socket - import OutgoingQueue - from Logging.StampedLogger import StampedLogger - # We need to get a modern smtplib. The Python 1.5.1 version does not - # support ehlo (ESMTP), but the Python 1.5.2 version does. However, the - # interface to conn.ehlo() has changed between Python 1.5.2beta and 1.5.2 - # final. Also, there was a patch to smtplib.py after Python 1.5.2 final - # was released. For all these reasons we import smtplib directly out of - # the Mailman.pythonlib package. This contains the latest (as of - # 27-Apr-1999) smtplib.py file from the Python CVS tree. - from Mailman.pythonlib import smtplib - try: - conn = smtplib.SMTP(mm_cfg.SMTPHOST) - # Do the EHLO/HELO manually so we can check for DSN support - if conn.ehlo()[0] >= 400: - conn.helo() - # receipt opts, empty unless DSN is supported, in which case we only - # want notification on failures - ropts = [] - if conn.has_extn('dsn'): - ropts.append('NOTIFY=failure') - # With a global listmember database, we could intercept RCPT errors - # here to disable/remove bad local addresses. Currently we don't - # know which list(s) the address is on :( - refused = conn.sendmail(sender, recipient, text, rcpt_options=ropts) - # - # debugging - # -## l = StampedLogger('smtp-delivery', 'TrySMTPDelivery', immediate=1) -## sys.stdout = l -## try: -## print 'SMTP delivery:', -## if refused: print 'partial' -## else: print 'full' -## print 'queue_entry:', queue_entry -## print 'sender:', sender -## print 'recipient:', recipient -## if md5: -## texthash = md5.new(text).digest() -## x = [] -## for c in texthash: -## z = hex(ord(c))[2:] -## if len(z) == 1: z = '0'+z -## x.append(z) -## print 'md5 of text:', string.join(x, '') -## if refused: -## print 'refused:', refused -## finally: -## sys.stdout = sys.__stdout__ - # - # end debugging - # - conn.quit() - defer = 0 - failure = None - # Any exceptions that warrant leaving the message on the queue should be - # identified by their exception, below, with setting 'defer' to 1 and - # 'failure' to something suitable. Without a particular exception we fall - # through to the blanket 'except:', which dequeues the message. - # - except (# MTA not responding, or other socket prob - socket.error, - # Unusual HELO response, hopefully due to transient problems - smtplib.SMTPHeloError): - # Leave the message on queue - defer = 1 - failure = sys.exc_info() - log_hint = "Maybe your MTA daemon needs restarting?" - except smtplib.SMTPSenderRefused: - # Leave message on queue, hoping problem (which probably has to - # do with "relaying restrictions") will be fixed shortly - defer = 1 - failure = sys.exc_info() - # Try to notify local mailman-owner of the problem by email -- - # unless the failure is on the mailman-owner address (in which - # case the MTA configuration is _seriously_ screwed up) - log_hint = ("MTA '%s' relaying restrictions probably " - "too strict" % mm_cfg.SMTPHOST) - admin = mm_cfg.MAILMAN_OWNER - if sender <> admin: - pass -# SendTextToUser(log_hint, """\ -# Mailman currently isn't allowed to send mail with sender address -# -# %(sender)s -# -# In order for your Mailman installation to function properly, sending -# from this address should be allowed. -# -# The most common cause of such a problem is the MTA's relaying -# restrictions being set too tight. You should in your case check the -# MTA running on '%(mta_host)s'. -# -# As Mailman tries to be MTA independent, you will have to look in your -# MTA manuals for instructions on how to change it's relaying -# restriction configuration.""" % {'sender': sender, -# 'mta_host': mm_cfg.SMTPHOST}, -# admin, admin) - else: - log_hint = log_hint + " -- even for sender '%s'" % admin - except: - # Unanticipated cause of delivery failure - *don't* leave message - # queued, or it may stay, with reattempted delivery, forever... - defer = 0 - failure = sys.exc_info() - log_hint = "" - - if defer: - OutgoingQueue.deferMessage(queue_entry) - else: - OutgoingQueue.dequeueMessage(queue_entry) - if failure: - t, v = failure[0], failure[1] - # XXX Here may be the place to get the failure info back to the list - # object, so it can disable the recipient, etc. But how? - l = StampedLogger("smtp-failures", "TrySMTPDelivery", immediate=1) - l.write("To %s:\n" % recipient) - l.write("\t %s" % t) - if v: - l.write(' / %s' % v) - l.write(' (%s)\n' % (defer and 'deferred' or 'dequeued')) - if log_hint: - l.write(' %s\n' % log_hint) - l.flush() - - - def QuotePeriods(text): return string.join(string.split(text, '\n.\n'), '\n .\n') @@ -573,15 +369,6 @@ def MakeRandomPassword(length=4): -def SnarfMessage(msg): - if msg.unixfrom: - text = msg.unixfrom + string.join(msg.headers, '') + '\n' + msg.body - else: - text = string.join(msg.headers, '') + '\r\n' + msg.body - return (msg.GetSender(), text) - - - def QuoteHyperChars(str): arr = regsub.splitx(str, '[<>"&]') i = 1 |
