Exemplo n.º 1
0
    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
Exemplo n.º 2
0
def GenerateEmailAddresses(view, name):
    list = []
    for i in range(random.randint(1, 2)):
        email = Mail.EmailAddress(view=view)
        email.emailAddress = GenerateEmailAddress(name)
        list.append(email)
    return list
Exemplo n.º 3
0
 def updateExpectedFieldDict(self, dict):
     for field in dict.keys():
         if field == "startDate": # start date update
             tmp = string.split(dict[field],"/")
             if self.expected_field_dict.has_key("startTime"):
                 startTime = self.expected_field_dict["startTime"]
                 new = datetime(month=string.atoi(tmp[0]), day=string.atoi(tmp[1]), year=string.atoi(tmp[2]), hour=startTime.hour, minute=startTime.minute)
             else:
                 new = datetime(month=string.atoi(tmp[0]), day=string.atoi(tmp[1]), year=string.atoi(tmp[2]))
             self.expected_field_dict["startTime"] = new
         elif field == "startTime": # start time update
             tmp = string.split(dict[field],":")
             if self.expected_field_dict.has_key("startTime"):
                 startTime = self.expected_field_dict["startTime"]
                 new = datetime(month=startTime.month, day=startTime.day, year=startTime.year, hour=string.atoi(tmp[0]), minute=string.atoi(tmp[1][:2]))
             else:
                 new = datetime(hour=string.atoi(tmp[0]), minute=string.atoi(tmp[1]))
             self.expected_field_dict["startTime"] = new
         elif field == "endDate": # end date update
             tmp = string.split(dict[field],"/")
             if self.expected_field_dict.has_key("endTime"):
                 endTime = self.expected_field_dict["endTime"]
                 new = datetime(month=string.atoi(tmp[0]), day=string.atoi(tmp[1]), year=string.atoi(tmp[2]), hour=endTime.hour, minute=endTime.minute)
             else:
                 new = datetime(month=string.atoi(tmp[0]), day=string.atoi(tmp[1]), year=string.atoi(tmp[2]))
             self.expected_field_dict["endTime"] = new
         elif field == "endTime": # end time update
             tmp = string.split(dict[field],":")
             if self.expected_field_dict.has_key("endTime"):
                 endTime = self.expected_field_dict["endTime"]
                 new = datetime(month=endTime.month, day=endTime.day, year=endTime.year, hour=string.atoi(tmp[0]), minute=string.atoi(tmp[1][:2]))
             else:
                 new = datetime(hour=string.atoi(tmp[0]), minute=string.atoi(tmp[1]))
             self.expected_field_dict["endTime"] = new
         elif field == "fromAddress": # from address update
             email = Mail.EmailAddress(view=view)
             email.emailAddress = dict[field]
             self.expected_field_dict["fromAdress"] = email
         elif field == "toAddress": # from address update
             email = Mail.EmailAddress(view=view)
             email.emailAddress = dict[field]
             self.expected_field_dict["toAdress"] = email
             
         else:
             self.expected_field_dict[field] = dict[field]
Exemplo n.º 4
0
 def setUp(self):
     super(CommunicationStatusTestCase, self).setUp()
     self.address = Mail.EmailAddress(
                     itsView=self.view,
                     fullName=u"Mr. President",
                     emailAddress=u"*****@*****.**")
     #account = Mail.IMAPAccount(itsView=self.view,
     #                           replyToAddress=self.address)
     schema.ns('osaf.pim', self.view).meEmailAddressCollection.add(self.address)
     self.note = Note(itsView=self.view)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
def GenerateCalendarParticipant(view, emailAddress):
    """ Generate an email address corresponding to the parameters """
    email = Mail.EmailAddress(view=view)
    if emailAddress == '*':  # semi-random data
        domainName = random.choice(DOMAIN_LIST)
        handle = random.choice(LASTNAMES).lower()
        email.emailAddress = "%s@%s" % (handle, domainName)
    elif not emailAddress == '':
        email.emailAddress = emailAddress
    else:  # default value
        email.emailAddress = 'Me'

    return email
Exemplo n.º 7
0
    def __populateAccount(self, account):

        account.username = "******"
        account.password = "******"
        account.host = "test"

        if type(account) == Mail.AccountBase:
            account.port = 1
            account.connectionSecurity = "NONE"

        if type(account) == Mail.SMTPAccount:
            account.fullName = "test"
            account.replyToAddress = Mail.EmailAddress(view=account.itsView)
            account.replyToAddress.emailAddress = "*****@*****.**"
Exemplo n.º 8
0
    def __populateAccount(self, account):

        #XXX: i18n usernames and passwords can be non-ascii.
        # Need to investigate how best to deal with this as
        # there is no standard. It is server implementation dependent.
        account.username = uw("test")
        account.password = password.Password(itsView=account.itsView,
                                             itsParent=account)
        waitForDeferred(account.password.encryptPassword(uw("test")))
        account.host = uw("test")

        if type(account) == Mail.AccountBase:
            account.port = 1
            account.connectionSecurity = "NONE"

        if type(account) == Mail.SMTPAccount:
            account.fullName = uw("test")
            account.replyToAddress = Mail.EmailAddress(itsView=account.itsView)
            account.replyToAddress.emailAddress = "*****@*****.**"
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
def GenerateCalendarParticipant(view):
    email = Mail.EmailAddress(view=view)
    domainName = random.choice(DOMAIN_LIST)
    handle = random.choice(LASTNAMES).lower()
    email.emailAddress = "%s@%s" % (handle, domainName)
    return email
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
 def setUp(self):
     super(MailWhoTestCase, self).setUp()
     self.loadParcel("osaf.pim.mail")
     self.address = Mail.EmailAddress(itsView=self.view,
                                      fullName=u"Grant Baillie",
                                      emailAddress=u"*****@*****.**")