def text(subtype, body, charset=None, disposition=None, filename=None): return MimePart(container=Body(content_type=ContentType("text", subtype), body=body, charset=charset, disposition=disposition, filename=filename), is_root=True)
def make_part(content_type, start, end, iterator, parts=(), enclosed=None, parent=None, badmime=False): # here we detect where the message really starts # the exact position in the string, at the end of the # starting boundary and after the beginning of the end boundary if start.is_boundary(): start = start.end + 1 else: start = start.start # if this is the message ending, end of part # the position of the last symbol of the message if end.is_end(): end = len(iterator.string) - 1 # for multipart boundaries # consider the final boundary as the ending one elif content_type.is_multipart(): end = end.end # otherwise, end is position of the the symbol before # the boundary start else: end = end.start - 1 # our tokenizer detected the beginning of the message container # that is separated from the enclosed message by newlines # here we find where the enclosed message begins by searching for the # first newline if parent and (parent.is_message_container() or parent.is_headers_container()): start = locate_first_newline(iterator.stream, start) if badmime: content_type = ContentType('application', 'octet-stream') # ok, finally, create the MimePart. # note that it does not parse anything, just remembers # the position in the string return MimePart(container=Stream(content_type=content_type, start=start, end=end, stream=iterator.stream, string=iterator.string), badmime=badmime, parts=parts, enclosed=enclosed, is_root=(parent == None))
def binary(maintype, subtype, body, filename=None, disposition=None, charset=None, trust_ctype=False): return MimePart(container=Body(content_type=ContentType(maintype, subtype), trust_ctype=trust_ctype, body=body, charset=charset, disposition=disposition, filename=filename), is_root=True)
def message_container(message): part = MimePart( container=Part(ContentType("message", "rfc822")), enclosed=message) message.set_root(False) return part
def multipart(subtype): return MimePart( container=Part( ContentType( "multipart", subtype, {"boundary": uuid.uuid4().hex})), is_root=True)