コード例 #1
0
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)
コード例 #2
0
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))
コード例 #3
0
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)
コード例 #4
0
ファイル: create.py プロジェクト: smokymountains/flanker
def message_container(message):
    part = MimePart(
        container=Part(ContentType("message", "rfc822")),
        enclosed=message)
    message.set_root(False)
    return part
コード例 #5
0
ファイル: create.py プロジェクト: smokymountains/flanker
def multipart(subtype):
    return MimePart(
        container=Part(
            ContentType(
                "multipart", subtype, {"boundary": uuid.uuid4().hex})),
        is_root=True)