def setUp(self): super(InOutCollectionTests, self).setUp() self.inCol = schema.ns('osaf.pim', self.view).inCollection self.outCol = schema.ns('osaf.pim', self.view).outCollection self.meCol = schema.ns("osaf.pim", self.view).meEmailAddressCollection self.m1 = MailMessage(itsView=self.view) self.m2 = MailMessage(itsView=self.view) self.m3 = MailMessage(itsView=self.view) self.m4 = MailMessage(itsView=self.view) self.m5 = MailMessage(itsView=self.view) self.m6 = MailMessage(itsView=self.view) self.m7 = MailMessage(itsView=self.view) self.e1 = EmailAddress.getEmailAddress(self.view, "*****@*****.**", uw("Test User1")) self.e2 = EmailAddress.getEmailAddress(self.view, u"*****@*****.**", uw("Test User2")) self.e3 = EmailAddress.getEmailAddress(self.view, u"*****@*****.**", uw("Test User3")) # (Differs from e3 only by case of the emailAddress) self.e4 = EmailAddress.getEmailAddress(self.view, self.e3.emailAddress.upper(), self.e3.fullName) self.imapAcct = IMAPAccount(itsView=self.view) self.smtpAcct = SMTPAccount(itsView=self.view)
def previewQuickConvert(view, headers, body, eimml, ics): # 1.0 Case # 1. Standard mail message # a. headers (build a decoded headers dict using m.keys()) # b. body # 2. ICS # a. headers (build a decoded headers dict using m.keys()) # b. body # c. decoded ics attachment # 3. EIM # a. headers (build a decoded headers dict using m.keys()) # b. decoded eim attachment mailStamp = icsDesc = icsSummary = None if eimml: # Get the from address ie. Sender. emailAddr = headers.get("From") if not emailAddr: # A peer address is required for eimml # deserialization. If there is no peer # then ignore the eimml data. return (-1, None) name, addr = emailUtils.parseaddr(emailAddr) peer = EmailAddress.getEmailAddress(view, addr, name) matchingAddresses = [] for address in addressMatchGenerator(peer): matchingAddresses.append(address) # the matchingAddresses list will at least contain the # peer address since it is an EmailAddress Item and # there for will be in the EmailAddressCollection index. statusCode, mailStamp = parseEIMML(view, peer, matchingAddresses, eimml) if statusCode != 1: # There was either an error during # processing of the eimml or the # eimml was older than the current # Item's state so it was ignored. return (statusCode, None) elif ics: result = parseICS(view, ics) if result is not None: # If the result is None then there # was an error that prevented converting # the ics text to a Chandler Item # in which case the ics is ignored and # the rest of the message parsed. mailStamp, icsDesc, icsSummary = result if not mailStamp: mailStamp = MailMessage(itsView=view) mailStamp.fromEIMML = False if getattr(mailStamp, "messageId", None): # The presence a messageId indicated that # this message has already been sent or # received and thus is an update. mailStamp.isUpdated = True # Setting these values here reduces Observer # processing time when calculating if the # message should appear in the In Collection mailStamp.viaMailService = True # Look at the from address if it matches a me address # and the ignore me attribute enabled then set toMe to # false otherwise set to True mailStamp.toMe = True if not mailStamp.fromEIMML: mailStamp.body = body if icsSummary or icsDesc: # If ics summary or ics description exist then # add them to the message body mailStamp.body += buildICSInfo(mailStamp, icsSummary, icsDesc) __parseHeaders(view, headers, mailStamp, False, False) return (1, mailStamp)
def messageObjectToKind(view, messageObject, messageText=None): """ This method converts a email message string to a Chandler C{MailMessage} object @param messageObject: A C{email.Message} object representation of a mail message @type messageObject: C{email.Message} @return: C{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 RFC2822 message" assert messageText is None or isinstance(messageText, str), \ "messageText can either be a string or None" mailStamp = None icsSummary = None icsDesc = None chandlerAttachments = getChandlerAttachments(messageObject) if chandlerAttachments["eimml"]: eimml = chandlerAttachments["eimml"][0] peer = getPeer(view, messageObject) if peer is None: # A peer address is required for eimml # deserialization. If there is no peer # then ignore the eimml data and return # an error flag. return (-1, None) matchingAddresses = [] for address in addressMatchGenerator(peer): matchingAddresses.append(address) # the matchingAddresses list will at least contain the # peer address since it is an EmailAddress Item and # there for will be in the EmailAddressCollection index. statusCode, mailStamp = parseEIMML(view, peer, matchingAddresses, eimml) if statusCode != 1: # There was either an error during # processing of the eimml or the # eimml was older than the current # Item's state so it was ignored. return (statusCode, None) elif chandlerAttachments["ics"]: ics = chandlerAttachments["ics"][0] result = parseICS(view, ics, messageObject) if result is not None: # If the result is None then there # was an error that prevented converting # the ics text to a Chandler Item # in which case the ics is ignored and # the rest of the message parsed. mailStamp, icsDesc, icsSummary = result if not mailStamp: mailStamp = MailMessage(itsView=view) mailStamp.fromEIMML = False if not IGNORE_ATTACHMENTS: # Save the original message text in a text blob if messageText is None: messageText = messageObject.as_string() mailStamp.rfc2822Message = dataToBinary(mailStamp, "rfc2822Message", messageText, 'message/rfc822', 'bz2', False) if getattr(mailStamp, "messageId", None): # The presence a messageId indicated that # this message has already been sent or # received and thus has been updated. mailStamp.isUpdated = True #if verbose(): # if messageObject.has_key("Message-ID"): # messageId = messageObject["Message-ID"] # else: # messageId = "<Unknown Message>" # # buf = ["Message: %s\n-------------------------------" % messageId] if not mailStamp.fromEIMML: # Do not parse the message to build the # item.body since that data is in the eimml. if IGNORE_ATTACHMENTS: counter = None else: counter = Counter() bodyBuffer = {'plain': [], 'html': []} buf = None # The body of the message will be contained in the eimml so # do not try and parse the mail message body. __parsePart(view, messageObject, mailStamp, bodyBuffer, counter, buf) mailStamp.body = buildBody(bodyBuffer) __parseHeaders(view, messageObject, mailStamp, True, True) if icsSummary or icsDesc: # If ics summary or ics description exist then # add them to the message body mailStamp.body += buildICSInfo(mailStamp, icsSummary, icsDesc) #if verbose(): # trace("\n\n%s\n\n" % '\n'.join(buf)) return (1, mailStamp)