Пример #1
0
def blast(inbox, host, port, lmtp, debug):
    """
    Given a Maildir, this command will go through each email
    and blast it at your server.  It does nothing to the message, so
    it will be real messages hitting your server, not cleansed ones.
    """
    try:
        inbox = mailbox.mbox(inbox, create=False)
    except (mailbox.Error, IOError):
        try:
            inbox = mailbox.Maildir(inbox, factory=None, create=False)
        except (mailbox.Error, IOError):
            raise click.ClickException(
                "{} does not exist or is not a valid MBox or Maildir".format(
                    inbox))

    relay = server.Relay(host, port=port, lmtp=lmtp, debug=debug)

    for key in inbox.keys():
        msgfile = inbox.get_file(key)
        msg = encoding.from_file(msgfile)
        try:
            relay.deliver(msg)
        except socket.error as exp:
            raise click.ClickException(str(exp))
        finally:
            msgfile.close()
Пример #2
0
    def test_to_file_from_file(self):
        mb = mailbox.mbox("tests/data/spam")
        msg = encoding.from_message(mb[0])

        outfile = "run/encoding_test.msg"

        with open(outfile, 'w') as outfp:
            encoding.to_file(msg, outfp)

        with open(outfile) as outfp:
            msg2 = encoding.from_file(outfp)

        self.assertEqual(len(msg), len(msg2))
        os.unlink(outfile)
Пример #3
0
def test_to_file_from_file():
    mb = mailbox.mbox("tests/spam")
    msg = encoding.from_message(mb[0])

    outfile = "run/encoding_test.msg"

    with open(outfile, 'w') as outfp:
        encoding.to_file(msg, outfp)

    with open(outfile) as outfp:
        msg2 = encoding.from_file(outfp)

    assert_equal(len(msg), len(msg2))
    os.unlink(outfile)
Пример #4
0
def test_content_encoding_headers_are_maintained():
    inmail = encoding.from_file(open("tests/signed.msg"))

    ctype, ctype_params = inmail.content_encoding['Content-Type']

    assert_equal(ctype, 'multipart/signed')

    # these have to be maintained
    for key in ['protocol', 'micalg']:
        assert key in ctype_params

    # these get removed
    for key in encoding.CONTENT_ENCODING_REMOVED_PARAMS:
        assert key not in ctype_params

    outmsg = encoding.to_message(inmail)
    ctype, ctype_params = encoding.parse_parameter_header(outmsg, 'Content-Type')
    for key in ['protocol', 'micalg']:
        assert key in ctype_params, key
Пример #5
0
def test_content_encoding_headers_are_maintained():
    inmail = encoding.from_file(open("tests/signed.msg"))

    ctype, ctype_params = inmail.content_encoding['Content-Type']

    assert_equal(ctype, 'multipart/signed')

    # these have to be maintained
    for key in ['protocol', 'micalg']:
        assert key in ctype_params

    # these get removed
    for key in encoding.CONTENT_ENCODING_REMOVED_PARAMS:
        assert key not in ctype_params

    outmsg = encoding.to_message(inmail)
    ctype, ctype_params = encoding.parse_parameter_header(outmsg, 'Content-Type')
    for key in ['protocol', 'micalg']:
        assert key in ctype_params, key
Пример #6
0
def test_to_message_encoding_error(mp_init):
    mp_init.side_effect = raises_TypeError
    test = encoding.from_file(open("tests/borked.msg"))
    msg = encoding.to_message(test)
Пример #7
0
def test_specially_borked_lua_message():
    assert encoding.from_file(open("tests/borked.msg"))
Пример #8
0
 def test_to_message_encoding_error(self, mp_init):
     mp_init.side_effect = TypeError
     with open("tests/data/borked.msg", "rb") as file_obj:
         test = encoding.from_file(file_obj)
     with self.assertRaises(encoding.EncodingError):
         encoding.to_message(test)
Пример #9
0
 def test_specially_borked_lua_message(self):
     with open("tests/data/borked.msg", "rb") as file_obj:
         msg = encoding.from_file(file_obj)
     assert msg
Пример #10
0
def test_to_message_encoding_error(mp_init):
    mp_init.side_effect = raises_TypeError
    test = encoding.from_file(open("tests/borked.msg", "rb"))
    encoding.to_message(test)
Пример #11
0
def test_specially_borked_lua_message():
    msg = encoding.from_file(open("tests/borked.msg", "rb"))
    assert msg
Пример #12
0
def test_specially_borked_lua_message():
    assert encoding.from_file(open("tests/borked.msg"))
Пример #13
0
def test_specially_borked_lua_message():
    msg = encoding.from_file(open("tests/borked.msg", "rb"))
    assert msg