コード例 #1
0
ファイル: test_policies.py プロジェクト: toxinu/munch-core
 def mk_envelope(self, data, sender=None, recipients=None):
     env = Envelope(sender=sender)
     env.parse(data)
     if not recipients:
         recipients = ['root@localhost']
     env.recipients = recipients
     return env
コード例 #2
0
 def test_valid_prefix(self):
     recipient = '*****@*****.**'
     dsn = DSN_REPORT.replace('||TO||', recipient)
     dsn = dsn.replace('||RETURNPATH||', 'foo@bar')
     message = email.message_from_string(dsn)
     envelope = Envelope()
     envelope.parse_msg(message)
     envelope.recipients = [recipient]
     BackMuncherQueuePolicy().apply(envelope)
コード例 #3
0
 def test_invalide_returnpath(self):
     recipient = '*****@*****.**'
     unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
     unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
     message = email.message_from_string(unsubscribe)
     envelope = Envelope()
     envelope.parse_msg(message)
     envelope.recipients = [recipient]
     handler = UnsubscribeHandler(envelope, message)
     self.assertIsNone(handler.apply())
コード例 #4
0
 def test_invalide_returnpath(self):
     recipient = '*****@*****.**'
     arf = ARF_REPORT.replace('||TO||', '*****@*****.**')
     arf = arf.replace('||RETURNPATH||', recipient)
     message = email.message_from_string(arf)
     envelope = Envelope()
     envelope.parse_msg(message)
     envelope.recipients = [recipient]
     handler = ARFHandler(envelope, message)
     self.assertIsNone(handler.apply())
コード例 #5
0
 def test_invalide_recipient(self):
     recipient = '*****@*****.**'
     dsn = DSN_REPORT.replace('||TO||', recipient)
     dsn = dsn.replace('||RETURNPATH||', 'foo@bar')
     message = email.message_from_string(dsn)
     envelope = Envelope()
     envelope.parse_msg(message)
     envelope.recipients = [recipient]
     handler = DSNHandler(envelope, message)
     self.assertIsNone(handler.apply())
コード例 #6
0
 def test_invalid_return_path(self):
     recipient = 'foo@bar'
     dsn = DSN_REPORT.replace('||TO||', recipient)
     dsn = dsn.replace('||RETURNPATH||', recipient)
     message = email.message_from_string(dsn)
     envelope = Envelope()
     envelope.parse_msg(message)
     envelope.recipients = [recipient]
     with self.assertRaises(QueueError) as exc:
         BackMuncherQueuePolicy().apply(envelope)
     self.assertEqual(str(exc.exception), 'Domain not valid')
コード例 #7
0
 def test_valid_recipient(self):
     recipient = '*****@*****.**'
     dsn = DSN_REPORT.replace('||TO||', recipient)
     dsn = dsn.replace('||RETURNPATH||', 'foo@bar')
     message = email.message_from_string(dsn)
     envelope = Envelope()
     envelope.parse_msg(message)
     envelope.recipients = [recipient]
     with self.assertRaises(QueueError) as exc:
         BackMuncherQueuePolicy().apply(envelope)
     self.assertNotEqual(str(exc.exception), 'Missing recipient')
コード例 #8
0
    def test_unknown_identifier(self):
        recipient = 'return-{}@test.munch.example.com'.format(
            get_base_mail_identifier())
        unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
        unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(unsubscribe)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = UnsubscribeHandler(envelope, message)
        self.assertIsNone(handler.apply())

        recipient = 'return-{}@test.munch.example.com'.format(
            get_mail_identifier())
        unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
        unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(unsubscribe)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = UnsubscribeHandler(envelope, message)
        self.assertIsNone(handler.apply())
コード例 #9
0
    def test_unknown_identifier(self):
        recipient = 'return-{}@test.munch.example.com'.format(
            get_base_mail_identifier())
        arf = ARF_REPORT.replace('||TO||', '*****@*****.**')
        arf = arf.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(arf)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = ARFHandler(envelope, message)
        self.assertIsNone(handler.apply())

        recipient = 'return-{}@test.munch.example.com'.format(
            get_mail_identifier())
        arf = ARF_REPORT.replace('||TO||', '*****@*****.**')
        arf = arf.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(arf)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = ARFHandler(envelope, message)
        self.assertIsNone(handler.apply())
コード例 #10
0
    def test_unknown_identifier(self):
        recipient = 'return-{}@test.munch.example.com'.format(
            get_base_mail_identifier())
        dsn = DSN_REPORT.replace('||TO||', recipient)
        dsn = dsn.replace('||RETURNPATH||', 'foo@bar')
        message = email.message_from_string(dsn)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = DSNHandler(envelope, message)
        self.assertIsNone(handler.apply())

        recipient = 'return-{}@test.munch.example.com'.format(
            get_mail_identifier())
        dsn = DSN_REPORT.replace('||TO||', recipient)
        dsn = dsn.replace('||RETURNPATH||', 'foo@bar')
        message = email.message_from_string(dsn)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = DSNHandler(envelope, message)
        self.assertIsNone(handler.apply())
コード例 #11
0
    def test_parse(self):
        recipient = 'unsubscribe-{}@test.munch.example.com'.format(
            get_mail_identifier())
        unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
        unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(unsubscribe)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = UnsubscribeHandler(envelope, message)

        main_headers = dict(handler.message)

        self.assertEqual(main_headers['To'], recipient)
コード例 #12
0
    def test_valid_unsubscribe(self):
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)

        recipient = 'unsubscribe-{}@test.munch.example.com'.format(
            mail.identifier)
        unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
        unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(unsubscribe)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = UnsubscribeHandler(envelope, message)
        self.assertIsNotNone(handler.apply())
コード例 #13
0
    def test_valid_arf(self):
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)

        recipient = 'return-{}@test.munch.example.com'.format(
            mail.identifier)
        arf = ARF_REPORT.replace('||TO||', '*****@*****.**')
        arf = arf.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(arf)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = ARFHandler(envelope, message)
        self.assertIsNotNone(handler.apply())
コード例 #14
0
    def test_parse(self):
        recipient = 'return-{}@test.munch.example.com'.format(
            get_mail_identifier())
        arf = ARF_REPORT.replace('||TO||', recipient)
        arf = arf.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(arf)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = ARFHandler(envelope, message)

        main_headers = email.message_from_string(handler.message.as_string())
        orig_headers = handler.get_original()
        report_headers = handler.get_report()

        self.assertEqual(orig_headers['Return-Path'], recipient)
        self.assertEqual(report_headers['Feedback-Type'], 'abuse')
        self.assertEqual(main_headers['Date'], 'Thu, 8 Mar 2005 17:40:36 EDT')
コード例 #15
0
    def test_parse(self):
        recipient = 'return-{}@test.munch.example.com'.format(
            get_mail_identifier())
        dsn = DSN_REPORT.replace('||TO||', recipient)
        dsn = dsn.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(dsn)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = DSNHandler(envelope, message)

        main_headers = email.message_from_string(handler.message.as_string())
        report_headers = handler.get_report()

        self.assertEqual(main_headers['To'], recipient)

        self.assertEqual(
            report_headers['Arrival-Date'],
            'Mon,  1 Sep 2014 17:36:45 +0000 (UTC)')
        self.assertEqual(report_headers['Diagnostic-Code'], 'smtp; 250 OK')
        self.assertEqual(report_headers['Status'], '2.0.0')
        self.assertEqual(report_headers['Action'], 'relayed')