def testMail(self): self.note = Note(itsView=self.view) Mail.MailStamp(self.note).add() self.checkStatus(0, 'DRAFT', 'NEITHER') # Remove the MailStamp; that should make it no longer a Draft Mail.MailStamp(self.note).remove() self.checkStatus(0)
def onSendShareItemEvent(self, event): """ Send or share the selected items """ selectedItems = self.__getProxiedSelectedItems(event) if len(selectedItems) == 0: return # Make sure we have an outbound account; returns False if the user # cancels out and we don't. if not sharing.ensureAccountSetUp(self.itsView, outboundMail=True): return sendableItems = [ item for item in selectedItems if self.__getSendabilityOf(item) in ('send', 'update') ] assert list(selectedItems) == sendableItems for item in sendableItems: # For now, make sure we've got a 'from' string. # @@@ BJS: this'll go away when we change 'from' to an # account picker popup. if has_stamp(item, Mail.MailStamp): mailObject = Mail.MailStamp(item) #XXX this should raise an error instead of # adding the me address since that results # in the incorrect sender getting added # which can confuse user if unicode(mailObject.fromAddress).strip() == u'': mailObject.fromAddress = mailObject.getCurrentMeEmailAddress( ) Block.Block.postEventByNameWithSender('SendMail', {'item': item})
def onSendShareItemEventUpdateUI(self, event): """ Generically enable Send-ing. """ # default to a disabled "Send" with a send-arrow enabled = False label = messages.SEND bitmap = "ApplicationBarSend.png" selectedItems = self.__getSelectedItems() if len(selectedItems) > 0: # Collect the states of all the items, so that we can change the # label to "Sent" if they're all in that state. sendStates = set( [self.__getSendabilityOf(item) for item in selectedItems]) if len(sendStates) == 1: result = sendStates.pop() if result == 'send': enabled = True elif result == 'update': enabled = True label = messages.UPDATE # use U-shaped Update bitmap bitmap = "ApplicationBarUpdate.png" elif result == 'sent': enabled = False label = messages.SENT if has_stamp(item, Mail.MailStamp): mailObject = Mail.MailStamp(item) if mailObject.itsItem.lastModification == Modification.updated: label = messages.UPDATED bitmap = "ApplicationBarUpdate.png" event.arguments['Enable'] = enabled event.arguments['Text'] = label event.arguments['Bitmap'] = bitmap
def testNoStamp(self): # Make sure that, even if we create a Note with a toAddress, # that doesn't show up in the who field note = Note(itsView=self.view) notStampedMsg = Mail.MailStamp(note) notStampedMsg.toAddress = [self.address] self.failUnless(not hasattr(notStampedMsg.itsItem, 'displayWho'))
def setAttributes(self, item, doWho=True): try: savedItems = self.savedAttrs except AttributeError: self.savedAttrs = {} savedAttrs = SavedAttrs() self.savedAttrs[item.itsName] = savedAttrs displayName = 'aTitleOrHeadline' item.displayName = displayName savedAttrs.displayName = displayName item.createdOn = self.savedAttrs[ item.itsName].createdOn = datetime.now(item.itsView.tzinfo.default) if has_stamp(item, pim.TaskStamp): task = pim.TaskStamp(item) # Add some attributes here... if has_stamp(item, pim.EventStamp): event = pim.EventStamp(item) if has_stamp(item, Mail.MailStamp): mail = Mail.MailStamp(item) """
def __getSendabilityOf(self, item): """ Return the sendable state of this item """ assert item is not None item = getattr(item, 'proxiedItem', item) if has_stamp(item, Mail.MailStamp): return Mail.MailStamp(item).getSendability() else: return 'not'
def CanReplyOrForward(self, selectedItem): # We used to test for whether the message had ever been # received by the mail service ("in", sort of), but Mimi # thinks outgoing messages should be replyable too. # return has_stamp(selectedItem, Mail.MailStamp) and \ # Mail.MailStamp(selectedItem).viaMailService return has_stamp(selectedItem, Mail.MailStamp) and \ Mail.MailStamp(selectedItem).getSendability() != 'not'
def testStampWelcomeNote(self): # Look up the welcome note ... welcome = schema.ns("osaf.app", self.view).WelcomeEvent # stamp it as a mail ... stampedWelcome = Mail.MailStamp(welcome) stampedWelcome.add() self.failUnlessEqual(list(stampedWelcome.mimeContent.mimeParts), []) self.failUnlessEqual(stampedWelcome.mimeContent.mimeType, 'message/rfc822')
def _replyOrForward(self, item, replyMethod): pim_ns = schema.ns('osaf.pim', self.itsView) main = schema.ns("osaf.views.main", self.itsView) if main.MainView.trashCollectionSelected(): # Items can not be created in the Trash # collection return replyMessage = replyMethod(self.itsView, Mail.MailStamp(item)) # select the outbox collection if there was a reply if replyMessage is not None: inCollection = pim_ns.inCollection if main.MainView.getSidebarSelectedCollection() is inCollection: # Replys and Forwards can not be created in the # In collection so move the selected sidebard collection # to the Dashboard sidebar = Block.Block.findBlockByName("Sidebar") sidebar.select(pim_ns.allCollection) #add to dashboard by making mine pim_ns.allCollection.add(replyMessage) replyMessage.mine = True collection = main.MainView.getSidebarSelectedCollection() # Add the item to the current collection collection.add(replyMessage) # by default the "from" field is selected, which looks funny; # so switch focus to the message body, except for "Forward", # which goes to the "To" field # @@@ [grant] Fix this if replyMethod is not Mail.forwardMessage: focusBlockName = 'NotesBlock' else: focusBlockName = 'EditMailTo' main.MainView.postEventByName('FocusSelectItems', { 'items': [replyMessage], 'focus': focusBlockName })
def runMailTest(self, incoming=False, outgoing=False): self.note = Note(itsView=self.view) mail = Mail.MailStamp(self.note) mail.add() self.checkStatus(0, 'DRAFT', 'NEITHER') inoutFlags = 0 if incoming: inoutFlags |= CommunicationStatus.IN mail.toAddress = self.address if outgoing: inoutFlags |= CommunicationStatus.OUT mail.fromAddress = self.address elif not incoming: inoutFlags |= CommunicationStatus.NEITHER self.checkStatus(inoutFlags, 'DRAFT') self.note.changeEditState(Modification.queued) self.checkStatus(inoutFlags, 'QUEUED') self.note.changeEditState(Modification.sent) self.checkStatus(inoutFlags, 'SENT') self.note.changeEditState(Modification.edited) self.checkStatus(inoutFlags, 'EDITED', 'UPDATE', 'DRAFT') # Remove the MailStamp; that should make it no longer a Draft mail.remove() self.checkStatus(0, 'EDITED') # Re-add the stamp mail.add() self.checkStatus(inoutFlags, 'EDITED', 'UPDATE', 'DRAFT') # and finally, re-send it self.note.changeEditState(Modification.updated) self.checkStatus(inoutFlags, 'UPDATE', 'SENT')