Example #1
0
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
Example #2
0
    def __mailSuccess(self, result):
        """If the message was send successfully update the
           mailMessage"""

        if __debug__:
            self.parent.printCurrentView("transport.__mailSuccess")

        now = datetime.now()
        self.mailMessage.dateSent = now
        self.mailMessage.dateSentString = utils.dateTimeToRFC2882Date(now)

        self.mailMessage.deliveryExtension.sendSucceeded()

        if __debug__:
            addrs = []

            for address in result[1]:
                addrs.append(address[0])

            self.parent.log.info(constants.UPLOAD_SUCCESS % (", ".join(addrs)))