summaryrefslogtreecommitdiff
path: root/Mailman/Message.py
diff options
context:
space:
mode:
authorBarry Warsaw2007-08-01 16:11:08 -0400
committerBarry Warsaw2007-08-01 16:11:08 -0400
commitf8a6c46455a409125dcc0fcace7d7116898b0319 (patch)
tree4d1c942d92e4b63eb8f000e25477079c14bb5346 /Mailman/Message.py
parentd72336c1e5932158f6e1f80e5ea9e90d264b7c52 (diff)
parent7a7826e112a1d3f1999cb7a11e6df98cfcb712c9 (diff)
downloadmailman-f8a6c46455a409125dcc0fcace7d7116898b0319.tar.gz
mailman-f8a6c46455a409125dcc0fcace7d7116898b0319.tar.zst
mailman-f8a6c46455a409125dcc0fcace7d7116898b0319.zip
Move the pending database into the SQLAlchemy/Elixir layer. The old
Pending.py module is removed. Added an interface to this functionality such that any IPendable (essentially a key/value mapping) can be associated with a token, and that token can be confirmed and has a lifetime. Any keys and values can be stored, as long as both are unicodes. Added a doctest. Modified initialization of the database layer to support pluggability via setuptools. No longer is this layer initialized from a module, but now it's instantiated from a class that implements IDatabase. The StockDatabase class implements the SQLAchemy/Elixir layer, but this can be overridden in a setup.py. Bye bye MANAGERS_INIT_FUNCTION, we hardly knew ye. Added a package Mailman.app which will contain certain application specific functionality. Right now, the only there there is an IRegistar implementation, which didn't seem to fit anywhere else. Speaking of which, the IRegistrar interface implements all the logic related to registration and verification of email addresses. Think the equivalent of MailList.AddMember() except generalized out of a mailing list context. This latter will eventually go away. The IRegistrar sends the confirmation email. Added an IDomain interface, though the only implementation of this so far lives in the registration.txt doctest. This defines the context necessary for domain-level things, like address confirmation. A bunch of other cleanups in modules that are necessary due to the refactoring of Pending, but don't affect anything that's actually tested yet, so I won't vouch for them (except that they don't throw errors on import!). Clean up Defaults.py; also turn the functions seconds(), minutes(), hours() and days() into their datetime.timedelta equivalents. Consolidated the bogus email address exceptions. In some places where appropriate, use email 4.0 module names instead of the older brand. Switch from Mailman.Utils.unique_message_id() to email.utils.make_msgid() everywhere. This is because we need to allow sending not in the context of a mailing list (i.e. domain-wide address confirmation message). So we can't use a Message-ID generator that requires a mailing list. OTOH, this breaks Message-ID collision detection in the mail->news gateway. I'll fix that eventually. Remove the 'verified' row on the Address table. Now verification is checked by Address.verified_on not being None.
Diffstat (limited to 'Mailman/Message.py')
-rw-r--r--Mailman/Message.py47
1 files changed, 25 insertions, 22 deletions
diff --git a/Mailman/Message.py b/Mailman/Message.py
index e535b88cc..0ae724009 100644
--- a/Mailman/Message.py
+++ b/Mailman/Message.py
@@ -23,11 +23,11 @@ which is more convenient for use inside Mailman.
import re
import email
-import email.Message
-import email.Utils
+import email.message
+import email.utils
-from email.Charset import Charset
-from email.Header import Header
+from email.charset import Charset
+from email.header import Header
from Mailman import Utils
from Mailman.configuration import config
@@ -39,11 +39,11 @@ VERSION = tuple([int(s) for s in mo.group().split('.')])
-class Message(email.Message.Message):
+class Message(email.message.Message):
def __init__(self):
# We need a version number so that we can optimize __setstate__()
self.__version__ = VERSION
- email.Message.Message.__init__(self)
+ email.message.Message.__init__(self)
# BAW: For debugging w/ bin/dumpdb. Apparently pprint uses repr.
def __repr__(self):
@@ -126,7 +126,7 @@ class Message(email.Message.Message):
fieldval = self[h]
if not fieldval:
continue
- addrs = email.Utils.getaddresses([fieldval])
+ addrs = email.utils.getaddresses([fieldval])
try:
realname, address = addrs[0]
except IndexError:
@@ -179,7 +179,7 @@ class Message(email.Message.Message):
else:
fieldvals = self.get_all(h)
if fieldvals:
- pairs.extend(email.Utils.getaddresses(fieldvals))
+ pairs.extend(email.utils.getaddresses(fieldvals))
authors = []
for pair in pairs:
address = pair[1]
@@ -193,7 +193,7 @@ class Message(email.Message.Message):
Mailman to stop delivery in Scrubber.py (called from ToDigest.py).
"""
try:
- filename = email.Message.Message.get_filename(self, failobj)
+ filename = email.message.Message.get_filename(self, failobj)
return filename
except (UnicodeError, LookupError, ValueError):
return failobj
@@ -223,22 +223,22 @@ class UserNotification(Message):
self.recips = [recip]
def send(self, mlist, **_kws):
- """Sends the message by enqueuing it to the `virgin' queue.
+ """Sends the message by enqueuing it to the 'virgin' queue.
This is used for all internally crafted messages.
"""
# Since we're crafting the message from whole cloth, let's make sure
# this message has a Message-ID. Yes, the MTA would give us one, but
# this is useful for logging to logs/smtp.
- if not self.has_key('message-id'):
- self['Message-ID'] = Utils.unique_message_id(mlist)
+ if 'message-id' not in self:
+ self['Message-ID'] = email.utils.make_msgid()
# Ditto for Date: which is required by RFC 2822
- if not self.has_key('date'):
- self['Date'] = email.Utils.formatdate(localtime=1)
+ if 'date' not in self:
+ self['Date'] = email.utils.formatdate(localtime=True)
# UserNotifications are typically for admin messages, and for messages
# other than list explosions. Send these out as Precedence: bulk, but
# don't override an existing Precedence: header.
- if not self.has_key('precedence'):
+ if 'precedence' not in self:
self['Precedence'] = 'bulk'
self._enqueue(mlist, **_kws)
@@ -246,13 +246,16 @@ class UserNotification(Message):
# Not imported at module scope to avoid import loop
from Mailman.Queue.sbcache import get_switchboard
virginq = get_switchboard(config.VIRGINQUEUE_DIR)
- # The message metadata better have a `recip' attribute
- virginq.enqueue(self,
- listname=mlist.fqdn_listname,
- recips=self.recips,
- nodecorate=True,
- reduced_list_headers=True,
- **_kws)
+ # The message metadata better have a 'recip' attribute.
+ enqueue_kws = dict(
+ recips=self.recips,
+ nodecorate=True,
+ reduced_list_headers=True,
+ )
+ if mlist is not None:
+ enqueue_kws[listname] = mlist.fqdn_listname
+ enqueue_kws.update(_kws)
+ virginq.enqueue(self, **enqueue_kws)