示例#1
0
    def test_handle_message(self):

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])
示例#2
0
    def test_handle_message(self):

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])
    def test_handle_message_with_extended_from(self):

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification["to"])
        self.assertEquals(TO, notification["from"])
示例#4
0
    def test_handle_message_with_attachments(self):

        handle_message(self.multipartmsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        issue = self.sla.issue_set.all()[0]

        self.assertEquals(1, issue.attachment_set.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])
        self.assertEquals(TO, notification['from'])
示例#5
0
    def test_handle_message_with_attachments(self):

        handle_message(self.multipartmsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        issue = self.sla.issue_set.all()[0]

        self.assertEquals(1, issue.attachment_set.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])    
        self.assertEquals(TO, notification['from'])
示例#6
0
    def test_handle_message_sla_with_default_service(self):

        service = Service.objects.create(sla=self.sla, priority="laag")

        self.sla.default_service = service
        self.sla.save()

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        self.assertEquals(service, self.sla.issue_set.all()[0].service)

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])
        self.assertEquals(TO, notification['from'])
示例#7
0
    def test_handle_message_sla_with_default_service(self):

        service = Service.objects.create(sla=self.sla, priority="laag")

        self.sla.default_service = service
        self.sla.save()

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        self.assertEquals(service, self.sla.issue_set.all()[0].service)

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])    
        self.assertEquals(TO, notification['from'])
示例#8
0
    def test_handle_winmail_dat(self):

        msg = MIMEMultipart('alternative')

        msg['Subject'] = self.simplemsg['Subject'] = "Issue"
        msg['From'] = self.simplemsg['From'] = FROM
        msg['To'] = self.simplemsg['To'] = TO

        winmaildat = os.path.join(os.path.dirname(__file__), "winmail.dat")

        msg.attach(MIMEApplication(file(winmaildat).read(), "ms-tnef"))

        handle_message(msg)

        issue = self.sla.issue_set.all()[0]

        self.assertEquals(1, issue.attachment_set.all().count())

        self.assertTrue(issue.attachment_set.all()[0].is_image)
示例#9
0
    def test_handle_bouncing_issue(self):

        msg = MIMEText("It's broken", 'plain')

        msg['From'] = "*****@*****.**"
        msg['To'] = "*****@*****.**"
        msg['Subject'] = "help!"

        import mrwolfe.utils as utils
        utils.settings.ALLOW_NON_CONTACTS = False

        handle_message(msg)

        self.assertEquals(0, Issue.objects.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals("Invalid contact for support",
                          notification['subject'])
示例#10
0
    def test_handle_winmail_dat(self):

        msg = MIMEMultipart('alternative')

        msg['Subject'] = self.simplemsg['Subject'] = "Issue"
        msg['From'] = self.simplemsg['From'] = FROM
        msg['To'] = self.simplemsg['To'] = TO

        winmaildat = os.path.join(os.path.dirname(__file__), "winmail.dat")

        msg.attach(MIMEApplication(file(winmaildat).read(), "ms-tnef"))

        handle_message(msg)

        issue = self.sla.issue_set.all()[0]

        self.assertEquals(1, issue.attachment_set.all().count())

        self.assertTrue(issue.attachment_set.all()[0].is_image)
示例#11
0
    def test_handle_bouncing_issue(self):

        msg = MIMEText("It's broken", 'plain')

        msg['From'] = "*****@*****.**"
        msg['To'] = "*****@*****.**"
        msg['Subject'] = "help!"

        import mrwolfe.utils as utils
        utils.settings.ALLOW_NON_CONTACTS = False

        handle_message(msg)

        self.assertEquals(0, Issue.objects.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals("Invalid contact for support", 
                          notification['subject'])
示例#12
0
    def test_handle_message_with_existing_issue(self):

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        issue = self.sla.issue_set.all()[0]

        self.simplemsg.replace_header('subject', "Re: %s" % issue.issue_id)

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        self.assertEquals(1, issue.comments.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])
        self.assertEquals(TO, notification['from'])
示例#13
0
    def test_handle_message_with_existing_issue(self):

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        issue = self.sla.issue_set.all()[0]

        self.simplemsg.replace_header('subject', "Re: %s" % issue.issue_id)

        handle_message(self.simplemsg)

        self.assertEquals(1, self.sla.issue_set.all().count())

        self.assertEquals(1, issue.comments.all().count())

        notification = NotificationsBin.receive()

        self.assertEquals([FROM], notification['to'])    
        self.assertEquals(TO, notification['from'])
示例#14
0
    def handle_queue(self, mailqueue):

        LOGGER.info("Handling queue %s" % mailqueue)

        if mailqueue.protocol == 0:
            service = POPService(mailqueue.host, int(mailqueue.port or 995))
        else:
            service = IMAPService(mailqueue.host, int(mailqueue.port or 143))

        LOGGER.debug("Protocol used: %s" %
                     (mailqueue.protocol and "IMAP" or "POP"))

        service.auth(mailqueue.usr, mailqueue.pwd)

        cnt = 0
        unhandled = []

        for msg_id, message in service.list():

            try:
                handled = handle_message(message)

                if not handled:
                    LOGGER.warning("Unhandled message!")
                    unhandled.append(msg_id)
                else:
                    cnt += 1
            except:
                LOGGER.exception("Exception in handling message!")
                unhandled.append(msg_id)

        service.mark_unread(unhandled)

        LOGGER.info("Handled %i messages" % cnt)

        service.quit()