def test_readInvalidConfig(self):
        """
        Error messages for illegal UID value, illegal GID value, and illegal
        identity entry will be sent to stderr.
        """
        stdin = StringIO("\n")
        self.patch(sys, "stdin", stdin)

        filename = self.mktemp()
        myUid = os.getuid()
        myGid = os.getgid()

        with open(filename, "w") as f:
            # Create a config file with some invalid values
            f.write("[useraccess]\n"
                    "allow=invaliduser2,invaliduser1\n"
                    "deny=invaliduser3,invaliduser4,{}\n"
                    "order=allow,deny\n"
                    "[groupaccess]\n"
                    "allow=invalidgid1,invalidgid2\n"
                    "deny=invalidgid1,invalidgid2,{}\n"
                    "order=deny,allow\n"
                    "[identity]\n"
                    "localhost=funny\n"
                    "[addresses]\n"
                    "smarthost=localhost\n"
                    "default_domain=example.com\n".format(myUid, myGid))

        # The mailmail script looks in
        # the twisted.mail.scripts.GLOBAL_CFG variable
        # and then the twisted.mail.scripts.LOCAL_CFG
        # variable for the path to it's  config file.
        #
        # Override twisted.mail.scripts.LOCAL_CFG with the file we just
        # created.
        self.patch(mailmail, "LOCAL_CFG", filename)

        argv = ("test_mailmail.py", "*****@*****.**", "-oep")
        self.patch(sys, "argv", argv)
        mailmail.run()
        self.assertRegex(
            self.out.getvalue(),
            "Illegal UID in \\[useraccess\\] section: "
            "invaliduser1",
        )
        self.assertRegex(
            self.out.getvalue(),
            "Illegal GID in \\[groupaccess\\] section: "
            "invalidgid1",
        )
        self.assertRegex(self.out.getvalue(),
                         "Illegal entry in \\[identity\\] section: funny")
 def test_runErrorsToStderr(self):
     """
     Call L{mailmail.run}, and specify I{-oep} to print errors
     to stderr.  The sender, to, and printErrors options should be
     set and there should be no failure.
     """
     argv = ("test_mailmail.py", "*****@*****.**", "-oep")
     stdin = StringIO("\n")
     self.patch(sys, "argv", argv)
     self.patch(sys, "stdin", stdin)
     mailmail.run()
     self.assertEqual(self.options.sender, mailmail.getlogin())
     self.assertEqual(self.options.to, ["*****@*****.**"])
     # We should have printErrors set because we specified "-oep"
     self.assertTrue(self.options.printErrors)
     # We should not have any failures.
     self.assertIsNone(mailmail.failed)
Пример #3
0
#!C:\Users\xcpro\ve1\Scripts\python.exe
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
This script attempts to send some email.
"""

import sys, os
extra = os.path.dirname(os.path.dirname(sys.argv[0]))
sys.path.insert(0, extra)
try:
    import _preamble
except ImportError:
    sys.exc_clear()
sys.path.remove(extra)

from twisted.mail.scripts import mailmail
mailmail.run()
Пример #4
0
#!E:\wamp\www\weiboapi\weiboapi\srapyDemo\envs\Scripts\python.exe
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
This script attempts to send some email.
"""

import sys, os
extra = os.path.dirname(os.path.dirname(sys.argv[0]))
sys.path.insert(0, extra)
try:
    import _preamble
except ImportError:
    sys.exc_clear()
sys.path.remove(extra)

from twisted.mail.scripts import mailmail
mailmail.run()

Пример #5
0
# -*- coding: utf-8 -*-
import re
import sys

from twisted.mail.scripts.mailmail import run

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(run())