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

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-03-16 15:12:12 UTC
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120316151212-w2u06qd6oxi2cvli
Make an rfc822 message with a mime payload.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
def make_mime_message(message_id, body='body', headers=None, hidden=False,
52
52
                      attachment_type=None):
53
 
    message = MIMEMultipart()
54
 
    message.attach(MIMEText(body))
55
53
    if headers is None:
56
54
        headers = {}
57
 
    for key, value in headers.items():
58
 
        message[key] = value
 
55
    parts = MIMEMultipart()
 
56
    parts.attach(MIMEText(body))
59
57
    if attachment_type is not None:
60
58
        attachment = Message()
61
59
        attachment.set_payload('attactment data.')
62
60
        attachment['Content-Type'] = attachment_type
63
61
        attachment['Content-Disposition'] = 'attachment; filename="file.ext"'
64
 
        message.attach(attachment)
 
62
        parts.attach(attachment)
 
63
    message = Message()
 
64
    message.set_payload(parts.as_string())
 
65
    for key, value in headers.items():
 
66
        message[key] = value
65
67
    return make_json_message(message_id, message.as_string())
66
68
 
67
69