[Commits] (bkirsch) fixes bug# 2565 r=Morgen

commits at osafoundation.org commits at osafoundation.org
Tue Mar 8 16:05:46 PST 2005


Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/smtp.py 1.32 1.33

Log message:
fixes bug# 2565 r=Morgen

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

Index: chandler/parcels/osaf/mail/smtp.py
diff -u chandler/parcels/osaf/mail/smtp.py:1.32 chandler/parcels/osaf/mail/smtp.py:1.33
--- chandler/parcels/osaf/mail/smtp.py:1.32	Tue Feb 15 10:22:54 2005
+++ chandler/parcels/osaf/mail/smtp.py	Tue Mar  8 16:05:45 2005
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.32 $"
-__date__      = "$Date: 2005/02/15 18:22:54 $"
+__revision__  = "$Revision: 1.33 $"
+__date__      = "$Date: 2005/03/09 00:05:45 $"
 __copyright__ = "Copyright (c) 2005 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -107,31 +107,68 @@
 
         self.__getKinds()
 
+        #XXX: make sure that we need this could just check if outbound already
         self.mailMessage.outgoingMessage(account=self.account)
 
         """Clear out any previous DeliveryErrors from a previous attempt"""
         for item in self.mailMessage.deliveryExtension.deliveryErrors:
             item.delete()
 
-        messageText = message.kindToMessageText(self.mailMessage)
+        """Get the sender's Email Address will either be the Reply-To or From field"""
+        sender = self.__getSender()
 
-        d = defer.Deferred()
-        d.addCallback(self.execInViewThenCommitInThreadDeferred, self.__mailSuccessCheck)
-        d.addErrback(self.execInViewThenCommitInThreadDeferred,  self.__mailFailure)
 
-        to_addrs = self.__getRcptTo()
-        from_addr = self.__getMailFrom()
+        """Make sure that the Mail Message has a sender"""
+        if sender is None:
+            reactor.callLater(0, self.execInViewThenCommitInThread, self.__fatalError, \
+                              "A From Address is required to send an SMTP Mail Message.")
+            return
+
+
+        """Make sure the sender's Email Address is valid"""
+        if not Mail.EmailAddress.isValidEmailAddress(sender.emailAddress):
+            reactor.callLater(0, self.execInViewThenCommitInThread, self.__fatalError, \
+                              "%s is not a valid From Address." % \
+                              Mail.EmailAddress.format(sender))
+            return
 
-        """Perform error checking to make sure To, From have values"""
-        if len(to_addrs) == 0:
-            reactor.callLater(0, self.execInViewThenCommitInThread, self.__fatalError, "To Address")
+        """Make sure there is at least one Email Address to send the message to"""
+        if len(self.mailMessage.toAddress) == 0:
+            reactor.callLater(0, self.execInViewThenCommitInThread, self.__fatalError, \
+                              "A To Address is required to send an SMTP Mail Message.")
             return
 
-        if from_addr is None or len(from_addr.strip()) == 0:
-            reactor.callLater(0, self.execInViewThenCommitInThread, self.__fatalError, "From Address")
+        errs = []
+        #XXX: Clean up verbage and of course move to external file when i18n in place
+        errStr = "%s Address %s is not a valid Email Address."
+
+        """Make sure that each Recipients Email Address is valid"""
+        for toAddress in self.mailMessage.toAddress:
+            if not Mail.EmailAddress.isValidEmailAddress(toAddress.emailAddress):
+                errs.append(errStr % ("To", Mail.EmailAddress.format(toAddress)))
+
+        for ccAddress in self.mailMessage.ccAddress:
+            if not Mail.EmailAddress.isValidEmailAddress(ccAddress.emailAddress):
+                errs.append(errStr % ("Cc", Mail.EmailAddress.format(ccAddress)))
+
+        for bccAddress in self.mailMessage.bccAddress:
+            if not Mail.EmailAddress.isValidEmailAddress(bccAddress.emailAddress):
+                errs.append(errStr % ("Bcc", Mail.EmailAddress.format(bccAddress)))
+
+        if len(errs) > 0:
+            reactor.callLater(0, self.execInViewThenCommitInThread, self.__fatalError, \
+                              "\n".join(errs))
             return
 
-        SMTPSender.sendMailMessage(from_addr, to_addrs, messageText, d, self.account)
+        messageText = message.kindToMessageText(self.mailMessage)
+
+        d = defer.Deferred()
+        d.addCallback(self.execInViewThenCommitInThreadDeferred, self.__mailSuccessCheck)
+        d.addErrback(self.execInViewThenCommitInThreadDeferred,  self.__mailFailure)
+
+        SMTPSender.sendMailMessage(sender.emailAddress, self.__getRcptTo(), \
+                                     messageText, d, self.account)
+
 
     def __mailSuccessCheck(self, result):
         """Twisted smtp.py will call the deferred callback (this method) if
@@ -335,7 +372,7 @@
         if __debug__:
             self.printCurrentView("__fatalError")
 
-        e = errors.SMTPException("A %s is required to send an SMTP Mail Message." % str)
+        e = errors.SMTPException(str)
         self.__recordError(e)
         self.mailMessage.deliveryExtension.sendFailed()
 
@@ -360,13 +397,13 @@
         assert self.account is not None, "No Account for UUID: %s" % self.accountUUID
         assert self.mailMessage is not None, "No MailMessage for UUID: %s" % self.mailMessageUUID
 
-    def __getMailFrom(self):
+    def __getSender(self):
         #XXX: Will want to refine how this look is done when mail preferences are in place
         if self.mailMessage.replyToAddress is not None:
-            return self.mailMessage.replyToAddress.emailAddress
+            return self.mailMessage.replyToAddress
 
         elif self.mailMessage.fromAddress is not None:
-            return self.mailMessage.fromAddress.emailAddress
+            return self.mailMessage.fromAddress
 
         return None
 



More information about the Commits mailing list