~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/store.py

  • Committer: Curtis Hovey
  • Date: 2012-03-01 01:08:15 UTC
  • Revision ID: curtis.hovey@canonical.com-20120301010815-hz0al69e3j0c9e6n
Raise ArchiveIdNotFound if the client puts a message into an unknown archive.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    return threads.values()
39
39
 
40
40
 
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):
 
41
def make_json_message(message_id, raw_message):
54
42
    message = email.message_from_string(raw_message)
55
43
    headers = dict(message.items())
56
44
    message = {
62
50
        'date': headers.get('date'),
63
51
        'subject': headers.get('subject'),
64
52
        'author': headers.get('from'),
65
 
        'hidden': hidden,
 
53
        'hidden': False,
66
54
        'attachments': [],
67
 
        'replies': headers.get('in-reply-to'),
68
 
        'body': get_body_text(message),
 
55
        'replies': [],
 
56
        'body': raw_message,
69
57
        }
70
58
    return message
71
59