add some header encoding support so mime headers work
authorBryan Clark <clarkbw@gnome.org>
Thu, 22 Jan 2009 20:47:50 -0800
changeset 34 2ef3084bf0aee665f70421fc20ab90f787d4e19e
parent 33 80d0ddcd7f58a224e87e9154ef51af4e60aec26b
child 35 c16b02358f0632e6904e1711b6a111f3da6ca696
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
add some header encoding support so mime headers work
server/python/junius/getmail.py
--- a/server/python/junius/getmail.py
+++ b/server/python/junius/getmail.py
@@ -1,11 +1,11 @@
 #!/usr/bin/env python
 
-import base64, datetime, email.utils
+import base64, datetime, email.utils, email.header
 import pprint
 
 from gocept.imapapi.account import Account
 
 import junius.model as model
 
 '''
 Fetch new mail.
@@ -73,16 +73,20 @@ class JuniusAccount(object):
                         contact = seen_contacts[contact.id]
                     else:
                         involved_list.append(contact)
                         seen_contacts[contact.id] = contact
                 else:
                     # the contact does't exist, create it
                     if not name:
                         name = address
+                    else:
+                        name, encoding = email.header.decode_header(name)[0]
+                        if encoding:
+                            name = unicode(name, encoding)
                     contact = model.Contact(
                         name=name,
                         identities=[{'kind': 'email', 'value': address}]
                     )
                     contact.store(self.dbs.contacts)
                     involved_list.append(contact)
                     seen_contacts[contact.id] = contact
                 cur_results.append(contact)