コード例 #1
0
    def init_mailer_from_name(self, name):
        element = self.cfgtree.find('mailer[@name="%s"]' % name)
        if element is None:
            return None

        mail = Mail()
        mail.set_sender(element.find('from').text)
        mail.set_to(element.find('to').text)
        mail.set_subject(element.find('subject').text)
        mail.set_body(element.find('body').text)

        server = element.find('server').text
        return Mailer(server, mail)
コード例 #2
0
 def testConstructor(self):
     mail = Mail()
     self.assertNotEqual(mail.get_sender(), None)
     self.assertNotEqual(mail.get_sender(), '')
     user = getuser()
     self.assertTrue(mail.get_sender().startswith(user + '@'))
コード例 #3
0
 def setUp(self):
     self.mail = Mail(sender='test')
コード例 #4
0
class MailTest(unittest.TestCase):
    CORRELATE = Mail

    def setUp(self):
        self.mail = Mail(sender='test')

    def testConstructor(self):
        mail = Mail()
        self.assertNotEqual(mail.get_sender(), None)
        self.assertNotEqual(mail.get_sender(), '')
        user = getuser()
        self.assertTrue(mail.get_sender().startswith(user + '@'))

    def testSetFromTemplateString(self):
        self.mail.set_from_template_string(template)
        tmpl = self.mail.get_smtp_mail().strip()
        self.assertEqual(tmpl, smtp)
        head = self.mail.get_smtp_header().strip()
        self.assertTrue(tmpl.startswith(head))

    def testSetSender(self):
        self.assertEqual(self.mail.get_sender(), 'test')
        self.mail.set_sender('test2')
        self.assertEqual(self.mail.get_sender(), 'test2')

    def testGetSender(self):
        pass  # see testSetSender()

    def checkSetAddr(self, set_method, get_method):
        set_method('test')
        self.assertEqual(get_method(), ['test'])

        set_method(['test1', 'test2'])
        self.assertEqual(get_method(), ['test1', 'test2'])

        set_method('test1, test2')
        self.assertEqual(get_method(), ['test1', 'test2'])

    def checkAddAddr(self, add_method, get_method):
        add_method(['test1', 'test2'])
        self.assertEqual(get_method(), ['test1', 'test2'])

        add_method('test3, test4')
        self.assertEqual(get_method(), ['test1', 'test2', 'test3', 'test4'])

    def testSetTo(self):
        self.checkSetAddr(self.mail.set_to, self.mail.get_to)

    def testAddTo(self):
        self.checkAddAddr(self.mail.add_to, self.mail.get_to)

    def testGetTo(self):
        pass  # see testSetTo()

    def testSetCc(self):
        self.checkSetAddr(self.mail.set_cc, self.mail.get_cc)

    def testAddCc(self):
        self.checkAddAddr(self.mail.add_cc, self.mail.get_cc)

    def testGetCc(self):
        pass  # see testSetCc()

    def testSetBcc(self):
        self.checkSetAddr(self.mail.set_bcc, self.mail.get_bcc)

    def testAddBcc(self):
        self.checkAddAddr(self.mail.add_bcc, self.mail.get_bcc)

    def testGetBcc(self):
        pass  # see testSetBcc()

    def testGetReceipients(self):
        self.mail.set_to('test1')
        self.mail.set_cc('test2')
        self.mail.set_bcc('test3')
        self.assertEqual(self.mail.get_receipients(),
                         ['test1', 'test2', 'test3'])

    def testSetSubject(self):
        self.assertEqual(self.mail.get_subject(), '')
        self.mail.set_subject('test')
        self.assertEqual(self.mail.get_subject(), 'test')

    def testGetSubject(self):
        pass  # see testSetSubject()

    def testSetBody(self):
        self.assertEqual(self.mail.get_body(), '')
        self.mail.set_body('test')
        self.assertEqual(self.mail.get_body(), 'test')

    def testGetBody(self):
        pass  # see testSetBody()

    def testAddAttachment(self):
        self.assertEqual(self.mail.get_attachments(), [])
        self.mail.add_attachment('foo')
        self.assertEqual(self.mail.get_attachments(), ['foo'])
        self.mail.add_attachment('bar')
        self.assertEqual(self.mail.get_attachments(), ['foo', 'bar'])

    def testGetAttachments(self):
        self.testAddAttachment()

    def testGetSmtpHeader(self):
        pass  # see testSetFromTemplateString()

    def testGetSmtpMail(self):
        pass  # see testSetFromTemplateString()
コード例 #5
0
ファイル: mailTest.py プロジェクト: 0x24bin/exscript
 def setUp(self):
     self.mail = Mail(sender = 'test')
コード例 #6
0
ファイル: mailTest.py プロジェクト: 0x24bin/exscript
class MailTest(unittest.TestCase):
    CORRELATE = Mail

    def setUp(self):
        self.mail = Mail(sender = 'test')

    def testConstructor(self):
        mail = Mail()
        self.failIfEqual(mail.get_sender(), None)
        self.failIfEqual(mail.get_sender(), '')
        user = getuser()
        self.assert_(mail.get_sender().startswith(user + '@'))

    def testSetFromTemplateString(self):
        self.mail.set_from_template_string(template)
        tmpl = self.mail.get_smtp_mail().strip()
        self.assertEqual(tmpl, smtp)
        head = self.mail.get_smtp_header().strip()
        self.assert_(tmpl.startswith(head))

    def testSetSender(self):
        self.assertEqual(self.mail.get_sender(), 'test')
        self.mail.set_sender('test2')
        self.assertEqual(self.mail.get_sender(), 'test2')

    def testGetSender(self):
        pass # see testSetSender()

    def checkSetAddr(self, set_method, get_method):
        set_method('test')
        self.assertEqual(get_method(), ['test'])

        set_method(['test1', 'test2'])
        self.assertEqual(get_method(), ['test1', 'test2'])

        set_method('test1, test2')
        self.assertEqual(get_method(), ['test1', 'test2'])

    def checkAddAddr(self, add_method, get_method):
        add_method(['test1', 'test2'])
        self.assertEqual(get_method(), ['test1', 'test2'])

        add_method('test3, test4')
        self.assertEqual(get_method(), ['test1', 'test2', 'test3', 'test4'])

    def testSetTo(self):
        self.checkSetAddr(self.mail.set_to, self.mail.get_to)

    def testAddTo(self):
        self.checkAddAddr(self.mail.add_to, self.mail.get_to)

    def testGetTo(self):
        pass # see testSetTo()

    def testSetCc(self):
        self.checkSetAddr(self.mail.set_cc, self.mail.get_cc)

    def testAddCc(self):
        self.checkAddAddr(self.mail.add_cc, self.mail.get_cc)

    def testGetCc(self):
        pass # see testSetCc()

    def testSetBcc(self):
        self.checkSetAddr(self.mail.set_bcc, self.mail.get_bcc)

    def testAddBcc(self):
        self.checkAddAddr(self.mail.add_bcc, self.mail.get_bcc)

    def testGetBcc(self):
        pass # see testSetBcc()

    def testGetReceipients(self):
        self.mail.set_to('test1')
        self.mail.set_cc('test2')
        self.mail.set_bcc('test3')
        self.assertEqual(self.mail.get_receipients(),
                         ['test1', 'test2', 'test3'])

    def testSetSubject(self):
        self.assertEqual(self.mail.get_subject(), '')
        self.mail.set_subject('test')
        self.assertEqual(self.mail.get_subject(), 'test')

    def testGetSubject(self):
        pass # see testSetSubject()

    def testSetBody(self):
        self.assertEqual(self.mail.get_body(), '')
        self.mail.set_body('test')
        self.assertEqual(self.mail.get_body(), 'test')

    def testGetBody(self):
        pass # see testSetBody()

    def testAddAttachment(self):
        self.assertEqual(self.mail.get_attachments(), [])
        self.mail.add_attachment('foo')
        self.assertEqual(self.mail.get_attachments(), ['foo'])
        self.mail.add_attachment('bar')
        self.assertEqual(self.mail.get_attachments(), ['foo', 'bar'])

    def testGetAttachments(self):
        self.testAddAttachment()

    def testGetSmtpHeader(self):
        pass # see testSetFromTemplateString()

    def testGetSmtpMail(self):
        pass # see testSetFromTemplateString()
コード例 #7
0
ファイル: MailWindowTest.py プロジェクト: zdenotim/exscript
from Exscript.util.mail import Mail
from TkExscript import MailWindow
mail = Mail(subject='Test me', body='hello world')
MailWindow(mail).mainloop()
コード例 #8
0
    def __init__(self,
                 parent,
                 mail=None,
                 server='localhost',
                 show_to=True,
                 show_cc=True,
                 show_bcc=False,
                 on_subject_changed=None):
        """
        A simple editor for sending emails. If the given mail is None, a
        new mail is created, else it is passed to attach().

        @type  parent: tkinter.Frame
        @param parent: The parent widget.
        @type  mail: Exscript.util.mail.Mail
        @param mail: The email object to attach.
        @type  server: string
        @param server: The address of the mailserver.
        @type  show_to: bool
        @param show_to: Whether to show the "To:" entry box.
        @type  show_cc: bool
        @param show_cc: Whether to show the "Cc:" entry box.
        @type  show_bcc: bool
        @param show_bcc: Whether to show the "Bcc:" entry box.
        @type  on_subject_changed: function
        @param on_subject_changed: Called whenever the subject changes.
        """
        Frame.__init__(self, parent)
        self.pack(expand=True, fill=BOTH)
        self.columnconfigure(0, pad=6)
        self.columnconfigure(1, weight=1)

        row = -1
        self.label_to = Label(self, text='To:')
        self.entry_to = Entry(self)
        if show_to:
            row += 1
            self.rowconfigure(row, pad=row > 0 and 6 or 0)
            self.label_to.grid(row=row, column=0, sticky=W)
            self.entry_to.grid(row=row, column=1, columnspan=2, sticky=W + E)
            self.entry_to.bind('<Key>', self._on_field_changed)

        self.label_cc = Label(self, text='Cc:')
        self.entry_cc = Entry(self)
        if show_cc:
            row += 1
            self.rowconfigure(row, pad=row > 0 and 6 or 0)
            self.label_cc.grid(row=row, column=0, sticky=W)
            self.entry_cc.grid(row=row, column=1, columnspan=2, sticky=W + E)
            self.entry_cc.bind('<Key>', self._on_field_changed)

        self.label_bcc = Label(self, text='Bcc:')
        self.entry_bcc = Entry(self)
        if show_bcc:
            row += 1
            self.rowconfigure(row, pad=row > 0 and 6 or 0)
            self.label_bcc.grid(row=row, column=0, sticky=W)
            self.entry_bcc.grid(row=row, column=1, columnspan=2, sticky=W + E)
            self.entry_bcc.bind('<Key>', self._on_field_changed)

        row += 1
        self.rowconfigure(row, pad=row > 0 and 6 or 0)
        self.label_subject = Label(self, text='Subject:')
        self.label_subject.grid(row=row, column=0, sticky=W)
        self.entry_subject = Entry(self)
        self.entry_subject.grid(row=row, column=1, columnspan=2, sticky=W + E)
        self.entry_subject.bind('<Key>', self._on_subject_changed)

        row += 1
        self.rowconfigure(row, pad=6, weight=1)
        scrollbar = Scrollbar(self, takefocus=0)
        scrollbar.grid(row=row, column=2, sticky=N + S)
        self.text_widget = Text(self)
        self.text_widget.grid(row=row,
                              column=0,
                              columnspan=2,
                              sticky=N + S + E + W)
        self.text_widget.config(yscrollcommand=scrollbar.set)
        self.text_widget.bind('<Key>', self._on_field_changed)
        scrollbar.config(command=self.text_widget.yview)

        row += 1
        self.rowconfigure(row, pad=6)
        self.buttons = _ButtonBar(self,
                                  on_cancel=parent.quit,
                                  on_send=self._on_send)
        self.buttons.grid(row=row, column=0, columnspan=3, sticky=E)

        self.server = server
        self.on_subject_changed_cb = on_subject_changed
        self.locked = False
        self.mail = None
        self.attach(mail and mail or Mail())