diff options
author | Guido van Rossum <guido@python.org> | 2002-09-12 05:08:00 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-09-12 05:08:00 (GMT) |
commit | 4bf12543420f9beca5f2c6d886be0a2fe2cbd289 (patch) | |
tree | b5ecca559766d4e95bf9c93cad997079a044c4ef /Lib/mailbox.py | |
parent | d560ace3a76d1fa162fa40ec90a158d4d3540036 (diff) | |
download | cpython-4bf12543420f9beca5f2c6d886be0a2fe2cbd289.zip cpython-4bf12543420f9beca5f2c6d886be0a2fe2cbd289.tar.gz cpython-4bf12543420f9beca5f2c6d886be0a2fe2cbd289.tar.bz2 |
Undocumented feature: MHMailbox sets the msg object's _mh_msgno
attribute to the (stringized) message number (if this attribute is
settable). This is useful so users of this class can report the
correct message number (e.g. when classifying spam).
Also added a blank line before the first method of each class.
Diffstat (limited to 'Lib/mailbox.py')
-rwxr-xr-x | Lib/mailbox.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 6264394..d3c8ec8 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -10,6 +10,7 @@ __all__ = ["UnixMailbox","MmdfMailbox","MHMailbox","Maildir","BabylMailbox", "PortableUnixMailbox"] class _Mailbox: + def __init__(self, fp, factory=rfc822.Message): self.fp = fp self.seekp = 0 @@ -35,6 +36,7 @@ class _Mailbox: class _Subfile: + def __init__(self, fp, start, stop): self.fp = fp self.start = start @@ -94,6 +96,7 @@ class _Subfile: # Recommended to use PortableUnixMailbox instead! class UnixMailbox(_Mailbox): + def _search_start(self): while 1: pos = self.fp.tell() @@ -161,6 +164,7 @@ class PortableUnixMailbox(UnixMailbox): class MmdfMailbox(_Mailbox): + def _search_start(self): while 1: line = self.fp.readline() @@ -181,6 +185,7 @@ class MmdfMailbox(_Mailbox): class MHMailbox: + def __init__(self, dirname, factory=rfc822.Message): import re pat = re.compile('^[1-9][0-9]*$') @@ -204,7 +209,12 @@ class MHMailbox: return None fn = self.boxes.pop(0) fp = open(os.path.join(self.dirname, fn)) - return self.factory(fp) + msg = self.factory(fp) + try: + msg._mh_msgno = fn + except (AttributeError, TypeError): + pass + return msg class Maildir: @@ -238,6 +248,7 @@ class Maildir: class BabylMailbox(_Mailbox): + def _search_start(self): while 1: line = self.fp.readline() |