[Commits] (bkirsch) added fromAddress and collectionName to sharing

commits at osafoundation.org commits at osafoundation.org
Fri Aug 27 12:22:25 PDT 2004


Commit by: bkirsch
Modified files:
chandler/parcels/osaf/mail/debug.py 1.4 1.5
chandler/parcels/osaf/mail/imap.py 1.17 1.18
chandler/parcels/osaf/mail/sharing.py 1.6 1.7

Log message:
added fromAddress and collectionName to sharing

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/debug.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/imap.py.diff?r1=text&tr1=1.17&r2=text&tr2=1.18
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/mail/sharing.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7

Index: chandler/parcels/osaf/mail/imap.py
diff -u chandler/parcels/osaf/mail/imap.py:1.17 chandler/parcels/osaf/mail/imap.py:1.18
--- chandler/parcels/osaf/mail/imap.py:1.17	Wed Aug 25 17:48:58 2004
+++ chandler/parcels/osaf/mail/imap.py	Fri Aug 27 12:22:23 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.17 $"
-__date__      = "$Date: 2004/08/26 00:48:58 $"
+__revision__  = "$Revision: 1.18 $"
+__date__      = "$Date: 2004/08/27 19:22:23 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -21,8 +21,12 @@
 import common as common
 import repository.item.Query as Query
 
-#XXX: Need to make sure all the flags are in place to prevent a non-ssl session if 
-#     ssl required
+"""
+   twisted.IMAP4Client Exceptions:
+      1. IMAP4Exception
+      2. IllegalServerResponse
+      3. SSL?
+"""
 
 class ChandlerIMAP4Client(imap4.IMAP4Client):
 
@@ -30,6 +34,20 @@
         imap4.IMAP4Client.__init__(self, contextFactory)
         self.useSSL = useSSL
 
+    def sendLine(self, line):
+        """This method utilized for debugging SSL IMAP4 Communications"""
+        if __debug__ and self.useSSL:
+            self.factory.log.info(">>> %s" % line)
+
+        imap4.IMAP4Client.sendLine(self, line)
+
+    def lineReceived(self, line):
+        """This method utilized for debugging SSL IMAP4 Communications"""
+        if __debug__ and self.useSSL:
+            self.factory.log.info("<<< %s" % line)
+
+        imap4.IMAP4Client.lineReceived(self, line)
+
     def serverGreeting(self, caps):
         """
         This method overides C{imap4.IMAP4Client}.
@@ -53,7 +71,7 @@
 class ChandlerIMAP4Factory(protocol.ClientFactory):
     protocol = ChandlerIMAP4Client
 
-    def __init__(self, deferred, useSSL=False):
+    def __init__(self, deferred, log, useSSL=False):
         """
         A C{protocol.ClientFactory} that creates C{ChandlerIMAP4Client} instances
         and stores the callback and errback to be used by the C{ChandlerIMAP4Client} instances
@@ -61,13 +79,22 @@
         @param: deferred: A C{defer.Deferred} to callback when connected to the IMAP server 
                           and errback if no connection or command failed
         @type deferred: C{defer.Deferred}
+
+        @param: log: A log instance
+        @type log: C{}
+
+        @param: useSSL: A boolean to indicate whether to run in SSL mode
+        @type useSSL: C{boolean}
+
         @return: C{None}
         """
+        print "Log ", type(log)
 
         if not isinstance(deferred, defer.Deferred):
             raise IMAPException("deferred must be a defer.Deferred instance")
 
         self.deferred = deferred
+        self.log = log
         self.useSSL = useSSL
 
     def buildProtocol(self, addr):
@@ -150,7 +177,7 @@
         d.addCallback(self.loginClient)
         d.addErrback(self.catchErrors)
 
-        factory = ChandlerIMAP4Factory(d, useSSL)
+        factory = ChandlerIMAP4Factory(d, self.log, useSSL)
 
         if useSSL:
             reactor.connectSSL(host, port, factory, ssl.ClientContextFactory(useM2=1))
@@ -317,7 +344,8 @@
             totalDownloaded = 0
             foundInvitation = False
             sharingInvitations = {}
-            sharingHeader = sharing.getChandlerSharingHeader() 
+            sharingHeader = sharing.getChandlerSharingHeader()
+            div = sharing.SharingConstants.SHARING_DIVIDER
 
             for msg in msgs:
 
@@ -327,7 +355,9 @@
                 messageObject = email.message_from_string(messageText)
 
                 if messageObject[sharingHeader] is not None:
-                    sharingInvitations[uid] = messageObject[sharingHeader]
+                    url, collectionName = messageObject[sharingHeader].split(div)
+                    fromAddress = messageObject['From']
+                    sharingInvitations[uid] = (url, collectionName, fromAddress)
                     foundInvitation = True
                     continue
 
@@ -379,11 +409,13 @@
 
         return self.proto.expunge()
 
-    def _processSharingRequests(self, result, urls):
+    def _processSharingRequests(self, result, invites):
         if __debug__:
             self.printCurrentView("_processSharingRequests")
 
-        sharing.receivedInvitation(urls)
+        for invite in invites:
+            url, collectionName, fromAddress = invite
+            sharing.receivedInvitation(url, collectionName, fromAddress)
 
     def __getLastUID(self):
         return self.account.messageDownloadSequence

Index: chandler/parcels/osaf/mail/sharing.py
diff -u chandler/parcels/osaf/mail/sharing.py:1.6 chandler/parcels/osaf/mail/sharing.py:1.7
--- chandler/parcels/osaf/mail/sharing.py:1.6	Wed Aug 25 15:34:42 2004
+++ chandler/parcels/osaf/mail/sharing.py	Fri Aug 27 12:22:23 2004
@@ -22,47 +22,59 @@
     from StringIO import StringIO
 
 
-def receivedInvitation(url):
+def receivedInvitation(url, collectionName, fromAddress):
     """
        Calls osaf.framework.sharing.anounceSharingUrl.
-       If url is a C{list} will call the above method
-       for each URL in the C{list} otherwise will call
-       the above methodf with the url C{str} passed in.
 
-       @param url: The invitation url or a list of invitation url's
-       @type: C: {str} or C{list} of C{str}'s
+       @param url: The url to share
+       @type url: C{str}
+
+       @param collectionName: The name of the collection
+       @type collectionName: C{str}
+
+       @param fromAddress: The email address of the person sending the invite
+       @type: C{str} or C{EmailAddress}
     """
 
-    if isinstance(url, list):
-       for u in url:
-           if not isinstance(u, str):
-               raise SharingException("URL List contains a value that is not a String")
+    if not isinstance(url, str):
+        raise SharingException("URL must be a String")
+
+    if not isinstance(collectionName, str):
+        raise SharingException("collectionName must be a String")
+
+    if isinstance(fromAddress, Mail.EmailAddress):
+        fromAddress = message.format_addr(fromAddress)
 
-           chandlerSharing.Sharing.announceSharingUrl(u)
+    elif not isinstance(fromAddress, str):
+        raise SharingException("fromAddress must be a String or a Mail.EmailAddress")
 
-    elif isinstance(url, str):
-        chandlerSharing.Sharing.announceSharingUrl(url)
+    chandlerSharing.Sharing.announceSharingInvitation(url, collectionName, fromAddress)
 
-    else:
-        raise SharingException("URL must be a list of Strings or a String")
 
-def sendInvitation(url, sendToList):
-    SMTPInvitationSender(url, sendToList).sendInvitation()
+def sendInvitation(url, collectionName, sendToList):
+    SMTPInvitationSender(url, collectionName, sendToList).sendInvitation()
 
 class SharingConstants(object):
-    SHARING_HEADER = "Sharing-URL"
+    SHARING_HEADER  = "Sharing-URL"
+    SHARING_DIVIDER = ";"
 
 class SharingException(Exception):
     pass
 
 class SMTPInvitationSender(RepositoryView.AbstractRepositoryViewManager):
-    def __init__(self, url, sendToList, account=None):
+    def __init__(self, url, collectionName, sendToList, account=None):
         if account is not None and not account.isItemOf(Mail.MailParcel.getSMTPAccountKind()):
             raise SharingException("You must pass a SMTPAccount instance")
 
         if not isinstance(url, str):
             raise SharingException("URL must be a String")
 
+        if isinstance(collectionName, unicode):
+            collectionName = str(collectionName)
+
+        elif not isinstance(collectionName, str):
+            raise SharingException("collectionName must be a String or Unicode")
+
         if not isinstance(sendToList, list):
             raise SharingException("sendToList must be of a list of email addresses")
 
@@ -73,6 +85,7 @@
         self.account = None
         self.from_addr = None
         self.url = url
+        self.collectionName = collectionName
         self.sendToList = sendToList
         self.accountUUID = None
 
@@ -138,14 +151,15 @@
             for address in result[1]:
                 addrs.append(address[0])
 
-            info = "Sharing invitation %s sent to [%s]" % (self.url, ", ".join(addrs))
+            info = "Sharing invitation (%s: %s) sent to [%s]" % (self.collectionName, 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)
+                e = "Failed to send invitation | (%s: %s) | %s | %s | %s |" % (self.collectionName, self.url,
+                                                                               email, code, str)
                 errorText.append(e)
 
             self.log.error('\n'.join(e))
@@ -156,19 +170,22 @@
         if __debug__:
             self.printCurrentView("__invitationFailure")
 
-        e = "Failed to send invitation | %s | %s |" % (self.url, result.value)
+        e = "Failed to send invitation | (%s: %s) | %s |" % (self.collectionName, self.url, result.value)
         self.log.error(e)
         self.__cleanup()
 
     def __cleanup(self):
         self.account = None
         self.url = None
+        self.collectionName = None
         self.from_addr = None
         self.sendToList = None
 
     def __createMessageText(self):
+        sendStr = "%s%s%s" % (self.url, SharingConstants.SHARING_DIVIDER, self.collectionName)
+
         messageObject = common.getChandlerTransportMessage()
-        messageObject[getChandlerSharingHeader()] = self.url
+        messageObject[getChandlerSharingHeader()] = sendStr
         messageObject['From'] = self.from_addr
         messageObject['To'] = ', '.join(self.sendToList)
         messageObject['Message-ID'] = message.createMessageID()

Index: chandler/parcels/osaf/mail/debug.py
diff -u chandler/parcels/osaf/mail/debug.py:1.4 chandler/parcels/osaf/mail/debug.py:1.5
--- chandler/parcels/osaf/mail/debug.py:1.4	Wed Aug 25 12:45:31 2004
+++ chandler/parcels/osaf/mail/debug.py	Fri Aug 27 12:22:23 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.4 $"
-__date__      = "$Date: 2004/08/25 19:45:31 $"
+__revision__  = "$Revision: 1.5 $"
+__date__      = "$Date: 2004/08/27 19:22:23 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -21,7 +21,7 @@
 
 
 def sendInvitation():
-    sharing.sendInvitation("http://test.com", ['brian at localhost'])
+    sharing.sendInvitation("http://test.com", "In", ['brian at localhost'])
 
 def sendSMTPMessage():
     account, replyToAddress = smtp.getSMTPAccount()



More information about the Commits mailing list