From: Pierre Habouzit (MadCoder Date: Tue, 21 Dec 2004 14:13:24 +0000 (+0000) Subject: bounces + mail delivery X-Git-Tag: xorg/old~630 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=b4a8fd97cce5b376205dffd3b6c6dfdd0a8a66f6;p=platal.git bounces + mail delivery add the sendmail delivery in plat/al work on the bounce proxy. should be done (IMHO) TODO : the cron that uses emails_broken to send the broken leg messages. git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-118 --- diff --git a/bin/sendmail b/bin/sendmail new file mode 100755 index 0000000..e887936 --- /dev/null +++ b/bin/sendmail @@ -0,0 +1,30 @@ +#!/bin/ash +export LANG=C + +UID="$1" +ALIAS="$2" +PASS="$3" + +[ -n "$UID" ] || { + echo "uid vide" + exit 75 # TEMPFAIL +} + +[ -n "$ALIAS" ] || { + echo "alias vide" + exit 75 # TEMPFAIL +} + +TO=`mysql -u web -h localhost --password="$3" -B -N x4dat -e \ + "UPDATE emails SET last=NOW() WHERE uid = '$UID' AND FIND_IN_SET('active',flags) AND uid != 0; \ + SELECT email FROM emails WHERE uid = '$UID' AND FIND_IN_SET('active',flags) AND uid != 0"` +[ $? -eq 0 ] || { + echo "MySQL error for $UID" + exit 75 # TEMPFAIL +} +[ -n "$TO" ] || { + exec cat > /dev/null +} + +OURSENDER=`echo "${ALIAS}__${SENDER}" | sed -e s/@/__/` +exec /usr/lib/sendmail -oi -V+= -f "${OURSENDER}@bounces.m4x.org" $TO diff --git a/bin/smtp_bounce_proxy.py b/bin/smtp_bounce_proxy.py index 28ae641..5be333d 100755 --- a/bin/smtp_bounce_proxy.py +++ b/bin/smtp_bounce_proxy.py @@ -1,10 +1,11 @@ #! /usr/bin/python +# set:encoding=iso-8859-1: import asyncore import email -import email.Message import os, re, sys +from email import Message, MIMEText, MIMEMultipart from email.Iterators import typed_subpart_iterator, _structure from smtpd import PureProxy @@ -56,7 +57,7 @@ def msg_of_str(data): return email.message_from_string(data, _class=BounceMessag # #------------------------------------------------------------------------------- -class BounceMessage(email.Message.Message): +class BounceMessage(Message.Message): def body(self): """this method returns the part that is commonely designed as the 'body' @@ -88,7 +89,7 @@ class BounceMessage(email.Message.Message): it seems to be designed like this : ============================================= - [...QMAIL crap...] + [...QMAIL crap... --- Below this line is a copy of the message. Return-Path: <...> @@ -141,13 +142,12 @@ class BounceMessage(email.Message.Message): nb = int(mysql.rowcount) for x in range(0,nb): row = mysql.fetchone() - rxp = re.compile(str(row[1])) - if rxp.match(body): + if re.compile(str(row[1]), re.I | re.M).search(body): return (int(row[0]), str(row[2])) return (NOTICE, '') - def forge_error(self, txt): + def forge_error(self, alias, dest, txt): """we have to do our little treatments for the broken mail, and then we create an informative message for the original SENDER to : - explain to him what happened (the detailed error) @@ -155,13 +155,59 @@ class BounceMessage(email.Message.Message): - if no other leg, give an information to the SENDER on how he can give to us a real good leg and attach any sensible information about the original mail (@see attached_mail) """ - raise NotImplementedError + + mysql.execute("SELECT id FROM aliases WHERE alias='%s' AND type IN ('alias', 'a_vie') LIMIT 1" % (alias)) + if int(mysql.rowcount) is not 1: + return None + uid = mysql.fetchone()[0] + mysql.execute("UPDATE emails SET panne = NOW() WHERE uid='%s' AND email='%s'""" % (uid, dest)) + mysql.execute("REPLACE INTO emails_broken (uid,email) VALUES(%s, '%s')" % (uid, dest)) + mysql.execute("""SELECT COUNT(*), + IFNULL(SUM(panne=0 OR (last!=0 AND ( TO_DAYS(NOW())-TO_DAYS(last) )>7 AND panne""" + bounce['To'] = sender self._deliver("MAILER-DAEMON@bounces.m4x.org", [sender], bounce.as_string()) except: pass diff --git a/upgrade/0.9.3/85_bounces_proxy.sql b/upgrade/0.9.3/85_bounces_proxy.sql index 97eba0b..47f7270 100644 --- a/upgrade/0.9.3/85_bounces_proxy.sql +++ b/upgrade/0.9.3/85_bounces_proxy.sql @@ -10,3 +10,11 @@ create table emails_bounces_re ( ); insert into admin_a values(1,'Regexps Bounces', 'admin/emails_bounces_re.php', 30); + +alter table emails add column last date not null after panne; + +create table emails_broken ( + uid int not null, + email varchar(255) not null, + primary key (uid,email) +);