mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
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.
This commit is contained in:
parent
d560ace3a7
commit
4bf1254342
1 changed files with 12 additions and 1 deletions
|
|
@ -10,6 +10,7 @@
|
|||
"PortableUnixMailbox"]
|
||||
|
||||
class _Mailbox:
|
||||
|
||||
def __init__(self, fp, factory=rfc822.Message):
|
||||
self.fp = fp
|
||||
self.seekp = 0
|
||||
|
|
@ -35,6 +36,7 @@ def next(self):
|
|||
|
||||
|
||||
class _Subfile:
|
||||
|
||||
def __init__(self, fp, start, stop):
|
||||
self.fp = fp
|
||||
self.start = start
|
||||
|
|
@ -94,6 +96,7 @@ def close(self):
|
|||
|
||||
# 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 @@ def _search_end(self):
|
|||
|
||||
|
||||
class MHMailbox:
|
||||
|
||||
def __init__(self, dirname, factory=rfc822.Message):
|
||||
import re
|
||||
pat = re.compile('^[1-9][0-9]*$')
|
||||
|
|
@ -204,7 +209,12 @@ def next(self):
|
|||
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 @@ def next(self):
|
|||
|
||||
|
||||
class BabylMailbox(_Mailbox):
|
||||
|
||||
def _search_start(self):
|
||||
while 1:
|
||||
line = self.fp.readline()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue