Example #1
0
    def test_issue141_one_last_digest(self):
        # Currently DigestMode.summary_digests are equivalent to mime_digests.
        self._mlist.send_welcome_message = False
        bart = subscribe(self._mlist, 'Bart')
        self._mlist.send_one_last_digest_to(
            bart.address, DeliveryMode.summary_digests)
        make_digest_messages(self._mlist)
        # There should be one message in the outgoing queue, destined for
        # Bart, formatted as a MIME digest.
        items = get_queue_messages('virgin')
        self.assertEqual(len(items), 1)
        # Bart is the only recipient.
        self.assertEqual(items[0].msgdata['recipients'],
                         set(['*****@*****.**']))
        # The message is a MIME digest, with the structure we expect.
        fp = StringIO()
        structure(items[0].msg, fp)
        self.assertMultiLineEqual(fp.getvalue(), """\
multipart/mixed
    text/plain
    text/plain
    message/rfc822
        text/plain
    text/plain
""")
Example #2
0
 def test_digest_messages(self):
     # In LP: #1130697, the digest runner creates MIME digests using the
     # stdlib MIMEMutlipart class, however this class does not have the
     # extended attributes we require (e.g. .sender).  The fix is to use a
     # subclass of MIMEMultipart and our own Message subclass; this adds
     # back the required attributes.  (LP: #1130696)
     #
     # Start by creating the raw ingredients for the digests.  This also
     # runs the digest runner, thus producing the digest messages into the
     # virgin queue.
     make_digest_messages(self._mlist)
     # Run the virgin queue processor, which runs the cook-headers and
     # to-outgoing handlers.  This should produce no error.
     error_log = LogFileMark('mailman.error')
     runner = make_testable_runner(VirginRunner, 'virgin')
     runner.run()
     error_text = error_log.read()
     self.assertEqual(len(error_text), 0, error_text)
     self.assertEqual(len(get_queue_messages('shunt')), 0)
     messages = get_queue_messages('out')
     self.assertEqual(len(messages), 2)
     # Which one is the MIME digest?
     mime_digest = None
     for bag in messages:
         if bag.msg.get_content_type() == 'multipart/mixed':
             assert mime_digest is None, 'Found two MIME digests'
             mime_digest = bag.msg
     # The cook-headers handler ran.
     self.assertIn('x-mailman-version', mime_digest)
     self.assertEqual(mime_digest['precedence'], 'list')
     # The list's -request address is the original sender.
     self.assertEqual(bag.msgdata['original_sender'],
                      '*****@*****.**')
Example #3
0
 def test_digest_messages(self):
     # In LP: #1130697, the digest runner creates MIME digests using the
     # stdlib MIMEMutlipart class, however this class does not have the
     # extended attributes we require (e.g. .sender).  The fix is to use a
     # subclass of MIMEMultipart and our own Message subclass; this adds
     # back the required attributes.  (LP: #1130696)
     #
     # Start by creating the raw ingredients for the digests.  This also
     # runs the digest runner, thus producing the digest messages into the
     # virgin queue.
     make_digest_messages(self._mlist)
     # Run the virgin queue processor, which runs the cook-headers and
     # to-outgoing handlers.  This should produce no error.
     error_log = LogFileMark('mailman.error')
     runner = make_testable_runner(VirginRunner, 'virgin')
     runner.run()
     error_text = error_log.read()
     self.assertEqual(len(error_text), 0, error_text)
     self.assertEqual(len(get_queue_messages('shunt')), 0)
     messages = get_queue_messages('out')
     self.assertEqual(len(messages), 2)
     # Which one is the MIME digest?
     mime_digest = None
     for bag in messages:
         if bag.msg.get_content_type() == 'multipart/mixed':
             assert mime_digest is None, 'Found two MIME digests'
             mime_digest = bag.msg
     # The cook-headers handler ran.
     self.assertIn('x-mailman-version', mime_digest)
     self.assertEqual(mime_digest['precedence'], 'list')
     # The list's -request address is the original sender.
     self.assertEqual(bag.msgdata['original_sender'],
                      '*****@*****.**')
Example #4
0
    def test_issue141_one_last_digest(self):
        # Currently DigestMode.summary_digests are equivalent to mime_digests.
        # Also tests issue 234.
        self._mlist.send_welcome_message = False
        bart = subscribe(self._mlist, 'Bart')
        self._mlist.send_one_last_digest_to(bart.address,
                                            DeliveryMode.summary_digests)
        make_digest_messages(self._mlist)
        # There should be one message in the outgoing queue, destined for
        # Bart, formatted as a MIME digest.
        items = get_queue_messages('virgin', expected_count=1)
        # Bart is the only recipient.
        self.assertEqual(items[0].msgdata['recipients'],
                         set(['*****@*****.**']))
        # The message is a MIME digest, with the structure we expect.
        fp = StringIO()
        structure(items[0].msg, fp)
        self.assertMultiLineEqual(
            fp.getvalue(), """\
multipart/mixed
    text/plain
    text/plain
    multipart/digest
        message/rfc822
            text/plain
    text/plain
""")
Example #5
0
 def test_simple_message(self):
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     make_digest_messages(self._mlist)
     self._check_virgin_queue()
Example #6
0
 def test_simple_message(self):
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     make_digest_messages(self._mlist)
     self._check_virgin_queue()
Example #7
0
 def test_process_digest(self):
     # MIME digests messages are multiparts.
     make_digest_messages(self._mlist)
     messages = [bag.msg for bag in get_queue_messages('virgin')]
     self.assertEqual(len(messages), 2)
     for msg in messages:
         try:
             cook_headers.process(self._mlist, msg, {})
         except AttributeError as error:
             # LP: #1130696 would raise an AttributeError on .sender
             self.fail(error)
Example #8
0
 def test_simple_message(self):
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     make_digest_messages(self._mlist)
     self._check_virgin_queue()
     # The digest mbox and all intermediary mboxes must have been removed
     # (GL #259).
     self.assertEqual(os.listdir(self._mlist.data_path), [])
Example #9
0
 def test_process_digest(self):
     # MIME digests messages are multiparts.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     make_digest_messages(self._mlist)
     items = get_queue_messages('virgin', expected_count=2)
     for item in items:
         try:
             cook_headers.process(self._mlist, item.msg, {})
         except AttributeError as error:
             # LP: #1130696 would raise an AttributeError on .sender
             self.fail(error)
Example #10
0
 def test_non_ascii_message(self):
     msg = Message()
     msg['From'] = '*****@*****.**'
     msg['To'] = '*****@*****.**'
     msg['Content-Type'] = 'multipart/mixed'
     msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
                         'plain', 'utf-8'))
     mbox = digest_mbox(self._mlist)
     mbox.add(msg.as_string())
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     make_digest_messages(self._mlist, msg)
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     self._check_virgin_queue()
Example #11
0
 def test_process_digest(self):
     # MIME digests messages are multiparts.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     make_digest_messages(self._mlist)
     messages = [bag.msg for bag in get_queue_messages('virgin')]
     self.assertEqual(len(messages), 2)
     for msg in messages:
         try:
             cook_headers.process(self._mlist, msg, {})
         except AttributeError as error:
             # LP: #1130696 would raise an AttributeError on .sender
             self.fail(error)
Example #12
0
 def test_utf7_message_with_inline_ascii_sig(self):
     # The test message is bigger than 1K.  Set the threshold bigger to
     # avoid double processing in make_digest_messages.
     self._mlist.digest_size_threshold = 5
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     with open_binary('mailman.runners.tests.data',
                      'ascii_in_utf7.eml') as fp:
         msg = message_from_binary_file(fp, Message)
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     make_digest_messages(self._mlist, msg)
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     self._check_virgin_queue()
Example #13
0
 def test_non_ascii_message(self):
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     msg = Message()
     msg['From'] = '*****@*****.**'
     msg['To'] = '*****@*****.**'
     msg['Content-Type'] = 'multipart/mixed'
     msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
                         'plain', 'utf-8'))
     mbox = digest_mbox(self._mlist)
     mbox.add(msg.as_string())
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     make_digest_messages(self._mlist, msg)
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     self._check_virgin_queue()
Example #14
0
 def test_non_ascii_message(self):
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     msg = Message()
     msg['From'] = '*****@*****.**'
     msg['To'] = '*****@*****.**'
     msg['Content-Type'] = 'multipart/mixed'
     msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
                         'plain', 'utf-8'))
     mbox = digest_mbox(self._mlist)
     mbox.add(msg.as_string())
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     make_digest_messages(self._mlist, msg)
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     self._check_virgin_queue()
Example #15
0
 def test_digest_messages(self):
     # In LP: #1130697, the digest runner creates MIME digests using the
     # stdlib MIMEMutlipart class, however this class does not have the
     # extended attributes we require (e.g. .sender).  The fix is to use a
     # subclass of MIMEMultipart and our own Message subclass; this adds
     # back the required attributes.  (LP: #1130696)
     self._mlist.send_welcome_message = False
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     # Start by creating the raw ingredients for the digests.  This also
     # runs the digest runner, thus producing the digest messages into the
     # virgin queue.
     make_digest_messages(self._mlist)
     # Run the virgin queue processor, which runs the cook-headers and
     # to-outgoing handlers.  This should produce no error.
     error_log = LogFileMark('mailman.error')
     runner = make_testable_runner(VirginRunner, 'virgin')
     runner.run()
     error_text = error_log.read()
     self.assertEqual(len(error_text), 0, error_text)
     get_queue_messages('shunt', expected_count=0)
     items = get_queue_messages('out', expected_count=2)
     # Which one is the MIME digest?
     mime_digest = None
     for item in items:
         if item.msg.get_content_type() == 'multipart/mixed':
             assert mime_digest is None, 'Found two MIME digests'
             mime_digest = item.msg
     # The cook-headers handler ran.
     self.assertIn('x-mailman-version', mime_digest)
     self.assertEqual(mime_digest['precedence'], 'list')
     # The list's -request address is the original sender.
     self.assertEqual(item.msgdata['original_sender'],
                      '*****@*****.**')
Example #16
0
 def test_digest_messages(self):
     # In LP: #1130697, the digest runner creates MIME digests using the
     # stdlib MIMEMutlipart class, however this class does not have the
     # extended attributes we require (e.g. .sender).  The fix is to use a
     # subclass of MIMEMultipart and our own Message subclass; this adds
     # back the required attributes.  (LP: #1130696)
     self._mlist.send_welcome_message = False
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     # Start by creating the raw ingredients for the digests.  This also
     # runs the digest runner, thus producing the digest messages into the
     # virgin queue.
     make_digest_messages(self._mlist)
     # Run the virgin queue processor, which runs the cook-headers and
     # to-outgoing handlers.  This should produce no error.
     error_log = LogFileMark('mailman.error')
     runner = make_testable_runner(VirginRunner, 'virgin')
     runner.run()
     error_text = error_log.read()
     self.assertEqual(len(error_text), 0, error_text)
     get_queue_messages('shunt', expected_count=0)
     items = get_queue_messages('out', expected_count=2)
     # Which one is the MIME digest?
     mime_digest = None
     for item in items:
         if item.msg.get_content_type() == 'multipart/mixed':
             assert mime_digest is None, 'Found two MIME digests'
             mime_digest = item.msg
     # The cook-headers handler ran.
     self.assertIn('x-mailman-version', mime_digest)
     self.assertEqual(mime_digest['precedence'], 'list')
     # The list's -request address is the original sender.
     self.assertEqual(item.msgdata['original_sender'],
                      '*****@*****.**')
Example #17
0
 def test_simple_message(self):
     make_digest_messages(self._mlist)
     self._check_virgin_queue()
Example #18
0
    def test_non_ascii_in_ascii_part(self):
        # Subscribe some users receiving digests.
        anne = subscribe(self._mlist, 'Anne')
        anne.preferences.delivery_mode = DeliveryMode.mime_digests
        bart = subscribe(self._mlist, 'Bart')
        bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
        msg = message_from_bytes(
            b"""\
From: [email protected]
To: [email protected]
Subject: Non-ascii in ascii message
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="abcxyz"

--abcxyz
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 8bit

Don\xe2\x80\x99t try this at home.
--abcxyz--
""", Message)
        # Use any error logs as the error message if the test fails.
        error_log = LogFileMark('mailman.error')
        make_digest_messages(self._mlist, msg)
        # The runner will send the file to the shunt queue on exception.
        self.assertEqual(len(self._shuntq.files), 0, error_log.read())
        items = self._check_virgin_queue()
        self.assertEqual(
            self._get_plain_body(items), b"""\
Send Test mailing list submissions to
\[email protected]

To subscribe or unsubscribe via email, send a message with subject or
body 'help' to
\[email protected]

You can reach the person managing the list at
\[email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Test digest..."

Today\'s Topics:

   1. Non-ascii in ascii message ([email protected])


----------------------------------------------------------------------

Message: 1
From: [email protected]
Subject: Non-ascii in ascii message
To: [email protected]
Content-Type: multipart/mixed; boundary="abcxyz"

Don\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdt try this at home.

------------------------------

Subject: Digest Footer

_______________________________________________
Test mailing list -- [email protected]
To unsubscribe send an email to [email protected]


------------------------------

End of Test Digest, Vol 1, Issue 1
**********************************
""")