[Commits] (bkirsch) Cleaning up message parsing logic by providing
a more robust detailed API,
created a common.py file to be used for placing common code shared
among mail operations
commits at osafoundation.org
commits at osafoundation.org
Tue Aug 3 16:47:58 PDT 2004
Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/common.py None 1.1
chandler/parcels/osaf/mail/message.py 1.2 1.3
chandler/parcels/osaf/mail/imap.py 1.3 1.4
Log message:
Cleaning up message parsing logic by providing a more robust detailed API, created a common.py file to be used for placing common code shared among mail operations
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/common.py?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/message.py.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/imap.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4
Index: chandler/parcels/osaf/mail/message.py
diff -u chandler/parcels/osaf/mail/message.py:1.2 chandler/parcels/osaf/mail/message.py:1.3
--- chandler/parcels/osaf/mail/message.py:1.2 Mon Aug 2 17:11:43 2004
+++ chandler/parcels/osaf/mail/message.py Tue Aug 3 16:47:57 2004
@@ -1,11 +1,12 @@
-__revision__ = "$Revision: 1.2 $"
-__date__ = "$Date: 2004/08/03 00:11:43 $"
+__revision__ = "$Revision: 1.3 $"
+__date__ = "$Date: 2004/08/03 23:47:57 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
import osaf.contentmodel.mail.Mail as Mail
import mx.DateTime as DateTime
import email as email
+import email.Message as Message
import email.Utils as Utils
def format_addr(addr):
@@ -23,47 +24,80 @@
str = str + '<' + addr[1] + '>'
return str
+def messageTextToKind(messageText):
+ """
+ This method converts a email message string to
+ a Chandler C{Mail.MailMessage} object
+
+ @param messageText: A string representation of a mail message
+ @type messageText: string
+ @return: C{Mail.MailMessage}
+ """
+
+ if not isinstance(messageText, str):
+ raise TypeError("messageText must be a String")
+
+ return messageObjectToKind(email.message_from_string(messageText))
-def make_message(data):
+def messageObjectToKind(messageObject):
"""
This method converts a email message string to
a Chandler C{Mail.MailMessage} object
- @param data: A string representation of a mail message
- @type data: string
+ @param messageObject: A C{email.Message} object representation of a mail message
+ @type messageObject: C{email.Message}
@return: C{Mail.MailMessage}
"""
- msg = email.message_from_string(data)
+ if not isinstance(messageObject, Message.Message):
+ raise TypeError("messageObject must be a Python email.Message.Message instance")
m = Mail.MailMessage()
if m is None:
- print "MailMessage was NULL"
- return None
+ raise Exception("Repository returned a MailMessage that was None")
- m.dateSent = DateTime.mktime(Utils.parsedate(msg['Date']))
+ m.dateSent = DateTime.mktime(Utils.parsedate(messageObject['Date']))
m.dateReceived = DateTime.now()
- if msg['Subject'] is None:
+ if messageObject['Subject'] is None:
m.subject = ""
else:
- m.subject = msg['Subject']
+ m.subject = messageObject['Subject']
# XXX replyAddress should really be the Reply-to header, not From
m.replyAddress = Mail.EmailAddress()
- m.replyAddress.emailAddress = format_addr(Utils.parseaddr(msg['From']))
+ m.replyAddress.emailAddress = format_addr(Utils.parseaddr(messageObject['From']))
m.toAddress = []
- for addr in Utils.getaddresses(msg.get_all('To', [])):
+ for addr in Utils.getaddresses(messageObject.get_all('To', [])):
ea = Mail.EmailAddress()
ea.emailAddress = format_addr(addr)
m.toAddress.append(ea)
m.ccAddress = []
- for addr in Utils.getaddresses(msg.get_all('Cc', [])):
+ for addr in Utils.getaddresses(messageObject.get_all('Cc', [])):
ea = Mail.EmailAddress()
ea.emailAddress = format_addr(addr)
m.ccAddress.append(ea)
return m
+
+def KindToMessageObject(mailMessage):
+ """
+ This method converts a email message string to
+ a Chandler C{Mail.MailMessage} object
+
+ @param messageObject: A C{email.Message} object representation of a mail message
+ @type messageObject: C{email.Message}
+ @return: C{Mail.MailMessage}
+ """
+
+ ### Check that the kind is a mail message
+ if not isinstance(mailMessage, Mail.MailMessage):
+ raise Exception("mailMessage must be an instance of Kind Mail.MailMessage")
+
+
+ messageObject = Message.Message()
+
+ return messageObject
Index: chandler/parcels/osaf/mail/imap.py
diff -u chandler/parcels/osaf/mail/imap.py:1.3 chandler/parcels/osaf/mail/imap.py:1.4
--- chandler/parcels/osaf/mail/imap.py:1.3 Mon Aug 2 17:11:43 2004
+++ chandler/parcels/osaf/mail/imap.py Tue Aug 3 16:47:57 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.3 $"
-__date__ = "$Date: 2004/08/03 00:11:43 $"
+__revision__ = "$Revision: 1.4 $"
+__date__ = "$Date: 2004/08/03 23:47:57 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -136,7 +136,7 @@
self.setViewCurrent()
try:
- if __debug__:
+ if __debug__:
self.printCurrentView("__getMail")
self.account = self.__getAccount()
@@ -147,7 +147,7 @@
serverName = self.account.serverName
serverPort = self.account.serverPort
- if __debug__:
+ if __debug__:
self.printAccount()
finally:
@@ -188,7 +188,7 @@
This method is a Twisted C{defer.Deferred} callback that logs in to an IMAP Server
based on the account information stored in a C{EmailAccountKind}.
- @param result: A Twisted callback result
+ @param result: A Twisted callback result
@type result: Could be anything
@param proto: The C{ChandlerIMAP4Client} protocol instance
@type proto: C{ChandlerIMAP4Client}
@@ -198,7 +198,7 @@
self.setViewCurrent()
try:
- if __debug__:
+ if __debug__:
self.printCurrentView("loginClient")
""" Save the IMAP4Client instance """
@@ -208,7 +208,7 @@
assert self.account is not None, "Account is None can not login client"
- return self.proto.login(str(self.account.accountName),
+ return self.proto.login(str(self.account.accountName),
str(self.account.password)).addCallback(self.__selectInbox)
finally:
self.restorePreviousView()
@@ -237,10 +237,10 @@
if self.__getLastUID() == 0:
msgSet = imap4.MessageSet(1, None)
- else:
+ else:
msgSet = imap4.MessageSet(self.__getLastUID(), None)
- d = self.proto.fetchUID(msgSet, uid=True)
+ d = self.proto.fetchUID(msgSet, uid=True)
d.addCallback(self.__getMessagesFromUIDS)
return d
@@ -298,13 +298,13 @@
try:
""" Refresh our view before adding items to our mail account
and commiting. Will not cause merge conflicts since
- no data changed in view in yet """
+ no data changed in view in yet """
self.view.commit()
- totalDownloaded = 0
+ totalDownloaded = 0
for msg in msgs:
- repMessage = message.make_message(msgs[msg]['RFC822'])
+ repMessage = message.messageTextToKind(msgs[msg]['RFC822'])
self.account.downloadedMail.append(repMessage)
uid = long(msgs[msg]['UID'])
@@ -318,14 +318,14 @@
finally:
self.restorePreviousView()
- """Commit the view in a thread to prevent blocking"""
+ """Commit the view in a thread to prevent blocking"""
self.commitView(True)
def _viewCommitSuccess(self):
"""
- Overides C{RepositoryView.AbstractRepositoryViewManager}.
- It posts a commit event to the GUI thread, unpins the C{EmailAccountKind} from
+ Overides C{RepositoryView.AbstractRepositoryViewManager}.
+ It posts a commit event to the GUI thread, unpins the C{EmailAccountKind} from
memory, and writes commit info to the logger
@return: C{None}
"""
@@ -359,7 +359,7 @@
if self.account.serverPort != 143:
str = "[Server: %s:%d User: %s] %s" % (self.account.serverName,
- self.account.serverPort,
+ self.account.serverPort,
self.account.accountName, info)
else:
str = "[Server: %s User: %s] %s" % (self.account.serverName,
More information about the Commits
mailing list