Exemple #1
0
    def test_concurrent_delivery_w_old_file(self):
        # Attempt to send message
        self.filename = os.path.join(self.dir, 'message')

        temp = open(self.filename, "w+b")
        temp.write(
            b('X-Actually-From: [email protected]\n'
              'X-Actually-To: [email protected], [email protected]\n'
              'Header: value\n\nBody\n'))
        temp.close()

        self.qp.maildir.files.append(self.filename)

        # Trick processor into thinking message is being delivered by
        # another process.
        head, tail = os.path.split(self.filename)
        tmp_filename = os.path.join(head, '.sending-' + tail)
        queue._os_link(self.filename, tmp_filename)
        os.utime(tmp_filename, (1, 1))  #mtime/utime 1970-01-01T00:00:01Z
        self.qp.send_messages()

        sent_message = self.qp.mailer.sent_messages[0]
        self.assertEqual(sent_message[0], '*****@*****.**')
        self.assertEqual(sent_message[1],
                         ('*****@*****.**', '*****@*****.**'))
        self.assertEqual(sent_message[2].as_string(),
                         'Header: value\n\nBody\n')
        self.assertFalse(os.path.exists(self.filename), 'File still exists')
        self.assertEqual(
            self.qp.log.infos,
            [('Mail from %s to %s sent.',
              ('*****@*****.**', '[email protected], [email protected]'), {})])
        self.assertFalse(os.path.exists(tmp_filename))
    def test_concurrent_delivery_w_old_file(self):
        # Attempt to send message
        self.filename = os.path.join(self.dir, 'message')

        temp = open(self.filename, "w+b")
        temp.write(b('X-Actually-From: [email protected]\n'
                     'X-Actually-To: [email protected], [email protected]\n'
                     'Header: value\n\nBody\n'))
        temp.close()

        self.qp.maildir.files.append(self.filename)

        # Trick processor into thinking message is being delivered by
        # another process.
        head, tail = os.path.split(self.filename)
        tmp_filename = os.path.join(head, '.sending-' + tail)
        queue._os_link(self.filename, tmp_filename)
        os.utime(tmp_filename, (1,1)) #mtime/utime 1970-01-01T00:00:01Z
        self.qp.send_messages()

        sent_message = self.qp.mailer.sent_messages[0]
        self.assertEqual(sent_message[0], '*****@*****.**')
        self.assertEqual(sent_message[1], 
                          ('*****@*****.**', '*****@*****.**'))
        self.assertEqual(sent_message[2].as_string(), 
                          'Header: value\n\nBody\n')
        self.assertFalse(os.path.exists(self.filename),
                         'File still exists')
        self.assertEqual(self.qp.log.infos,
                          [('Mail from %s to %s sent.',
                            ('*****@*****.**',
                             '[email protected], [email protected]'),
                            {})])
        self.assertFalse(os.path.exists(tmp_filename))
Exemple #3
0
    def test_concurrent_delivery(self):
        # Attempt to send message
        self.filename = os.path.join(self.dir, 'message')

        temp = open(self.filename, "w+b")
        temp.write(
            b('X-Actually-From: [email protected]\n') +
            b('X-Actually-To: [email protected], [email protected]\n') +
            b('Header: value\n\nBody\n'))
        temp.close()

        self.qp.maildir.files.append(self.filename)

        # Trick processor into thinking message is being delivered by
        # another process.
        head, tail = os.path.split(self.filename)
        tmp_filename = os.path.join(head, '.sending-' + tail)
        queue._os_link(self.filename, tmp_filename)
        try:
            self.qp.send_messages()

            self.assertEqual(self.qp.mailer.sent_messages, [])
            self.assertTrue(os.path.exists(self.filename),
                            'File does not exist')
            self.assertEqual(self.qp.log.infos, [])
        finally:
            os.unlink(tmp_filename)
    def test_concurrent_delivery(self):
        # Attempt to send message
        self.filename = os.path.join(self.dir, 'message')

        temp = open(self.filename, "w+b")
        temp.write(b('X-Actually-From: [email protected]\n')+
                   b('X-Actually-To: [email protected], [email protected]\n')+
                   b('Header: value\n\nBody\n'))
        temp.close()

        self.qp.maildir.files.append(self.filename)

        # Trick processor into thinking message is being delivered by
        # another process.
        head, tail = os.path.split(self.filename)
        tmp_filename = os.path.join(head, '.sending-' + tail)
        queue._os_link(self.filename, tmp_filename)
        try:
            self.qp.send_messages()

            self.assertEqual(self.qp.mailer.sent_messages, [])
            self.assertTrue(os.path.exists(self.filename),
                            'File does not exist')
            self.assertEqual(self.qp.log.infos, [])
        finally:
            os.unlink(tmp_filename)