from quopri import encodestring as _encodestring
-
+\f
# Helpers
def _qencode(s):
return _encodestring(s, quotetabs=1)
return value
-
+\f
def encode_base64(msg):
"""Encode the message's payload in Base64.
msg['Content-Transfer-Encoding'] = 'base64'
-
+\f
def encode_quopri(msg):
"""Encode the message's payload in Quoted-Printable.
msg['Content-Transfer-Encoding'] = 'quoted-printable'
-
+\f
def encode_7or8bit(msg):
"""Set the Content-Transfer-Encoding: header to 7bit or 8bit."""
orig = msg.get_payload()
msg['Content-Transfer-Encoding'] = '7bit'
-
+\f
def encode_noop(msg):
"""Do nothing."""
"""
-
+\f
class MessageError(Exception):
"""Base class for errors in this module."""
fcre = re.compile(r'^From ', re.MULTILINE)
-
+\f
class Generator:
"""Generates output from a Message object tree.
self._fp.write(s.getvalue())
-
+\f
class DecodedGenerator(Generator):
"""Generator a text representation of a message.
}
-
+\f
# Helper
def _make_boundary(self, text=None):
# Craft a random boundary. If text is given, ensure that the chosen
from types import StringType
-
+\f
def body_line_iterator(msg):
"""Iterate over the parts, returning string payloads line-by-line."""
for subpart in msg.walk():
yield line
-
+\f
def typed_subpart_iterator(msg, maintype='text', subtype=None):
"""Iterate over the subparts with a given MIME type.
import Message
-
+\f
class MIMEBase(Message.Message):
"""Base class for MIME specializations."""
import Encoders
-
+\f
class MIMEImage(MIMEBase.MIMEBase):
"""Class for generating image/* type MIME documents."""
import MIMEBase
-
+\f
class MIMEMessage(MIMEBase.MIMEBase):
"""Class representing message/* MIME documents."""
from Encoders import encode_7or8bit
-
+\f
class MIMEText(MIMEBase.MIMEBase):
"""Class for generating text/* type MIME documents."""
paramre = re.compile(r';\s*')
-
+\f
class Message:
"""Basic message object for use inside the object tree.
NL = '\n'
-
+\f
class Parser:
def __init__(self, _class=Message.Message):
"""Parser of RFC 2822 and MIME email messages.
UEMPTYSTRING = u''
-
+\f
# Helpers
def _identity(s):
return value
-
+\f
def getaddresses(fieldvalues):
"""Return a list of (REALNAME, EMAIL) for each fieldvalue."""
all = COMMASPACE.join(fieldvalues)
return a.getaddrlist()
-
+\f
ecre = re.compile(r'''
=\? # literal =?
(?P<charset>[^?]*?) # non-greedy up to the next ? is the charset
return UEMPTYSTRING.join(rtn)
-
+\f
def encode(s, charset='iso-8859-1', encoding='q'):
"""Encode a string according to RFC 2047."""
if encoding.lower() == 'q':
]
-
+\f
# Some convenience routines
from Parser import Parser as _Parser
from Message import Message as _Message