def messageObjectToKind(view, messageObject, messageText=None): """ This method converts a email message string to a Chandler C{Mail.MailMessage} object @param messageObject: A C{email.Message} object representation of a mail message @type messageObject: C{email.Message} @return: C{Mail.MailMessage} """ assert isinstance(messageObject, Message.Message), \ "messageObject must be a Python email.Message.Message instance" assert len(messageObject.keys()) > 0, \ "messageObject data is not a valid RFC2882 message" assert messageText is None or isinstance(messageText, str), \ "messageText can either be a string or None" m = Mail.MailMessage(view=view) """Save the original message text in a text blob""" if messageText is None: messageText = messageObject.as_string() m.rfc2822Message = utils.dataToBinary(m, "rfc2822Message", messageText, \ 'message/rfc822', 'bz2') counter = utils.Counter() bodyBuffer = [] buf = None if verbose(): if messageObject.has_key("Message-ID"): messageId = messageObject["Message-ID"] else: messageId = "<Unknown Message>" buf = ["Message: %s\n-------------------------------" % messageId] __parsePart(view, messageObject, m, bodyBuffer, counter, buf) """If the message has attachments set hasMimeParts to True""" if len(m.mimeParts) > 0: m.hasMimeParts = True body = (constants.LF.join(bodyBuffer)).replace(constants.CR, constants.EMPTY) m.body = utils.unicodeToText(m, "body", body, indexText=False) __parseHeaders(view, messageObject, m) if verbose(): logging.warn("\n\n%s\n\n" % '\n'.join(buf)) return m
def testWho(self): msg = Mail.MailMessage(itsView=self.view, subject=u"Hi!") msg.toAddress = [self.address] # Make sure the 'displayWho' field was set correctly self.failUnlessEqual(msg.itsItem.displayWho, u"Grant Baillie") # Now, remove the stamp... msg.remove() # ... and check the who field is gone self.failUnless(not hasattr(msg.itsItem, 'displayWho'))
def __init__(self, view, type, logger): if not type in ["Event", "Note", "Task", "MailMessage", "Collection"]: return else: self.isNote = self.isEvent = self.isTask = self.isMessage = self.allDay = False self.logger = logger now = datetime.now() if type == "Event": # New Calendar Event # set up the expected data dictionary with the default values self.expected_field_dict = {"displayName" : "New Event", "startTime" : now, "endTime" : now, "duration" : timedelta(minutes=60)} # create a default Calendar Event item = Calendar.CalendarEvent(view=view) item.startTime = self.expected_field_dict["startTime"] # because startTime is needed befor duration self.isEvent = True elif type == "Note": # New Note # set up the expected data dictionary with the default values self.expected_field_dict = {"displayName" : "New Note", "createdOn" : now} # create a default Note item = pim.Note(view=view) self.isNote = True elif type == "Task": # New Task # set up the expected data dictionary with the default values self.expected_field_dict = {"displayName" : "New Task", "createdOn" : now} # create a default Task item = pim.Task(view=view) self.isTask = True elif type == "MailMessage": # New Mail Message # set up the expected data dictionary with the default values email = Mail.EmailAddress(view=view) email.emailAddress = 'me' self.expected_field_dict = {"subject" : "untitled", "dateSent" : now, "fromAddress" : email} # create a default Message item = Mail.MailMessage(view=view) self.isMessage = True elif type == "Collection": # New Collection # set up the expected data dictionary with the default values self.expected_field_dict = {"displayName" : "Untitled"} # create a default Collection item = pim.ItemCollection(view=view) # fields affectation for field in self.expected_field_dict.keys(): setattr(item, field, self.expected_field_dict[field]) self.item = item if type =="Collection": Sgf.SidebarAdd(self.item) Sgf.SidebarSelect(self.item) else: Sgf.SummaryViewSelect(self.item)
def GenerateMailMessage(view, tzinfo=None): global M_FROM message = Mail.MailMessage(itsView=view) body = M_TEXT outbound = random.randint(0, 1) type = random.randint(1, 8) numTo = random.randint(1, 3) if M_FROM is None: M_FROM = GenerateCalendarParticipant(view) message.fromAddress = M_FROM for num in range(numTo): message.toAddress.append(GenerateCalendarParticipant(view)) message.subject = random.choice(TITLES) if TEST_I18N: message.subject = uw(message.subject) message.dateSent = datetime.now(tzinfo) if outbound: message.outgoingMessage() message.itsItem.changeEditState(Modification.sent, who=M_FROM) else: message.incomingMessage() if type == EVENT: Calendar.EventStamp(message).add() body += M_EVENT if type == TASK: pim.TaskStamp(message).add() body += M_TASK if type == BOTH: Calendar.EventStamp(message).add() pim.TaskStamp(message).add() body += M_BOTH if TEST_I18N: body = uw(body) message.body = body message.itsItem.setTriageStatus(randomEnum(pim.TriageEnum)) return message.itsItem
def testOutBoxQueryWithMail(self): self.loadParcels(['parcel:osaf.pim.mail']) import osaf.pim.mail as Mail # create an outbound Mail item view = self.rep.view aMessage = Mail.MailMessage(view=view) aMessage.isInbound = True view.commit() # now run the query qString = u"for i in '//parcels/osaf/pim/mail/MailMessageMixin' where i.isInbound == True" results = self._compileQuery('testOutboxQuery', qString) self._checkQuery(lambda i: not i.isInbound is True, results)
def __getMailMessage(self): if self.__mailMessage is not None: return self.__mailMessage view = self.rep.view m = Mail.MailMessage(view=view) m.fromAddress = Mail.EmailAddress(view=view) m.fromAddress.emailAddress = "*****@*****.**" toOne = Mail.EmailAddress(view=view) toOne.emailAddress = "*****@*****.**" toTwo = Mail.EmailAddress(view=view) toTwo.emailAddress = "*****@*****.**" toTwo.fullName = "John Johnson" m.toAddress = [] m.toAddress.append(toOne) m.toAddress.append(toTwo) ccOne = Mail.EmailAddress(view=view) ccOne.emailAddress = "*****@*****.**" m.ccAddress = [] m.ccAddress.append(ccOne) m.subject = "test mail" m.headers['Content-Length'] = "75" m.headers['Content-Type'] = "text/plain; charset=utf-8; format=flowed" m.headers['Content-Transfer-Encoding'] = "7bit" m.headers['Mime-Version'] = "1.0" m.headers[ 'Received'] = "from [192.168.101.37] (w002.z065106067.sjc-ca.dsl.cnc.net [65.106.67.2]) by kahuna.osafoundation.org (8.12.8/8.12.8) with ESMTP id i7GKWWpo017020; Mon, 16 Aug 2004 13:32:32 -0700" m.headers[ 'References'] = "<*****@*****.**> <*****@*****.**> <*****@*****.**> <*****@*****.**>" dateString = "Mon, 9 Aug 2004 13:55:15 -0700" m.dateSent = datetime.fromtimestamp( mktime(emailUtils.parsedate(dateString))) m.dateSentString = dateString m.body = utils.unicodeToText(m, "body", u"This is the body") m.rfc2822Message = utils.dataToBinary(m, "rfc2822Message", self.__mail) self.__mailMessage = m return self.__mailMessage
def GenerateMailMessage(view): global M_FROM message = Mail.MailMessage(view=view) body = M_TEXT outbound = random.randint(0, 1) type = random.randint(1, 8) numTo = random.randint(1, 3) if M_FROM is None: M_FROM = GenerateCalendarParticipant(view) message.fromAddress = M_FROM for num in range(numTo): message.toAddress.append(GenerateCalendarParticipant(view)) message.subject = random.choice(TITLES) message.dateSent = datetime.now() if outbound: acc = Mail.getCurrentSMTPAccount(view)[0] message.outgoingMessage(acc) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: acc = Mail.getCurrentMailAccount(view) message.incomingMessage(acc) if type == EVENT: message.StampKind('add', Calendar.CalendarEventMixin.getKind(message.itsView)) body += M_EVENT if type == TASK: message.StampKind('add', pim.TaskMixin.getKind(message.itsView)) body += M_TASK if type == BOTH: message.StampKind('add', pim.TaskMixin.getKind(message.itsView)) message.StampKind('add', Calendar.CalendarEventMixin.getKind(message.itsView)) body += M_BOTH message.body = message.getAttributeAspect('body', 'type').makeValue(body) return message
def __getMailMessage(self, addNewLine=False): view = self.view m = Mail.MailMessage(itsView=view) m.fromAddress = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**") toOne = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**") toTwo = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**", "John Johnson") m.toAddress = [] m.toAddress.append(toOne) m.toAddress.append(toTwo) ccOne = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**") m.ccAddress = [] m.ccAddress.append(ccOne) m.subject = "test mail" if addNewLine: m.subject += "\n" m.headers['Content-Length'] = "75" m.headers['Content-Type'] = "text/plain; charset=utf-8; format=flowed" m.headers['Content-Transfer-Encoding'] = "7bit" m.headers['Mime-Version'] = "1.0" m.headers['Received'] = "from [192.168.101.37] (w002.z065106067.sjc-ca.dsl.cnc.net [65.106.67.2]) by kahuna.test.com (8.12.8/8.12.8) with ESMTP id i7GKWWpo017020; Mon, 16 Aug 2004 13:32:32 -0700" m.headers['References'] = "<*****@*****.**> <*****@*****.**> <*****@*****.**> <*****@*****.**>" dateString = "Mon, 9 Aug 2004 13:55:15 -0700" m.dateSent = datetime.fromtimestamp(emailUtils.mktime_tz(emailUtils.parsedate_tz(dateString)), view.tzinfo.getInstance("Etc/GMT-7")) m.dateSentString = dateString m.itsItem.body = u"This is the body" if not IGNORE_ATTACHMENTS: m.rfc2822Message = utils.dataToBinary(m, "rfc2822Message", self.__mail) self.__mailMessage = m return self.__mailMessage
def __createMessage(self): self.repository.view.refresh() m = Mail.MailMessage(view=self.repository.view) m.subject = self.__createSubject() m.fromAddress = self.fromAddress sendStr = makeSharingHeaderValue(self.url, self.collectionName) m.chandlerHeaders[message.createChandlerHeader( constants.SHARING_HEADER)] = sendStr for address in self.sendToList: assert isinstance(address, Mail.EmailAddress), \ "sendToList can only contain EmailAddres Object" m.toAddress.append(address) m.body = utils.strToText(m, "body", self.collectionBody) self.repository.view.commit() return m
def testMail(self): """ Simple test for creating instances of email related kinds """ self.loadParcel("parcel:osaf.pim.mail") # Test the globals mailPath = Path('//parcels/osaf/pim/mail') view = self.rep.view self.assertEqual(Mail.AccountBase.getKind(view), view.find(Path(mailPath, 'AccountBase'))) self.assertEqual(Mail.IMAPAccount.getKind(view), view.find(Path(mailPath, 'IMAPAccount'))) self.assertEqual(Mail.SMTPAccount.getKind(view), view.find(Path(mailPath, 'SMTPAccount'))) self.assertEqual(Mail.MailDeliveryError.getKind(view), view.find(Path(mailPath, 'MailDeliveryError'))) self.assertEqual(Mail.MailDeliveryBase.getKind(view), view.find(Path(mailPath, 'MailDeliveryBase'))) self.assertEqual(Mail.SMTPDelivery.getKind(view), view.find(Path(mailPath, 'SMTPDelivery'))) self.assertEqual(Mail.IMAPDelivery.getKind(view), view.find(Path(mailPath, 'IMAPDelivery'))) self.assertEqual(Mail.MIMEBase.getKind(view), view.find(Path(mailPath, 'MIMEBase'))) self.assertEqual(Mail.MIMENote.getKind(view), view.find(Path(mailPath, 'MIMENote'))) self.assertEqual(Mail.MailMessage.getKind(view), view.find(Path(mailPath, 'MailMessage'))) self.assertEqual(Mail.MailMessageMixin.getKind(view), view.find(Path(mailPath, 'MailMessageMixin'))) self.assertEqual(Mail.MIMEBinary.getKind(view), view.find(Path(mailPath, 'MIMEBinary'))) self.assertEqual(Mail.MIMEText.getKind(view), view.find(Path(mailPath, 'MIMEText'))) self.assertEqual(Mail.MIMEContainer.getKind(view), view.find(Path(mailPath, 'MIMEContainer'))) self.assertEqual(Mail.MIMESecurity.getKind(view), view.find(Path(mailPath, 'MIMESecurity'))) self.assertEqual(Mail.EmailAddress.getKind(view), view.find(Path(mailPath, 'EmailAddress'))) # Construct sample items accountBaseItem = Mail.AccountBase("accountBaseItem", view=view) imapAccountItem = Mail.IMAPAccount("imapAccountItem", view=view) smtpAccountItem = Mail.SMTPAccount("smtpAccountItem", view=view) mailDeliveryErrorItem = Mail.MailDeliveryError("mailDeliveryErrorItem", view=view) mailDeliveryBaseItem = Mail.MailDeliveryBase("mailDeliveryBaseItem", view=view) smtpDeliveryItem = Mail.SMTPDelivery("smtpDeliveryItem", view=view) imapDeliveryItem = Mail.IMAPDelivery("imapDeliveryItem", view=view) mimeBaseItem = Mail.MIMEBase("mimeBaseItem", view=view) mimeNoteItem = Mail.MIMENote("mimeNoteItem", view=view) mailMessageItem = Mail.MailMessage("mailMessageItem", view=view) mailMessageMixinItem = Mail.MailMessageMixin("mailMessageMixinItem", view=view) mimeBinaryItem = Mail.MIMEBinary("mimeBinaryItem", view=view) mimeTextItem = Mail.MIMEText("mimeTextItem", view=view) mimeContainerItem = Mail.MIMEContainer("mimeContainerItem", view=view) mimeSecurityItem = Mail.MIMESecurity("mimeSecurityItem", view=view) emailAddressItem = Mail.EmailAddress("emailAddressItem", view=view) # Double check kinds self.assertEqual(accountBaseItem.itsKind, Mail.AccountBase.getKind(view)) self.assertEqual(imapAccountItem.itsKind, Mail.IMAPAccount.getKind(view)) self.assertEqual(smtpAccountItem.itsKind, Mail.SMTPAccount.getKind(view)) self.assertEqual(mailDeliveryErrorItem.itsKind, Mail.MailDeliveryError.getKind(view)) self.assertEqual(mailDeliveryBaseItem.itsKind, Mail.MailDeliveryBase.getKind(view)) self.assertEqual(smtpDeliveryItem.itsKind, Mail.SMTPDelivery.getKind(view)) self.assertEqual(imapDeliveryItem.itsKind, Mail.IMAPDelivery.getKind(view)) self.assertEqual(mimeBaseItem.itsKind, Mail.MIMEBase.getKind(view)) self.assertEqual(mimeNoteItem.itsKind, Mail.MIMENote.getKind(view)) self.assertEqual(mailMessageItem.itsKind, Mail.MailMessage.getKind(view)) self.assertEqual(mailMessageMixinItem.itsKind, Mail.MailMessageMixin.getKind(view)) self.assertEqual(mimeBinaryItem.itsKind, Mail.MIMEBinary.getKind(view)) self.assertEqual(mimeTextItem.itsKind, Mail.MIMEText.getKind(view)) self.assertEqual(mimeContainerItem.itsKind, Mail.MIMEContainer.getKind(view)) self.assertEqual(mimeSecurityItem.itsKind, Mail.MIMESecurity.getKind(view)) self.assertEqual(emailAddressItem.itsKind, Mail.EmailAddress.getKind(view)) accountBaseItem = self.__populateAccount(accountBaseItem) smtpAccountItem = self.__populateAccount(smtpAccountItem) imapAccountItem = self.__populateAccount(imapAccountItem) mailDeliveryErrorItem.errorCode = 25 mailDeliveryErrorItem.errorString = "Test String" mailDeliveryErrorItem.errorDate = datetime.now() smtpDeliveryItem.state = "DRAFT" smtpDeliveryItem.deliveryError = mailDeliveryErrorItem imapDeliveryItem.uid = 0 mimeBaseItem.mimeType = "SGML" mimeBinaryItem.mimeType = "APPLICATION" mimeTextItem.mimeType = "PLAIN" mimeContainerItem.mimeType = "ALTERNATIVE" mimeSecurityItem.mimeType = "SIGNED" # Literal properties mailMessageItem.dateSent = datetime.now() mailMessageItem.dateReceived = datetime.now() mailMessageItem.subject = "Hello" mailMessageItem.spamScore = 5 # Item Properties emailAddressItem.emailAddress = "*****@*****.**" mailMessageItem.replyAddress = emailAddressItem self._reopenRepository() view = self.rep.view contentItemParent = view.findPath("//userdata") mailMessageItem = contentItemParent.getItemChild("mailMessageItem") #Test cloud membership items = mailMessageItem.getItemCloud('copying') self.assertEqual(len(items), 1)
def testMail(self): """ Simple test for creating instances of email related kinds """ self.loadParcel("osaf.pim.mail") # Test the globals mailPath = Path('//parcels/osaf/pim/mail') view = self.view self.assertEqual(Mail.AccountBase.getKind(view), view.find(Path(mailPath, 'AccountBase'))) self.assertEqual(Mail.IMAPAccount.getKind(view), view.find(Path(mailPath, 'IMAPAccount'))) self.assertEqual(Mail.SMTPAccount.getKind(view), view.find(Path(mailPath, 'SMTPAccount'))) self.assertEqual(schema.itemFor(Mail.MIMEBase, view), view.find(Path(mailPath, 'MIMEBase'))) self.assertEqual(schema.itemFor(Mail.MIMENote, view), view.find(Path(mailPath, 'MIMENote'))) self.assertEqual(schema.itemFor(Mail.MailStamp, view), view.find(Path(mailPath, 'MailStamp'))) self.assertEqual(schema.itemFor(Mail.MIMEBinary, view), view.find(Path(mailPath, 'MIMEBinary'))) self.assertEqual(schema.itemFor(Mail.MIMEText, view), view.find(Path(mailPath, 'MIMEText'))) self.assertEqual(schema.itemFor(Mail.MIMEContainer, view), view.find(Path(mailPath, 'MIMEContainer'))) self.assertEqual(schema.itemFor(Mail.MIMESecurity, view), view.find(Path(mailPath, 'MIMESecurity'))) self.assertEqual(Mail.EmailAddress.getKind(view), view.find(Path(mailPath, 'EmailAddress'))) # Construct sample items accountBaseItem = Mail.AccountBase("accountBaseItem", itsView=view) imapAccountItem = Mail.IMAPAccount("imapAccountItem", itsView=view) smtpAccountItem = Mail.SMTPAccount("smtpAccountItem", itsView=view) mimeBaseObject = Mail.MIMEBase("mimeBaseItem", itsView=view) mimeNoteObject = Mail.MIMENote("mimeNoteItem", itsView=view) mailMessageObject = Mail.MailMessage("mailMessageItem", itsView=view) mimeBinaryObject = Mail.MIMEBinary("mimeBinaryItem", itsView=view) mimeTextObject = Mail.MIMEText("mimeTextItem", itsView=view) mimeContainerObject = Mail.MIMEContainer("mimeContainerItem", itsView=view) mimeSecurityObject = Mail.MIMESecurity("mimeSecurityItem", itsView=view) emailAddressItem = Mail.EmailAddress("emailAddressItem", itsView=view) # Double check kinds self.assertEqual(accountBaseItem.itsKind, Mail.AccountBase.getKind(view)) self.assertEqual(imapAccountItem.itsKind, Mail.IMAPAccount.getKind(view)) self.assertEqual(smtpAccountItem.itsKind, Mail.SMTPAccount.getKind(view)) self.failUnless(isinstance(mimeBaseObject, Mail.MIMEBase)) self.failUnless(isinstance(mimeNoteObject, Mail.MIMENote)) self.failUnless(isinstance(mailMessageObject, Mail.MailStamp)) self.failUnless(isinstance(mailMessageObject.itsItem, Note)) self.failUnless(has_stamp(mailMessageObject, Mail.MailStamp)) self.failUnless(isinstance(mimeBinaryObject, Mail.MIMEBinary)) self.failUnless(isinstance(mimeTextObject, Mail.MIMEText)) self.failUnless(isinstance(mimeContainerObject, Mail.MIMEContainer)) self.failUnless(isinstance(mimeSecurityObject, Mail.MIMESecurity)) self.assertEqual(emailAddressItem.itsKind, Mail.EmailAddress.getKind(view)) accountBaseItem = self.__populateAccount(accountBaseItem) smtpAccountItem = self.__populateAccount(smtpAccountItem) imapAccountItem = self.__populateAccount(imapAccountItem) mimeBaseObject.mimeType = "SGML" mimeBinaryObject.mimeType = "APPLICATION" mimeTextObject.mimeType = "PLAIN" mimeContainerObject.mimeType = "ALTERNATIVE" mimeSecurityObject.mimeType = "SIGNED" # Literal properties mailMessageObject.dateSent = datetime.now(view.tzinfo.default) mailMessageObject.subject = uw("Hello") self.assertEqual(mailMessageObject.subject, mailMessageObject.itsItem.displayName) #mailMessageObject.spamScore = 5 # Item Properties emailAddressItem.emailAddress = u"*****@*****.**" mailMessageObject.replyToAddress = emailAddressItem self._reopenRepository() view = self.view contentItemParent = view.findPath("//userdata") mailMessageItem = contentItemParent.getItemChild("mailMessageItem") #Test cloud membership items = mailMessageItem.getItemCloud('copying') self.assertEqual(len(items), 3) # item & reply-to address, mimeContent
def testStamping(self): view = self.sandbox.itsView # Get the stamp kinds mailStamp = Mail.MailStamp taskStamp = pim.TaskStamp eventStamp = Calendar.EventStamp noteKind = pim.Note.getKind(view) # start out with a Note aNote = pim.Note("noteItem1", itsParent=self.sandbox) self.setAttributes(aNote, doWho=False) self.assertAttributes(aNote) add = 'add' remove = 'remove' # stamp everything on and off the note self.traverseStampSquence(aNote, ((add, mailStamp), (add, taskStamp), (add, eventStamp), (remove, eventStamp), (remove, taskStamp), (remove, mailStamp))) # stamp everything on again, remove in a different order self.traverseStampSquence(aNote, ((add, mailStamp), (add, taskStamp), (add, eventStamp), (remove, mailStamp), (remove, taskStamp), (remove, eventStamp))) self.assertAttributes(aNote) # Create a Task, and do all kinds of stamping on it aTask = pim.Task("aTask", itsParent=self.sandbox).itsItem self.setAttributes(aTask) self.traverseStampSquence(aTask, ((add, eventStamp), (remove, taskStamp))) # now it's an Event self.traverseStampSquence(aTask, ((add, mailStamp), (remove, mailStamp))) self.traverseStampSquence(aTask, ((add, mailStamp), (add, taskStamp), (remove, mailStamp), (remove, taskStamp))) self.traverseStampSquence(aTask, ((add, taskStamp), (add, mailStamp), (remove, mailStamp), (remove, taskStamp))) self.traverseStampSquence(aTask, ((add, mailStamp), (remove, eventStamp))) # now it's a Mail self.traverseStampSquence(aTask, ((add, taskStamp), (remove, mailStamp))) # it's a Task again self.traverseStampSquence(aTask, ((add, mailStamp), (remove, taskStamp))) self.traverseStampSquence(aTask, ((add, taskStamp), (remove, mailStamp))) # it's a Task again self.traverseStampSquence(aTask, ((add, eventStamp), (remove, taskStamp), (add, mailStamp), (remove, eventStamp), (add, taskStamp), (remove, mailStamp))) self.failUnless(has_stamp(aTask, taskStamp)) # check stamping on an Event anEvent = Calendar.CalendarEvent("anEvent", itsParent=self.sandbox).itsItem self.setAttributes(anEvent) # round-robin its Kind back to event self.traverseStampSquence(anEvent, ((add, mailStamp), (remove, eventStamp), (add, taskStamp), (remove, mailStamp), (add, eventStamp), (remove, taskStamp))) self.failUnless(has_stamp(anEvent, eventStamp)) # check stamping on a Mail Message aMessage = Mail.MailMessage("aMessage", itsParent=self.sandbox).itsItem self.setAttributes(aMessage) self.traverseStampSquence(aMessage, ((add, eventStamp), (add, taskStamp), (remove, eventStamp), (remove, taskStamp))) self.failUnless(has_stamp(aMessage, mailStamp)) # now mixin some arbitrary Kind #anotherKind = view.findPath('//parcels/osaf/framework/blocks/Block') # stamp an event, mail, task with another kind #aNote.StampKind(add, anotherKind) #aTask.StampKind(add, anotherKind) #anEvent.StampKind(add, anotherKind) #aMessage.StampKind(add, anotherKind) #self.assertKinds(aNote, (noteKind, anotherKind)) #self.assertKinds(aTask, (taskKind, anotherKind)) #self.assertKinds(anEvent, (eventKind, anotherKind)) #self.assertKinds(aMessage, (mailKind, anotherKind)) # unstamp with another kind #aNote.StampKind(remove, anotherKind) #aTask.StampKind(remove, anotherKind) #anEvent.StampKind(remove, anotherKind) #aMessage.StampKind(remove, anotherKind) # see that they still have their attributes #self.assertKinds(aNote, (noteKind, )) #self.assertKinds(aTask, (taskKind, )) #self.assertKinds(anEvent, (eventKind, )) #self.assertKinds(aMessage, (mailKind, )) # Test some failure cases # These cases should produce suitable warning messages in Chandler.log if testFailureCases: anotherEvent = Calendar.CalendarEvent( "anotherEvent", itsParent=self.sandbox).itsItem self.setAttributes(anotherEvent) self.failUnless(has_stamp(anotherEvent, eventStamp)) # Could use assertRaises here, but it's syntax with respect to parameters is # not clear with my complex arguments, so try/except/else is more readable. try: # double stamping self.traverseStampSquence(anotherEvent, ((add, mailStamp), (add, mailStamp))) except StampAlreadyPresentError: pass else: self.failUnless(False, "Double stamping should raise an exception!") try: # unstamping something not present self.traverseStampSquence(anotherEvent, ((remove, taskStamp), )) except StampNotPresentError: pass else: self.failUnless( False, "Unstamping a stamp not present should raise an exception!" ) # Test for Bug:6151: Make sure items don't disappear # from the all collection if they're unstamped # # Make an email ... aMessage = Mail.MailMessage("aNewMessage", itsParent=self.sandbox) self.setAttributes(aMessage.itsItem) # Make sure it's in "Out" aMessage.fromMe = True outCollection = schema.ns("osaf.pim", view).outCollection self.failUnless(aMessage.itsItem in outCollection) # unstamp its emailness self.traverseStampSquence(aMessage.itsItem, (('add', taskStamp), ('remove', mailStamp))) allCollection = schema.ns("osaf.pim", view).allCollection self.failUnless(aMessage.itsItem in allCollection)
def GenerateMailMessage(view, mainView, args): """ Generate one Mail message item """ message = Mail.MailMessage(view=view) # subject if args[0] == '*': # semi-random data message.subject = random.choice(TITLES) elif not args[0] == '': message.subject = args[0] else: #default value message.subject = 'untitled' # dateSent (date + time) message.dateSent = ReturnCompleteDatetime(args[2], args[3]) # fromAdress message.fromAddress = GenerateCalendarParticipant(view, args[4]) # toAddress if args[5] == '*': for num in range(random.randint(1, 3)): message.toAddress.append(GenerateCalendarParticipant( view, args[5])) elif not args[5] == '': addressList = string.split(args[5], ';') for add in addressList: message.toAddress.append(GenerateCalendarParticipant(view, add)) else: #default value message.toAddress.append( GenerateCalendarParticipant(view, '*****@*****.**')) # outbound smtpAccount = Mail.getCurrentSMTPAccount(view)[0] mailAccount = Mail.getCurrentMailAccount(view) if args[6] == '*': outbound = random.randint(0, 1) if outbound: message.outgoingMessage(smtpAccount) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: message.incomingMessage(mailAccount) elif args[6] == 'TRUE': message.outgoingMessage(smtpAccount) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: # default value "incoming" message.incomingMessage(mailAccount) # Stamp Event if args[7] == '*': type = random.randint(0, 1) if type: message.StampKind( 'add', Calendar.CalendarEventMixin.getKind(message.itsView)) elif args[7] == 'TRUE': message.StampKind('add', Calendar.CalendarEventMixin.getKind(message.itsView)) # Stamp Task if args[8] == '*': type = random.randint(0, 1) if type: message.StampKind('add', TaskMixin.getKind(message.itsView)) elif args[8] == 'TRUE': message.StampKind('add', TaskMixin.getKind(message.itsView)) # body if args[9] == '*': message.body = message.getAttributeAspect('body', 'type').makeValue(M_TEXT) elif not args[9] == '': message.body = message.getAttributeAspect('body', 'type').makeValue(args[9]) else: # default value message.body = message.getAttributeAspect('body', 'type').makeValue(M_TEXT) #collection if args[1] == '*': # semi-random data collectionsDict.values()[random.randint(0, len(collectionsDict) - 1)].add(message) elif not args[1] == '': collectionNames = string.split(args[1], ';') for name in collectionNames: if collectionsDict.has_key(name): collectionsDict[name].add(message) else: GenerateCollection(view, mainView, [name]) collectionsDict[name].add(message) return message