def populateHeader(messageObject, param, var, type='String'): if type == 'String': if utils.hasValue(var): #XXX: Willl need to detect i18n charset and encoded if needed messageObject[param] = var elif(type == 'EmailAddress'): if var is not None and utils.hasValue(var.emailAddress): #XXX: Willl need to detect i18n charset and encoded if needed messageObject[param] = Mail.EmailAddress.format(var)
def kindToMessageObject(mailMessage): """ 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{Message.Message} """ assert isinstance(mailMessage, Mail.MailMessageMixin), \ "mailMessage must be an instance of Kind Mail.MailMessage" messageObject = Message.Message() """Create a messageId if none exists""" if not utils.hasValue(mailMessage.messageId): mailMessage.messageId = utils.createMessageID() """Create a dateSent if none exists""" if not utils.hasValue(mailMessage.dateSentString): mailMessage.dateSent = datetime.now() mailMessage.dateSentString = utils.dateTimeToRFC2882Date(mailMessage.dateSent) populateHeader(messageObject, 'Message-ID', mailMessage.messageId) populateHeader(messageObject, 'Date', mailMessage.dateSentString) populateEmailAddresses(mailMessage, messageObject) populateStaticHeaders(messageObject) populateChandlerHeaders(mailMessage, messageObject) populateHeaders(mailMessage, messageObject) populateHeader(messageObject, 'Subject', mailMessage.subject) try: payload = mailMessage.body #XXX: Temp hack this should be fixed in GUI level # investigate with Andi and Bryan if payload.encoding is None: payload.encoding = constants.DEFAULT_CHARSET payloadUStr = utils.textToUnicode(payload) except AttributeError: payloadUStr = u"" messageObject.set_payload(payloadUStr) return messageObject
def isChandlerHeader(header): """Returns true if the header is Chandler defined header""" assert utils.hasValue(header), "You must pass a String" if header.startswith(constants.CHANDLER_HEADER_PREFIX): return True return False
def populateEmailAddressList(emailAddressList, messageObject, key): addrs = [] for address in emailAddressList: if utils.hasValue(address.emailAddress): addrs.append(Mail.EmailAddress.format(address)) if len(addrs) > 0: messageObject[key] = ", ".join(addrs)
def __getEmailAddress(view, name, addr): keyArgs = {} if utils.hasValue(name): keyArgs['fullName'] = name """ Use any existing EmailAddress, but don't update them because that will cause the item to go stale in the UI thread.""" #XXX: This method needs much better performance return Mail.EmailAddress.getEmailAddress(view, addr, **keyArgs)
def createChandlerHeader(postfix): """Creates a chandler header with postfix provided""" assert utils.hasValue(postfix), "You must pass a String" return constants.CHANDLER_HEADER_PREFIX + postfix