]
-\f
# Some convenience routines. Don't import Parser and Message as side-effects
# of importing email since those cascadingly import most of the rest of the
# email package.
MISC_LEN = 7
-\f
# Helpers
def header_length(bytearray):
"""Return the length of s when it is encoded with base64."""
return n
-\f
def header_encode(header_bytes, charset='iso-8859-1'):
"""Encode a single header line with Base64 encoding in a given charset.
return '=?%s?b?%s?=' % (charset, encoded)
-\f
def body_encode(s, maxlinelen=76, eol=NL):
r"""Encode a string with base64.
return EMPTYSTRING.join(encvec)
-\f
def decode(string):
"""Decode a raw base64 string, returning a bytes object.
from email.encoders import encode_7or8bit
-\f
# Flags for types of header encodings
QP = 1 # Quoted-Printable
BASE64 = 2 # Base64
EMPTYSTRING = ''
-\f
# Defaults
CHARSETS = {
# input header enc body enc output conv
}
-\f
# Convenience functions for extending the above mappings
def add_charset(charset, header_enc=None, body_enc=None, output_charset=None):
"""Add character set properties to the global registry.
CODEC_MAP[charset] = codecname
-\f
# Convenience function for encoding strings, taking into account
# that they might be unknown-8bit (ie: have surrogate-escaped bytes)
def _encode(string, codec):
return string.encode(codec)
-\f
class Charset:
"""Map character sets to their email properties.
from quopri import encodestring as _encodestring
-\f
def _qencode(s):
enc = _encodestring(s, quotetabs=True)
# Must encode spaces, which quopri.encodestring() doesn't do
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(decode=True)
msg['Content-Transfer-Encoding'] = '7bit'
-\f
def encode_noop(msg):
"""Do nothing."""
NeedMoreData = object()
-\f
class BufferedSubFile(object):
"""A file-ish object that can have new data loaded into it.
return line
-\f
class FeedParser:
"""A feed-style parser of email."""
fcre = re.compile(r'^From ', re.MULTILINE)
-\f
class Generator:
"""Generates output from a Message object tree.
def _compile_re(cls, s, flags):
return re.compile(s, flags)
-\f
+
class BytesGenerator(Generator):
"""Generates a bytes version of a Message object tree.
return re.compile(s.encode('ascii'), flags)
-\f
_FMT = '[Non-text (%(type)s) part of message omitted, filename %(filename)s]'
class DecodedGenerator(Generator):
}, file=self)
-\f
# Helper used by Generator._make_boundary
_width = len(repr(sys.maxsize-1))
_fmt = '%%0%dd' % _width
_embedded_header = re.compile(r'\n[^ \t]+:')
-\f
# Helpers
_max_append = email.quoprimime._max_append
-\f
def decode_header(header):
"""Decode a message header value without converting charset.
return collapsed
-\f
def make_header(decoded_seq, maxlinelen=None, header_name=None,
continuation_ws=' '):
"""Create a Header from a sequence of pairs as returned by decode_header()
return h
-\f
class Header:
def __init__(self, s=None, charset=None,
maxlinelen=None, header_name=None,
self._chunks = chunks
-\f
class _ValueFormatter:
def __init__(self, headerlen, maxlen, continuation_ws, splitchars):
self._maxlen = maxlen
from io import StringIO
-\f
# This function will become a method of the Message class
def walk(self):
"""Walk over the message tree, yielding each subpart.
yield from subpart.walk()
-\f
# These two functions are imported into the Iterators.py interface module.
def body_line_iterator(msg, decode=False):
"""Iterate over the parts, returning string payloads line-by-line.
yield subpart
-\f
def _structure(msg, fp=None, level=0, include_default=False):
"""A handy debugging aid"""
if fp is None:
from email import message
-\f
class MIMEBase(message.Message):
"""Base class for MIME specializations."""
from email.mime.nonmultipart import MIMENonMultipart
-\f
class MIMEMessage(MIMENonMultipart):
"""Class representing message/* MIME documents."""
from email.mime.base import MIMEBase
-\f
class MIMEMultipart(MIMEBase):
"""Base class for MIME multipart/* type messages."""
from email.mime.base import MIMEBase
-\f
class MIMENonMultipart(MIMEBase):
"""Base class for MIME non-multipart type messages."""
from email.mime.nonmultipart import MIMENonMultipart
-\f
class MIMEText(MIMENonMultipart):
"""Class for generating text/* type MIME documents."""
return self.parse(StringIO(text), headersonly=headersonly)
-\f
class HeaderParser(Parser):
def parse(self, fp, headersonly=True):
return Parser.parse(self, fp, True)
def parsestr(self, text, headersonly=True):
return Parser.parsestr(self, text, True)
-\f
+
class BytesParser:
def __init__(self, *args, **kw):
self->pos = 0;
return PyBytes_FromStringAndSize(self->buffer, r);
}
-\f
/*
LEAVE_BUFFERED(self)
return res;
}
-\f
/*
}
return PyObject_GetAttr((PyObject *) self->writer, &_Py_ID(closed));
}
-\f
/*
EMPTYSTRING = ''
-\f
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
# there.
pot_header = _('''\
''')
-\f
+
def usage(code, msg=''):
print(__doc__ % globals(), file=sys.stderr)
if msg:
sys.exit(code)
-\f
def make_escapes(pass_nonascii):
global escapes, escape
if pass_nonascii:
s = '""\n"' + lineterm.join(lines) + '"'
return s
-\f
+
def containsAny(str, set):
"""Check whether 'str' contains ANY of the chars in 'set'"""
return 1 in [c in str for c in set]
return []
-\f
+
class TokenEater:
def __init__(self, options):
self.__options = options
print('msgstr ""\n', file=fp)
-\f
def main():
global default_keywords
try:
if closep:
fp.close()
-\f
+
if __name__ == '__main__':
main()
# some more test strings