[Commits] (bkirsch) Added deferred callback to smtp useful for sharing

commits at osafoundation.org commits at osafoundation.org
Thu Aug 19 18:27:17 PDT 2004


Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/MailTasks.py 1.5 1.6
chandler/parcels/osaf/mail/smtp.py 1.4 1.5

Log message:
Added deferred callback to smtp useful for sharing

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/MailTasks.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/smtp.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5

Index: chandler/parcels/osaf/mail/MailTasks.py
diff -u chandler/parcels/osaf/mail/MailTasks.py:1.5 chandler/parcels/osaf/mail/MailTasks.py:1.6
--- chandler/parcels/osaf/mail/MailTasks.py:1.5	Thu Aug 19 16:59:55 2004
+++ chandler/parcels/osaf/mail/MailTasks.py	Thu Aug 19 18:27:16 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.5 $"
-__date__      = "$Date: 2004/08/19 23:59:55 $"
+__revision__  = "$Revision: 1.6 $"
+__date__      = "$Date: 2004/08/20 01:27:16 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -12,6 +12,7 @@
 import common as common
 import message as message
 import logging as logging
+import twisted.internet.defer as defer
 
 
 class IMAPDownloadAction(Action.Action):
@@ -75,4 +76,9 @@
 
         Globals.repository.commit()
 
-        smtp.SMTPSender(account, m).sendMail()
+        d = defer.Deferred().addBoth(self.smtpResponse)
+
+        smtp.SMTPSender(account, m, d).sendMail()
+
+    def smtpResponse(selfi, result):
+        print "SMTP Response Got: ", result

Index: chandler/parcels/osaf/mail/smtp.py
diff -u chandler/parcels/osaf/mail/smtp.py:1.4 chandler/parcels/osaf/mail/smtp.py:1.5
--- chandler/parcels/osaf/mail/smtp.py:1.4	Thu Aug 19 17:33:12 2004
+++ chandler/parcels/osaf/mail/smtp.py	Thu Aug 19 18:27:16 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.4 $"
-__date__      = "$Date: 2004/08/20 00:33:12 $"
+__revision__  = "$Revision: 1.5 $"
+__date__      = "$Date: 2004/08/20 01:27:16 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -48,7 +48,7 @@
 
 class SMTPSender(RepositoryView.AbstractRepositoryViewManager):
 
-    def __init__(self, account, mailMessage):
+    def __init__(self, account, mailMessage, deferred=None):
         #XXX: Perhaps get the first account if None
         if account is None or not account.isItemOf(Mail.MailParcel.getSMTPAccountKind()):
             raise SMTPMailException("You must pass in a SMTPAccount instance")
@@ -63,9 +63,11 @@
 
         self.accountUUID = account.itsUUID
         self.account = None
-        self.mailMessage = None 
+        self.mailMessage = None
         self.mailMessageUUID = mailMessage.itsUUID
-        self.sent = False
+        self.deferred = deferred
+        self.failure = None
+        self.success = None
 
     #in thread
     def sendMail(self):
@@ -160,7 +162,8 @@
             self.mailMessage.dateSentString = message.dateTimeToRFC2882Date(DateTime.now())
 
             self.mailMessage.deliveryExtension.sendSucceeded()
-            self.sent = True 
+
+            self.success = result
 
         finally:
            self.restorePreviousView()
@@ -179,7 +182,7 @@
             self.log.error("SMTP send failed: %s" % exc)
 
             self.mailMessage.deliveryExtension.sendFailed()
-            self.sent = False
+            self.failure = exc
 
         finally:
            self.restorePreviousView()
@@ -196,10 +199,6 @@
         @return: C{None}
         """
 
-        #XXX: Post a failure event back to the Gui
-        #XXX: Could just look at the message Delivery Extension state as well
-        if not self.sent:
-            pass
 
         self.account.setPinned(False)
         self.mailMessage.setPinned(False)
@@ -208,6 +207,16 @@
 
         Globals.wxApplication.PostAsyncEvent(Globals.repository.commit)
 
+        #XXX: Post a failure event back to the Gui
+        #XXX: Could just look at the message Delivery Extension state as well
+        if self.failure is not None:
+            if self.deferred is not None:
+                self.deferred.errback(self.failure)
+
+        elif self.success is not None:
+            if self.deferred is not None:
+                self.deferred.callback(self.success)
+
     def __getKinds(self):
 
         accountKind = Mail.MailParcel.getSMTPAccountKind()



More information about the Commits mailing list