Ejemplo n.º 1
0
def process_parts(parts, reply_code=None, from_address=None):
    """Uploads the attachments and parses out the
    body, if body is multipart.
    Links to attachments will be added to the body of the question.
    Returns ready to post body of the message and the list
    of uploaded files.
    """
    body_text = ''
    stored_files = list()
    attachments_markdown = ''

    if DEBUG_EMAIL:
        sys.stderr.write('--- MESSAGE PARTS:\n\n')

    for (part_type, content) in parts:
        if part_type == 'attachment':
            if DEBUG_EMAIL:
                sys.stderr.write('REGULAR ATTACHMENT:\n')
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            attachments_markdown += '\n\n' + markdown
        elif part_type == 'body':
            if DEBUG_EMAIL:
                sys.stderr.write('BODY:\n')
                sys.stderr.write(content.encode('utf-8'))
                sys.stderr.write('\n')
            body_text += '\n\n' + content.strip('\n\t ')
        elif part_type == 'inline':
            if DEBUG_EMAIL:
                sys.stderr.write('INLINE ATTACHMENT:\n')
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            body_text += markdown

    if DEBUG_EMAIL:
        sys.stderr.write('--- THE END\n')

    body_text = body_text.replace('\r\n', '\n') #dos2unix

    #if the response separator is present -
    #split the body with it, and discard the "so and so wrote:" part
    if reply_code:
        #todo: maybe move this part out
        signature = extract_user_signature(body_text, reply_code)
        body_text = extract_reply(body_text)
    else:
        signature = None

    attachments_markdown = attachments_markdown.replace('\r\n', '\n') #dos2unix
    body_text += attachments_markdown

    if from_address:
        body_text = parsing.strip_trailing_sender_references(
                                                        body_text,
                                                        from_address
                                                    )

    body_text = body_text.strip()
    return body_text, stored_files, signature
Ejemplo n.º 2
0
def process_parts(parts, reply_code=None, from_address=None):
    """Uploads the attachments and parses out the
    body, if body is multipart.
    Links to attachments will be added to the body of the question.
    Returns ready to post body of the message and the list
    of uploaded files.
    """
    body_text = ''
    stored_files = list()
    attachments_markdown = ''

    if DEBUG_EMAIL:
        sys.stderr.write('--- MESSAGE PARTS:\n\n')

    for (part_type, content) in parts:
        if part_type == 'attachment':
            if DEBUG_EMAIL:
                sys.stderr.write('REGULAR ATTACHMENT:\n')
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            attachments_markdown += '\n\n' + markdown
        elif part_type == 'body':
            if DEBUG_EMAIL:
                sys.stderr.write('BODY:\n')
                sys.stderr.write(content.encode('utf-8'))
                sys.stderr.write('\n')
            body_text += '\n\n' + content.strip('\n\t ')
        elif part_type == 'inline':
            if DEBUG_EMAIL:
                sys.stderr.write('INLINE ATTACHMENT:\n')
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            body_text += markdown

    if DEBUG_EMAIL:
        sys.stderr.write('--- THE END\n')

    body_text = body_text.replace('\r\n', '\n') #dos2unix

    #if the response separator is present -
    #split the body with it, and discard the "so and so wrote:" part
    if reply_code:
        #todo: maybe move this part out
        signature = extract_user_signature(body_text, reply_code)
        body_text = extract_reply(body_text)
    else:
        signature = None

    attachments_markdown = attachments_markdown.replace('\r\n', '\n') #dos2unix
    body_text += attachments_markdown

    if from_address:
        body_text = parsing.strip_trailing_sender_references(
                                                        body_text,
                                                        from_address
                                                    )

    body_text = body_text.strip()
    return body_text, stored_files, signature
Ejemplo n.º 3
0
def process_parts(parts, reply_code=None, from_address=None):
    """Uploads the attachments and parses out the
    body, if body is multipart.
    Links to attachments will be added to the body of the question.
    Returns ready to post body of the message and the list
    of uploaded files.
    """
    body_text = ""
    stored_files = list()
    attachments_markdown = ""

    if DEBUG_EMAIL:
        sys.stderr.write("--- MESSAGE PARTS:\n\n")

    for (part_type, content) in parts:
        if part_type == "attachment":
            if DEBUG_EMAIL:
                sys.stderr.write("REGULAR ATTACHMENT:\n")
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            attachments_markdown += "\n\n" + markdown
        elif part_type == "body":
            if DEBUG_EMAIL:
                sys.stderr.write("BODY:\n")
                sys.stderr.write(content.encode("utf-8"))
                sys.stderr.write("\n")
            body_text += "\n\n" + content.strip("\n\t ")
        elif part_type == "inline":
            if DEBUG_EMAIL:
                sys.stderr.write("INLINE ATTACHMENT:\n")
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            body_text += markdown

    if DEBUG_EMAIL:
        sys.stderr.write("--- THE END\n")

    # if the response separator is present -
    # split the body with it, and discard the "so and so wrote:" part
    if reply_code:
        # todo: maybe move this part out
        signature = extract_user_signature(body_text, reply_code)
        body_text = extract_reply(body_text)
    else:
        signature = None

    body_text += attachments_markdown

    if from_address:
        body_text = parsing.strip_trailing_sender_references(body_text, from_address)

    return body_text.strip(), stored_files, signature
Ejemplo n.º 4
0
def process_parts(parts, reply_code=None, from_address=None):
    """Uploads the attachments and parses out the
    body, if body is multipart.
    Links to attachments will be added to the body of the question.
    Returns ready to post body of the message and the list
    of uploaded files.
    """
    body_text = ''
    stored_files = list()
    attachments_markdown = ''
    for (part_type, content) in parts:
        if part_type == 'attachment':
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            attachments_markdown += '\n\n' + markdown
        elif part_type == 'body':
            body_text += '\n\n' + content.strip('\n\t ')
        elif part_type == 'inline':
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            body_text += markdown

    #if the response separator is present -
    #split the body with it, and discard the "so and so wrote:" part
    if reply_code:
        #todo: maybe move this part out
        signature = extract_user_signature(body_text, reply_code)
        body_text = extract_reply(body_text)
    else:
        signature = None

    body_text += attachments_markdown

    if from_address:
        body_text = parsing.strip_trailing_sender_references(
                                                        body_text,
                                                        from_address
                                                    )

    return body_text.strip(), stored_files, signature
Ejemplo n.º 5
0
def process_parts(parts, reply_code=None, from_address=None):
    """Uploads the attachments and parses out the
    body, if body is multipart.
    Links to attachments will be added to the body of the question.
    Returns ready to post body of the message and the list
    of uploaded files.
    """
    body_text = ''
    stored_files = list()
    attachments_markdown = ''
    for (part_type, content) in parts:
        if part_type == 'attachment':
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            attachments_markdown += '\n\n' + markdown
        elif part_type == 'body':
            body_text += '\n\n' + content.strip('\n\t ')
        elif part_type == 'inline':
            markdown, stored_file = process_attachment(content)
            stored_files.append(stored_file)
            body_text += markdown

    #if the response separator is present -
    #split the body with it, and discard the "so and so wrote:" part
    if reply_code:
        #todo: maybe move this part out
        signature = extract_user_signature(body_text, reply_code)
        body_text = extract_reply(body_text)
    else:
        signature = None

    body_text += attachments_markdown

    if from_address:
        body_text = parsing.strip_trailing_sender_references(
            body_text, from_address)

    return body_text.strip(), stored_files, signature