~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/store.py

  • Committer: Curtis Hovey
  • Date: 2012-03-16 16:10:54 UTC
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120316161054-jk68i83kh81qm2vi
Store the body text only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    return threads.values()
39
39
 
40
40
 
41
 
def make_json_message(message_id, raw_message):
 
41
def get_body_text(message):
 
42
    """Return the first plain/text messaage part."""
 
43
    if not message.is_multipart():
 
44
        return message.get_payload()
 
45
    for part in email.iterators.typed_subpart_iterator(message, 'multipart'):
 
46
        subparts = part.get_payload()
 
47
        for subpart in subparts:
 
48
            if subpart.get_content_type() == 'text/plain':
 
49
                return subpart.get_payload().strip()
 
50
    return ''
 
51
 
 
52
 
 
53
def make_json_message(message_id, raw_message, hidden=False):
42
54
    message = email.message_from_string(raw_message)
43
55
    headers = dict(message.items())
44
56
    message = {
50
62
        'date': headers.get('date'),
51
63
        'subject': headers.get('subject'),
52
64
        'author': headers.get('from'),
53
 
        'hidden': False,
 
65
        'hidden': hidden,
54
66
        'attachments': [],
55
 
        'replies': [],
56
 
        'body': raw_message,
 
67
        'replies': headers.get('in-reply-to'),
 
68
        'body': get_body_text(message),
57
69
        }
58
70
    return message
59
71