~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-20 14:28:59 UTC
  • mfrom: (2625.6.3 bzr.email_message)
  • mto: This revision was merged to the branch mainline in revision 2640.
  • Revision ID: john@arbash-meinel.com-20070720142859-a24s0khul0yw91bh
(Adeodato Simó) EmailMessage class, allowing much nicer access to Email object than stdlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    def get_message_addresses(message):
80
80
        """Get the origin and destination addresses of a message.
81
81
 
82
 
        :param message: An email.Message or email.MIMEMultipart object.
 
82
        :param message: A message object supporting get() to access its
 
83
            headers, like email.Message or bzrlib.email_message.EmailMessage.
83
84
        :return: A pair (from_email, to_emails), where from_email is the email
84
85
            address in the From header, and to_emails a list of all the
85
86
            addresses in the To, Cc, and Bcc headers.
86
87
        """
87
 
        from_email = Utils.parseaddr(message['From'])[1]
 
88
        from_email = Utils.parseaddr(message.get('From', None))[1]
88
89
        to_full_addresses = []
89
90
        for header in ['To', 'Cc', 'Bcc']:
90
 
            to_full_addresses += message.get_all(header, [])
 
91
            value = message.get(header, None)
 
92
            if value:
 
93
                to_full_addresses.append(value)
91
94
        to_emails = [ pair[1] for pair in
92
95
                Utils.getaddresses(to_full_addresses) ]
93
96