def test_factory(self): from repoze.sendmail.maildir import Maildir # Case 1: normal maildir Maildir('/path/to/maildir') # Case 2a: directory does not exist, create = False self.assertRaises(ValueError, Maildir, '/path/to/nosuchfolder', False) # Case 2b: directory does not exist, create = True Maildir('/path/to/nosuchfolder', True) dirs = list(self.fake_os_module._made_directories) dirs.sort() self.assertEqual(dirs, ['/path/to/nosuchfolder', '/path/to/nosuchfolder/cur', '/path/to/nosuchfolder/new', '/path/to/nosuchfolder/tmp']) # Case 3: it is a file, not a directory self.assertRaises(ValueError, Maildir, '/path/to/regularfile', False) self.assertRaises(ValueError, Maildir, '/path/to/regularfile', True) # Case 4: it is a directory, but not a maildir self.assertRaises(ValueError, Maildir, '/path/to/emptydirectory', False) self.assertRaises(ValueError, Maildir, '/path/to/emptydirectory', True)
def createDataManager(self, fromaddr, toaddrs, message): message = copy_message(message) message['X-Actually-From'] = Header(fromaddr, 'utf-8') message['X-Actually-To'] = Header(','.join(toaddrs), 'utf-8') maildir = Maildir(self.queuePath, True) tx_message = maildir.add(message) return MailDataManager(tx_message.commit, onAbort=tx_message.abort)
def test_add(self): from email.message import Message from repoze.sendmail.maildir import Maildir m = Maildir('/path/to/maildir') tx_message = m.add(Message()) self.assertTrue(tx_message._pending_path, '/path/to/maildir/tmp/1234500002.4242.myhostname.')
def test_newMessage(self): from repoze.sendmail.maildir import Maildir from repoze.sendmail.interfaces import IMaildirMessageWriter m = Maildir('/path/to/maildir') fd = m.newMessage() verifyObject(IMaildirMessageWriter, fd) self.assert_(fd._filename.startswith( '/path/to/maildir/tmp/1234500002.4242.myhostname.'))
def createDataManager(self, fromaddr, toaddrs, message): maildir = Maildir(self.queuePath, True) msg = maildir.newMessage() msg.write('X-Zope-From: %s\n' % fromaddr) msg.write('X-Zope-To: %s\n' % ", ".join(toaddrs)) msg.write(message) msg.close() return MailDataManager(msg.commit, onAbort=msg.abort)
def test_newMessage(self): from repoze.sendmail.maildir import Maildir from repoze.sendmail.interfaces import IMaildirMessageWriter m = Maildir('/path/to/maildir') fd = m.newMessage() verifyObject(IMaildirMessageWriter, fd) self.assert_( fd._filename.startswith( '/path/to/maildir/tmp/1234500002.4242.myhostname.'))
def setUp(self): from repoze.sendmail.delivery import QueuedMailDelivery from repoze.sendmail.maildir import Maildir self.dir = mkdtemp() self.queue_dir = os.path.join(self.dir, "queue") self.delivery = QueuedMailDelivery(self.queue_dir) self.maildir = Maildir(self.queue_dir, True) self.mailer = MailerStub()
def test_iteration(self): from repoze.sendmail.maildir import Maildir m = Maildir('/path/to/maildir') messages = list(m) self.assertEqual(messages, ['/path/to/maildir/new/1', '/path/to/maildir/new/2', '/path/to/maildir/cur/2', '/path/to/maildir/cur/1'])
def setUp(self): from repoze.sendmail.delivery import QueuedMailDelivery from repoze.sendmail.maildir import Maildir self.dir = mkdtemp() self.queue_dir = os.path.join(self.dir, "queue") self.delivery = QueuedMailDelivery(self.queue_dir) self.maildir = Maildir(self.queue_dir, True) self.mailer = _makeMailerStub() self.save_stderr = sys.stderr sys.stderr = self.stderr = StringIO()
def send(self, mto, message): """ keep in mind... This is only called inside another thread, after transaction has completed """ try: from repoze.sendmail import encoding encoding.cleanup_message(message) except ImportError: pass messageid = message['Message-Id'] if messageid is None: msgid_domain = self.msgid_domain messageid = message['Message-Id'] = make_msgid(domain=msgid_domain) if message['Date'] is None: message['Date'] = formatdate() message['X-Actually-From'] = Header(self.mfrom, 'utf-8') message['X-Actually-To'] = Header(','.join(mto), 'utf-8') maildir = Maildir(self.queuePath, True) tx_message = maildir.add(message) tx_message.commit() return messageid
def test_add_os_error(self): from email.message import Message from repoze.sendmail.maildir import Maildir self.fake_os_module._exception = OSError('test') m = Maildir('/path/to/maildir') self.assertRaises(OSError, m.add, Message())
def test_add_no_good_filenames(self): from email.message import Message from repoze.sendmail.maildir import Maildir self.fake_os_module._all_files_exist = True m = Maildir('/path/to/maildir') self.assertRaises(RuntimeError, m.add, Message())
def __init__(self, mailer, queue_path, Maildir=Maildir): self.mailer = mailer self.maildir = Maildir(queue_path, create=True)
def test_newMessage_never_loops(self): from repoze.sendmail.maildir import Maildir from repoze.sendmail.interfaces import IMaildirMessageWriter self.fake_os_module._all_files_exist = True m = Maildir('/path/to/maildir') self.assertRaises(RuntimeError, m.newMessage)
def __init__(self, mailer, queue_path, Maildir=Maildir, ignore_transient=False): self.mailer = mailer self.maildir = Maildir(queue_path, create=True) self.ignore_transient = ignore_transient
def setQueuePath(self, path): self.maildir = Maildir(path, True)