示例#1
0
 def deliver(self):
     WLog.debug("User %s Group %s" % (os.getuid(), os.getgid()))
     WLog.debug("Deliver with: %s" % self.deliver_application)
     p = subprocess.Popen(self.deliver_application, stdin=subprocess.PIPE)
     p.stdin.write(self.data)
     p.stdin.close()
示例#2
0
    def parse(self):
        # Split the data into headers and body
        split = data.find("\n\n")
        self.header_data = "%s\n\n" % data[:split]
        self.body_data = data[split + 2 :]

        # parse the e-mail header
        WLog.debug("Parsing e-mail")
        message = email.message_from_string(self.header_data)
        try:
            self.mail_to = sys.argv[sys.argv.index("-d") + 1]
        except (IndexError, ValueError):
            WLog.error("no recipient found")
            sys.stderr.write("no recipient found")
            sys.exit(2)
        try:
            self.mail_from = sys.argv[sys.argv.index("-f") + 1]
        except (IndexError, ValueError):
            self.mail_from = "unknown"
        if not self.mail_from:
            self.mail_from = message.get("From")
        if not self.mail_to:
            self.mail_to = message.get("Delivered-To")
        WLog.debug("e-mail from %s to %s" % (self.mail_from, self.mail_to))

        try:
            (self.user, self.domain) = self.mail_to.split("@")
        except:
            WLog.error("no valid destination mail address %s" % self.mail_to)
            sys.stderr.write("no valid destination mail address %s" % self.mail_to)
            sys.exit(3)

        try:
            self.extensions = sys.argv[sys.argv.index("-e") + 1]
        except (IndexError, ValueError):
            self.extensions = ""

        if self.extensions:
            (self.user, extensions) = self.user.split(DELIMITER)
            if self.extensions != extensions:
                WLog.error("self.extensions=%s extensions=%s" % (self.extensions, extensions))

        # set maildrop as default deliver
        self.deliver_application = [
            MAILDROP_DELIVER,
            "-d",
            "vmail",
            self.extensions,
            self.mail_to,
            self.user,
            self.domain,
            self.mail_from,
            "-w",
            "90",
        ]

        # replace Return-Path: <MAILER-DAEMON>
        try:
            if message.get("Return-Path") == "<MAILER-DAEMON>":
                WLog.notice("replace Return-Path: <MAILER-DAEMON> to %s" % MAILER_DAEMON)
                status, result = run([REFORMAIL, "-I", "Return-Path:%s" % MAILER_DAEMON], self.header_data)
                if status == 0:
                    self.header_data = result
        except Exception, e:
            WLog.error("%s" % e)
示例#3
0
            spam_headers = []

        try:
            if not self.is_virus and not self.is_spam and not self.extensions:
                self.deliver_application = [DOVECOT_DELIVER, "-d", self.mail_to, "-f", self.mail_from]
        except Exception:  # any errors
            pass

        headers = virus_headers + spam_headers

        if headers:
            args = reduce(operator.add, [["-I", header] for header in ["%s:" % h for h in RESERVED_HEADERS] + headers])
            status, result = run([REFORMAIL] + args, self.header_data)
            assert status == 0, "Could not run %s (exit code %d)" % (REFORMAIL, status)
            self.data = result + self.body_data
            WLog.debug("New headers set")

    def check_virus(self):
        headers = []

        # Get the version
        status, version = run([CLAMSCAN, "-V"])
        assert status == 0, "Could not run %s (exit code %d)" % (CLAMSCAN, status)

        headers.append("X-Virus-Checker-Version: %s" % version.split("\n")[0])

        # Scan the message
        status, message = run([CLAMSCAN, "-", "--stdout", "--disable-summary"], self.data)

        if status == 0:
            # No virus