Инструменты пользователя

Инструменты сайта


soft:xmail:callback_filter

Callback фильтр для XMail

Пример вызова фильтра:

filters.pre-data.tab

"!aex"	"/opt/xmail/bin/filters/callback.filter.py"	"$(FROM)"	"$(CRCPT)"	"$(FILE)"
#!/usr/bin/python
# -*- coding: utf8 -*-
 
"""
    Filename    : callback.filter.py
    Author      : Oleg Blednov
    Last update : Втр Мар 17 11:17:41 MSK 2009
"""
 
import os
import sys
import string
import DNS
import smtplib
import logging
import socket
 
logname = os.getenv("MAIL_ROOT")
if logname == None:
    logname = ""
else:
    logname = logname + "/logs/"
logname = logname + "callback.filter.log"
log = logging.getLogger("callback.filter")
hLog = logging.FileHandler(logname)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hLog.setFormatter(formatter)
log.addHandler(hLog)
log.setLevel(logging.INFO)
 
retcode = -1
 
if len(sys.argv) > 3:
    socket.timeout(30)
    retcode = 3
    where = "DNS"
    mxlist = DNS.mxlookup(sys.argv[1].rsplit("@",1)[1])
    sender = smtplib.quoteaddr(sys.argv[2])
    recipt = smtplib.quoteaddr(sys.argv[1])
    response = "550 Your server have no valid MX record."
    if mxlist != []:
        response = "550 Callback connection to your MX server failed."
        smtp = smtplib.SMTP()
        where = "MX"
        for mx in mxlist:
            try:
                smtp.connect(mx[1])
            except:
                continue
            where = "HELO"
            resp = smtp.helo()
            if resp[0] == 250:
                where = "FROM"
                resp = smtp.mail(sender)
                if resp[0] == 250:
                    where = "RCPT"
                    resp = smtp.rcpt(recipt)
            smtp.quit()
            response = str(resp[0]) + " " + resp[1]
            if resp[0] == 250 or resp[0] == 354:
                retcode = 0
            break
    logstr = "%s\t%s\t%s\t%s" % (sys.argv[1],sys.argv[2],where,response)
    if retcode == 0:
        log.info(logstr)
    else:
        rej = file("%s.rej" %(sys.argv[3]),"w")
        rej.write(response)
        rej.close()
        log.error(logstr)
else:
    print "Please enter <sender address>, <recipient address>, <reject_file_base_name>"
 
log.removeHandler(hLog)
hLog.close()
 
exit(retcode)

Дискуссия

Enter your comment
 
soft/xmail/callback_filter.txt · Последние изменения: 16.11.2009 20:26 (внешнее изменение)

Инструменты страницы