| 1 | diff -r 8fe7f66d1b98 tests/test_message.py |
|---|
| 2 | --- a/tests/test_message.py Mon Jul 14 21:59:31 2008 +0200 |
|---|
| 3 | +++ b/tests/test_message.py Mon Jul 14 22:00:42 2008 +0200 |
|---|
| 4 | @@ -1,6 +1,5 @@ |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | - |
|---|
| 8 | """Test the TurboMail Message class.""" |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | diff -r 8fe7f66d1b98 tests/test_tm2_compatibility.py |
|---|
| 12 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|---|
| 13 | +++ b/tests/test_tm2_compatibility.py Mon Jul 14 22:00:42 2008 +0200 |
|---|
| 14 | @@ -0,0 +1,55 @@ |
|---|
| 15 | + |
|---|
| 16 | + |
|---|
| 17 | +'''Test that most interfaces of TurboMail 2.x are working in TurboMail 3.x''' |
|---|
| 18 | + |
|---|
| 19 | +import unittest |
|---|
| 20 | + |
|---|
| 21 | +from turbomail.managers.immediate import ImmediateManager |
|---|
| 22 | +from turbomail.providers.debug import DebugProviderFactory |
|---|
| 23 | + |
|---|
| 24 | +class TestTurboMail2xCompatibility(unittest.TestCase): |
|---|
| 25 | + |
|---|
| 26 | + def tearDown(self): |
|---|
| 27 | + import turbomail |
|---|
| 28 | + turbomail.control.interface.stop(force=True) |
|---|
| 29 | + turbomail.control.interface.config = {'mail.on': False} |
|---|
| 30 | + |
|---|
| 31 | + def test_message_instantiation_with_positional_parameters(self): |
|---|
| 32 | + from turbomail import Message |
|---|
| 33 | + message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 34 | + message.plain = 'Hello world!' |
|---|
| 35 | + msg_string = str(message) |
|---|
| 36 | + self.failUnless('From: from@example.com' in msg_string) |
|---|
| 37 | + self.failUnless('To: to@example.com' in msg_string) |
|---|
| 38 | + self.failUnless('Subject: Test' in msg_string) |
|---|
| 39 | + |
|---|
| 40 | + def test_message_instantiation_with_keyword_parameters(self): |
|---|
| 41 | + from turbomail import Message |
|---|
| 42 | + message = Message(sender='from@example.com', recipient='to@example.com', |
|---|
| 43 | + subject='Test') |
|---|
| 44 | + message.plain = 'Hello world!' |
|---|
| 45 | + msg_string = str(message) |
|---|
| 46 | + self.failUnless('From: from@example.com' in msg_string) |
|---|
| 47 | + self.failUnless('To: to@example.com' in msg_string) |
|---|
| 48 | + self.failUnless('Subject: Test' in msg_string) |
|---|
| 49 | + |
|---|
| 50 | + def test_message_enqueue_not_enabled(self): |
|---|
| 51 | + import turbomail |
|---|
| 52 | + from turbomail import Message |
|---|
| 53 | + |
|---|
| 54 | + from turbomail import MailNotEnabledError |
|---|
| 55 | + message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 56 | + message.plain = 'Hello world!' |
|---|
| 57 | + self.assertRaises(MailNotEnabledError, turbomail.enqueue, message) |
|---|
| 58 | + |
|---|
| 59 | + def test_message_enqueue(self): |
|---|
| 60 | + import turbomail |
|---|
| 61 | + from turbomail import Message |
|---|
| 62 | + turbomail.control.interface.config = {'mail.on': True} |
|---|
| 63 | + |
|---|
| 64 | + turbomail.control.interface.start(manager=ImmediateManager(), |
|---|
| 65 | + provider=DebugProviderFactory()) |
|---|
| 66 | + message = Message('from@example.com', 'to@example.com', 'Test') |
|---|
| 67 | + message.plain = 'Hello world!' |
|---|
| 68 | + turbomail.enqueue(message) |
|---|
| 69 | + |
|---|
| 70 | diff -r 8fe7f66d1b98 turbomail/__init__.py |
|---|
| 71 | --- a/turbomail/__init__.py Mon Jul 14 21:59:31 2008 +0200 |
|---|
| 72 | +++ b/turbomail/__init__.py Mon Jul 14 22:00:42 2008 +0200 |
|---|
| 73 | @@ -0,0 +1,13 @@ |
|---|
| 74 | + |
|---|
| 75 | +from turbomail.control import interface |
|---|
| 76 | +from turbomail.exceptions import * |
|---|
| 77 | +from turbomail.message import Message |
|---|
| 78 | + |
|---|
| 79 | +def send(message): |
|---|
| 80 | + '''Send a message via TurboMail.''' |
|---|
| 81 | + return interface.send(message) |
|---|
| 82 | + |
|---|
| 83 | + |
|---|
| 84 | + |
|---|
| 85 | +enqueue = send |
|---|
| 86 | + |
|---|
| 87 | diff -r 8fe7f66d1b98 turbomail/exceptions.py |
|---|
| 88 | --- a/turbomail/exceptions.py Mon Jul 14 21:59:31 2008 +0200 |
|---|
| 89 | +++ b/turbomail/exceptions.py Mon Jul 14 22:00:42 2008 +0200 |
|---|
| 90 | @@ -3,7 +3,8 @@ |
|---|
| 91 | """Exceptions used by TurboMail to report common errors.""" |
|---|
| 92 | |
|---|
| 93 | __version__ = "$Revision: 84 $" |
|---|
| 94 | -__all__ = ['MailException', 'MailNotEnabledError', 'MailConfigurationError', 'ProviderException', 'ProviderExhaustedException', 'ManagerException'] |
|---|
| 95 | +__all__ = ['MailException', 'MailNotEnabledError', 'MailConfigurationError', |
|---|
| 96 | + 'ProviderException', 'ProviderExhaustedException', 'ManagerException'] |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | class MailException(Exception): |
|---|
| 100 | diff -r 8fe7f66d1b98 turbomail/message.py |
|---|
| 101 | --- a/turbomail/message.py Mon Jul 14 21:59:31 2008 +0200 |
|---|
| 102 | +++ b/turbomail/message.py Mon Jul 14 22:00:42 2008 +0200 |
|---|
| 103 | @@ -7,7 +7,7 @@ |
|---|
| 104 | from turbomail import release |
|---|
| 105 | from turbomail.util import AddressList |
|---|
| 106 | from turbomail.control import interface |
|---|
| 107 | -import re, os, email |
|---|
| 108 | +import os |
|---|
| 109 | |
|---|
| 110 | import email.Message |
|---|
| 111 | from email import Encoders, Charset |
|---|
| 112 | @@ -45,7 +45,7 @@ |
|---|
| 113 | class Message(object): |
|---|
| 114 | """Simple e-mail message class.""" |
|---|
| 115 | |
|---|
| 116 | - def __init__(self, **kw): |
|---|
| 117 | + def __init__(self, sender=None, recipient=None, subject=None, **kw): |
|---|
| 118 | """Instantiate a new Message object. |
|---|
| 119 | |
|---|
| 120 | No arguments are required, as everything can be set using class |
|---|
| 121 | @@ -64,8 +64,21 @@ |
|---|
| 122 | |
|---|
| 123 | self.date = kw.get("date", formatdate(localtime=True)) |
|---|
| 124 | |
|---|
| 125 | + if sender != None: |
|---|
| 126 | + # TODO: Raise ValueError! |
|---|
| 127 | + kw['from_'] = sender |
|---|
| 128 | + if recipient != None: |
|---|
| 129 | + kw['to'] = recipient |
|---|
| 130 | + if subject != None: |
|---|
| 131 | + kw['subject'] = subject |
|---|
| 132 | if 'authors' in kw: kw['author'] == kw['authors'] |
|---|
| 133 | if 'senders' in kw: kw['sender'] == kw['senders'] |
|---|
| 134 | +# if 'authors' in kw: |
|---|
| 135 | +# kw['author'] = kw['authors'] |
|---|
| 136 | +# if 'senders' in kw: |
|---|
| 137 | +# kw['sender'] = kw['senders'] |
|---|
| 138 | +# elif sender != None: |
|---|
| 139 | +# kw['sender'] = sender |
|---|
| 140 | |
|---|
| 141 | self._from = AddressList(configget("from_", "mail.message.author")) |
|---|
| 142 | self._sender = AddressList(configget("sender", "mail.message.sender")) |
|---|