[Commits] (bkirsch) added sharing logic for sending
commits at osafoundation.org
commits at osafoundation.org
Tue Aug 24 16:19:39 PDT 2004
Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/common.py 1.5 1.6
chandler/parcels/osaf/mail/debug.py 1.1 1.2
chandler/parcels/osaf/mail/message.py 1.13 1.14
chandler/parcels/osaf/mail/sharing.py 1.2 1.3
Log message:
added sharing logic for sending
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/common.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/debug.py.diff?r1=text&tr1=1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/message.py.diff?r1=text&tr1=1.13&r2=text&tr2=1.14
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/sharing.py.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
Index: chandler/parcels/osaf/mail/debug.py
diff -u chandler/parcels/osaf/mail/debug.py:1.1 chandler/parcels/osaf/mail/debug.py:1.2
--- chandler/parcels/osaf/mail/debug.py:1.1 Tue Aug 24 13:20:27 2004
+++ chandler/parcels/osaf/mail/debug.py Tue Aug 24 16:19:38 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.1 $"
-__date__ = "$Date: 2004/08/24 20:20:27 $"
+__revision__ = "$Revision: 1.2 $"
+__date__ = "$Date: 2004/08/24 23:19:38 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -8,6 +8,7 @@
import repository.item.Query as Query
import imap as imap
import smtp as smtp
+import sharing as sharing
import common as common
import message as message
import logging as logging
@@ -19,6 +20,9 @@
imap.IMAPDownloader(account).getMail()
+def sendInvitation():
+ sharing.SMTPInvitationSender("http://test.com", ['brian at localhost', 'bkirsch at osafoundation.org']).sendInvitation()
+
def sendSMTPMessage():
accountKind = Mail.MailParcel.getSMTPAccountKind()
account = None
Index: chandler/parcels/osaf/mail/sharing.py
diff -u chandler/parcels/osaf/mail/sharing.py:1.2 chandler/parcels/osaf/mail/sharing.py:1.3
--- chandler/parcels/osaf/mail/sharing.py:1.2 Thu Aug 19 18:08:22 2004
+++ chandler/parcels/osaf/mail/sharing.py Tue Aug 24 16:19:38 2004
@@ -1,12 +1,181 @@
-"""SENDING:
- I Receive
- 1. URL
- 2 TO Address List
+import twisted.mail.smtp as smtp
+import application.Globals as Globals
+import twisted.internet.reactor as reactor
+import twisted.internet.error as error
+import twisted.internet.defer as defer
+import twisted.internet.ssl as ssl
+import email.Message as Message
+import logging as logging
+import smtp as smtp
+import common as common
+import errors as errorCode
+import message as message
+import osaf.contentmodel.mail.Mail as Mail
+import repository.persistence.RepositoryView as RepositoryView
+import repository.item.Query as Query
+import repository.util.UUID as UUID
+import mx.DateTime as DateTime
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
+
+
+"""
Receiving:
1. I Post the URL for sharing
2. Delete the message on the imap server
-
-
+
+def osaf.framework.sharing.announceSharingUrl(url):
+ TO DO: Hook up events if invitation fails or succeeds
"""
+class SharingConstants(object):
+ SHARING_HEADER = "Sharing-URL"
+
+class SharingException(Exception):
+ pass
+
+class SMTPInvitationSender(RepositoryView.AbstractRepositoryViewManager):
+ """Sends from the first SMTP Account it can find"""
+
+ def __init__(self, url, sendToList):
+
+ if not isinstance(url, str):
+ raise SharingException("URL must be a String")
+
+ if not isinstance(sendToList, list):
+ raise SharingException("sendToList must be of a list of email addresses")
+
+ viewName = "SMTPInvitationSender_%s" % str(UUID.UUID())
+
+ super(SMTPInvitationSender, self).__init__(Globals.repository, viewName)
+
+ self.account = None
+ self.from_addr = None
+ self.url = url
+ self.sendToList = sendToList
+
+ def sendInvitation(self):
+ if __debug__:
+ self.printCurrentView("sendInvitation")
+
+ reactor.callFromThread(self.__sendInvitation)
+
+ def __sendInvitation(self):
+ self.setViewCurrent()
+
+ try:
+ if __debug__:
+ self.printCurrentView("__sendInvitation")
+
+ self.__getData()
+
+ username = self.account.username
+ password = self.account.password
+ host = self.account.host
+ port = self.account.port
+ useSSL = self.account.useSSL
+ useAuth = self.account.useAuth
+ retries = self.account.numRetries
+ authRequired = True
+ sslContext = None
+ heloFallback = False
+
+ if not useAuth:
+ authRequired = False
+ heloFallback = True
+ username = None
+ password = None
+
+ if useSSL:
+ sslContext = ssl.ClientContextFactory(useM2=1)
+
+ messageText = self.__createMessageText()
+
+ print "Message Text:\n", messageText
+
+ d = defer.Deferred().addCallbacks(self.__invitationSuccessCheck, self.__invitationFailure)
+ msg = StringIO(messageText)
+
+ finally:
+ self.restorePreviousView()
+
+ factory = smtp.ChandlerESMTPSenderFactory(username, password, self.from_addr, self.sendToList, msg, d,
+ retries, sslContext, heloFallback, authRequired, useSSL, useSSL)
+
+ reactor.connectTCP(host, port, factory)
+
+ def __invitationSuccessCheck(self, result):
+ if __debug__:
+ self.printCurrentView("__invitationSuccessCheck")
+
+ if result[0] == len(result[1]):
+ addrs = []
+
+ for address in result[1]:
+ addrs.append(address[0])
+
+ info = "Sharing invitation %s sent to [%s]" % (self.url, ", ".join(addrs))
+ self.log.info(info)
+
+ else:
+ errorText = []
+ for recipient in result[1]:
+ email, code, str = recipient
+ e = "Failed to send invitation | %s | %s | %s | %s |" % (self.url, email, code, str)
+ errorText.append(e)
+
+ self.log.error('\n'.join(e))
+
+ self.__cleanup()
+
+ def __invitationFailure(self, result):
+ if __debug__:
+ self.printCurrentView("__invitationFailure")
+
+ e = "Failed to send invitation | %s | %s |" % (self.url, result.value)
+ self.log.error(e)
+ self.__cleanup()
+
+ def __cleanup(self):
+ self.account = None
+ self.url = None
+ self.from_addr = None
+ self.sendToList = None
+
+ def __createMessageText(self):
+ messageObject = common.getChandlerTransportMessage()
+ messageObject[message.createChandlerHeader(SharingConstants.SHARING_HEADER)] = self.url
+ messageObject['From'] = self.from_addr
+ messageObject['To'] = ', '.join(self.sendToList)
+ messageObject['Message-ID'] = message.createMessageID()
+ messageObject['User-Agent'] = common.CHANDLER_USERAGENT
+
+ return messageObject.as_string()
+
+ def __getData(self):
+ accountKind = Mail.MailParcel.getSMTPAccountKind()
+
+ """Get the first SMTP Account"""
+ for acc in Query.KindQuery().run([accountKind]):
+ self.account = acc
+ break
+
+ if self.account is None:
+ raise SharingException("No SMTP Account found to send invitation with")
+
+ imapList = self.account.accounts
+
+ if imapList is None:
+ raise SharingException("No IMAP Accounts associated with the SMTP account. Can not get replyToAddress.")
+
+ """Get the first IMAP Account"""
+ for imapAccount in imapList:
+ self.from_addr = imapAccount.replyToAddress.emailAddress
+ break
+
+ if self.from_addr is None:
+ raise SharingException("No replyToAddress found for IMAP Account")
+
Index: chandler/parcels/osaf/mail/common.py
diff -u chandler/parcels/osaf/mail/common.py:1.5 chandler/parcels/osaf/mail/common.py:1.6
--- chandler/parcels/osaf/mail/common.py:1.5 Thu Aug 19 17:33:12 2004
+++ chandler/parcels/osaf/mail/common.py Tue Aug 24 16:19:38 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.5 $"
-__date__ = "$Date: 2004/08/20 00:33:12 $"
+__revision__ = "$Revision: 1.6 $"
+__date__ = "$Date: 2004/08/24 23:19:38 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -10,7 +10,7 @@
import email.Message as Message
import email.Utils as Utils
-CHANDLER_USERAGENT = "Open Source Applications Foundation Chandler .4B Release"
+CHANDLER_USERAGENT = "Chandler/.4B Release"
CHANDLER_HEADER_PREFIX = "X-Chandler-"
ATTACHMENT_BODY_WARNING = "\tThe body of this message consists of Multiple Mime Parts.\n\tFor .4B Chandler does not support MIME Parts"
@@ -27,13 +27,13 @@
pass
def getChandlerTransportMessage():
- message = """Subject: ***FOR CHANDLER INTERNAL USE - DO NOT DELETE ***
+ message = \
+"""Subject: ***FOR CHANDLER INTERNAL USE - DO NOT DELETE ***
- This message is used for Chandler to Chandler communication and is
- not intended to be viewed by the user. Please do not delete this message
- as Chandler will manage this email automatically for you.
-
- """
+This message is used for Chandler to Chandler communication and is
+not intended to be viewed by the user. Please do not delete this message
+as Chandler will manage this email automatically for you.
+"""
return email.message_from_string(message)
Index: chandler/parcels/osaf/mail/message.py
diff -u chandler/parcels/osaf/mail/message.py:1.13 chandler/parcels/osaf/mail/message.py:1.14
--- chandler/parcels/osaf/mail/message.py:1.13 Thu Aug 19 16:59:55 2004
+++ chandler/parcels/osaf/mail/message.py Tue Aug 24 16:19:38 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.13 $"
-__date__ = "$Date: 2004/08/19 23:59:55 $"
+__revision__ = "$Revision: 1.14 $"
+__date__ = "$Date: 2004/08/24 23:19:38 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -112,7 +112,7 @@
if not hasValue(postfix):
return None
- return common.CHANDLER_HEASER_PREFIX + postfix
+ return common.CHANDLER_HEADER_PREFIX + postfix
def isChandlerHeader(header):
if not hasValue(header):
@@ -252,6 +252,8 @@
else:
messageObject['Message-ID'] = createMessageID()
+ messageObject['User-Agent'] = common.CHANDLER_USERAGENT
+
__populateParam(messageObject, 'Date', mailMessage.dateSentString)
__populateParam(messageObject, 'Subject', mailMessage.subject)
__populateParam(messageObject, 'Content-Type', mailMessage.contentType)
More information about the Commits
mailing list