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 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)
示例#3
0
def addMaiStamp(item):
    ms = MailStamp(item)
    ms.add()

    ms.subject = uw("Test Mail")
    ms.body = uw("Test ") * 60

    toAddr = EmailAddress.getEmailAddress(view, "*****@*****.**")
    ms.toAddress.append(toAddr)

    ms.fromAddress = EmailAddress.getEmailAddress(view, "*****@*****.**")
    ms.ccAddress.append(ms.fromAddress)

    org = EmailAddress.getEmailAddress(view, "The Management")
    ms.originators.append(org)

    return ms
示例#4
0
def addMaiStamp(item):
    ms = MailStamp(item)
    ms.add()

    ms.subject = uw("Test Mail")
    ms.body = uw("Test ") * 60

    toAddr = EmailAddress.getEmailAddress(view, "*****@*****.**")
    ms.toAddress.append(toAddr)

    ms.fromAddress = EmailAddress.getEmailAddress(view,
                                                  "*****@*****.**")
    ms.ccAddress.append(ms.fromAddress)

    org = EmailAddress.getEmailAddress(view, "The Management")
    ms.originators.append(org)

    return ms
示例#5
0
def getPeer(view, messageObject):
    # Get the from address ie. Sender.
    emailAddr = messageObject.get("From")

    if not emailAddr:
        return None

    name, addr = emailUtils.parseaddr(emailAddr)

    return EmailAddress.getEmailAddress(view, getUnicodeValue(addr), decodeHeader(name))
示例#6
0
def __assignToKind(view, kindVar, messageObject, key, hType, attr, decode,
                   makeUnicode):
    header = messageObject.get(key)

    if header is None:
        return None

    if decode:
        header = decodeHeader(header)

    elif makeUnicode:
        header = getUnicodeValue(header)

    if hType == "String":
        setattr(kindVar, attr, header)

    elif hType == "EmailAddress":
        name, addr = emailUtils.parseaddr(messageObject.get(key))

        if decode:
            name = decodeHeader(name)

        if makeUnicode:
            addr = getUnicodeValue(addr)

        ea = EmailAddress.getEmailAddress(view, addr, name)

        if ea is not None:
            setattr(kindVar, attr, ea)

    elif hType == "EmailAddressList":
        for name, addr in emailUtils.getaddresses(
                messageObject.get_all(key, [])):
            if decode:
                name = decodeHeader(name)

            if makeUnicode:
                addr = getUnicodeValue(addr)

            ea = EmailAddress.getEmailAddress(view, addr, name)

            if ea is not None:
                kindVar.append(ea)
示例#7
0
def getPeer(view, messageObject):
    # Get the from address ie. Sender.
    emailAddr = messageObject.get("From")

    if not emailAddr:
        return None

    name, addr = emailUtils.parseaddr(emailAddr)

    return EmailAddress.getEmailAddress(view, getUnicodeValue(addr),
                                        decodeHeader(name))
示例#8
0
def __assignToKind(view, kindVar, messageObject, key, hType, attr, decode, makeUnicode):
    header = messageObject.get(key)

    if header is None:
        return None

    if decode:
        header = decodeHeader(header)

    elif makeUnicode:
        header = getUnicodeValue(header)

    if hType == "String":
        setattr(kindVar, attr, header)

    elif hType == "EmailAddress":
        name, addr = emailUtils.parseaddr(messageObject.get(key))

        if decode:
            name = decodeHeader(name)

        if makeUnicode:
            addr = getUnicodeValue(addr)

        ea = EmailAddress.getEmailAddress(view, addr, name)

        if ea is not None:
            setattr(kindVar, attr, ea)

    elif hType == "EmailAddressList":
        for name, addr in emailUtils.getaddresses(messageObject.get_all(key, [])):
            if decode:
                name = decodeHeader(name)

            if makeUnicode:
                addr = getUnicodeValue(addr)

            ea = EmailAddress.getEmailAddress(view, addr, name)

            if ea is not None:
                kindVar.append(ea)
示例#9
0
def parseICS(view, ics, messageObject=None):

    from osaf.sharing import (deserialize, SharingTranslator, ICSSerializer,
                              remindersFilter)


    icsDesc = icsSummary = None

    peer = None
    if messageObject is not None:
        peer = getPeer(view, messageObject)
    if peer is None:
        # we don't really need a valid peer to import icalendar, make one up
        peer = EmailAddress.getEmailAddress(view, "*****@*****.**")

    try:
        items = deserialize(view, peer, ics, SharingTranslator,
                            ICSSerializer, filter=remindersFilter)
    except Exception, e:
        logging.exception(e)
        return None
示例#10
0
def parseICS(view, ics, messageObject=None):

    from osaf.sharing import (deserialize, SharingTranslator, ICSSerializer,
                              remindersFilter)

    icsDesc = icsSummary = None

    peer = None
    if messageObject is not None:
        peer = getPeer(view, messageObject)
    if peer is None:
        # we don't really need a valid peer to import icalendar, make one up
        peer = EmailAddress.getEmailAddress(view, "*****@*****.**")

    try:
        items = deserialize(view,
                            peer,
                            ics,
                            SharingTranslator,
                            ICSSerializer,
                            filter=remindersFilter)
    except Exception, e:
        logging.exception(e)
        return None
示例#11
0
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)
示例#12
0
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)
示例#13
0
def getAddress(view, match):
    """Get an EmailAddress from a many_contacts_re match."""
    return EmailAddress.getEmailAddress(view, match.group('contact'))