# -*- coding: utf-8 -*-

import email

from DebianChangesBot.utils import quoted_printable

def parse_mail(fileobj):
    headers, body = {}, []
    msg = email.message_from_file(fileobj)

    for k, v in msg.items():
        headers[k] = quoted_printable(v).replace('\n', '').strip()

    for line in email.iterators.body_line_iterator(msg):
        line = unicode(line, 'utf-8', 'replace').replace('\n', '')
        body.append(line)

    # Merge lines joined with "=\n"
    i = len(body) - 1
    while i > 0:
        i -= 1
        prev = body[i]
        if len(prev) == 74 and prev.endswith('='):
            body[i] = body[i][:-1] + body[i + 1]
            del body[i + 1]

    # Remove =20 from end of lines
    i = 0
    while i < len(body):
        if body[i].endswith('=20'):
            body[i] = body[i][:-3] + ' '
        i += 1

    return headers, body

# -*- coding: utf-8 -*-

import email

from DebianChangesBot.utils import quoted_printable

def parse_mail(fileobj):
    headers, body = {}, []
    msg = email.message_from_file(fileobj)

    for k, v in msg.items():
        headers[k] = quoted_printable(v).replace('\n', '').strip()

    for line in email.Iterators.body_line_iterator(msg):
        line = unicode(line, 'utf-8', 'replace').replace('\n', '')
        body.append(line)

    # Merge lines joined with "=\n"
    i = len(body) - 1
    while i > 0:
        i -= 1
        prev = body[i]
        if len(prev) == 74 and prev.endswith('='):
            body[i] = body[i][:-1] + body[i + 1]
            del body[i + 1]

    # Remove =20 from end of lines
    i = 0
    while i < len(body):
        if body[i].endswith('=20'):
            body[i] = body[i][:-3] + ' '
        i += 1

    return headers, body

Use 2.4 email iterator syntax so the fixture tests pass
Use 2.4 email iterator syntax so the fixture tests pass

python2.4 called its email iterators: email.Iterators.
python2.5 uses email.iterators, but to allow cross-version code,
Iterators works.

Signed-off-by: Jonny Lamb <54cd04502facfcf96b325c60af9b1611ee761860@jonnylamb.com>
