summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2007-02-19 11:40:14 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2007-02-19 11:40:14 +0000
commit28dc5085dd2edaf55746a1c52fe2da2595ef372d (patch)
tree1d65f1f32471d0499e3640e8b906d4c17f00d454
parenta02b000d87c44c77f8ff1617c2d654fc8568d17a (diff)
Send acks
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@255 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rwxr-xr-xsplit-mailman-mails-and-discard-and-save60
1 files changed, 59 insertions, 1 deletions
diff --git a/split-mailman-mails-and-discard-and-save b/split-mailman-mails-and-discard-and-save
index ab02340..eb00669 100755
--- a/split-mailman-mails-and-discard-and-save
+++ b/split-mailman-mails-and-discard-and-save
@@ -28,6 +28,8 @@ check_maildir SPAMLEARN
check_maildir HAMLEARN
APPROVE_PASSWORD = YAML::load( File.open( 'mailman-passwords.yaml' ) )
+ERRORBOX = "mail/errors"
+
if ARGV[0] == "spam"
ACTION = "spam"
MAILIN = "mail/spam-in"
@@ -76,6 +78,14 @@ def uniqueName
HOSTNAME]
end
+def move_mail_file(from, tofolder)
+ fn = uniqueName
+ target = tofolder+"/new/"+fn
+ File.link(from, target)
+ File.unlink(from)
+ target
+end
+
def store_in_maildir(md, msg)
fn = uniqueName
File.open(md+"/tmp/"+fn, "w", 0600) do |f|
@@ -185,6 +195,38 @@ def bogo_check(message)
[c, out.join]
end
+def fetch_resent_info(message)
+ origmsgid = message.header['Message-Id']
+ from = message.header['Resent-From']
+ date = message.header['Resent-Date']
+ msgid = message.header['Resent-Message-Id']
+ header = message.header.to_s
+
+ throw "Did not find Message-Id header in mail" unless origmsgid
+ throw "Did not find Resent-From header in mail" unless from
+ throw "Did not find Resent-Date header in mail" unless date
+ throw "Did not find Resent-Message-Id header in mail" unless msgid
+
+ return { 'origmsgid' => origmsgid,
+ 'from' => from,
+ 'date' => date,
+ 'msgid' => msgid,
+ 'header' => header }
+end
+
+def send_ack(action, resent_info)
+ mail = RMail::Message.new()
+ mail.header['From'] = FROM
+ mail.header['To'] = ERRORSTO
+ mail.header['Subject'] = "#{action} by #{resent_info['from']}"
+ mail.header['In-Reply-To'] = resent_info['origmsgid']
+ mail.header['References'] = resent_info['origmsgid']+' '+resent_info['msgid']
+ mail.body = "On #{resent_info['date']} #{resent_info['from']} #{action} this message.\n" +
+ "\n" +
+ "Request headers follow:\n" +
+ resent_info['header']
+ store_in_maildir(OUTBOX, mail)
+end
def process_mail(filename)
message = File.open(filename) { |f| RMail::Parser.read(f) }
@@ -212,11 +254,15 @@ def process_mail(filename)
if ACTION == "ham"
+ resent_info = fetch_resent_info(message)
store_in_maildir(HAMLEARN, held_part)
approve(cookie, request_address)
+ send_ack('APPROVED', resent_info)
elsif ACTION == "spam"
+ resent_info = fetch_resent_info(message)
store_in_maildir(SPAMLEARN, held_part)
discard(cookie, request_address)
+ send_ack('DISCARDED', resent_info)
elsif ACTION == "classify"
sa_class , sa_text , sa_score = sa_check(held_part)
bogo_class, bogo_text = bogo_check(held_part)
@@ -261,6 +307,18 @@ Dir[MAILIN+"/new/*"].each do |filename|
process_mail filename
File.unlink filename
rescue Exception => e
- STDERR.puts "Error when processing #{filename}: #{e}"
+ begin
+ newname = move_mail_file(filename, ERRORBOX)
+ mail_error = RMail::Message.new()
+ mail_error.header['From'] = FROM
+ mail_error.header['To'] = ERRORSTO
+ mail_error.header['Subject'] = "handling of #{filename} failed"
+ mail_error.body = "Processing of #{filename} failed: #{e}\n" +
+ "Moved to #{newname}"
+ store_in_maildir(OUTBOX, mail_error)
+ rescue Exception => e2
+ STDERR.puts "Error when processing #{filename}: #{e}"
+ STDERR.puts "During error handling we encountered a new problem: #{e2}"
+ end
end
end