[Postfixbuch-users] perl script für bounce per hand aus der warteschleife
Robert Schetterer
robert at schetterer.org
Do Mai 4 14:48:21 CEST 2006
Hi @ll,
ich moechte mails per hand aus der warteschleife an den sender bouncen
hat jemand von euch ein geeignetes script?
Ich hab was gefunden, funzt aber net richtig weil die queue id wohl
nicht richtig ausgelesen wird ( perl kram )
vieleicht kann das mal jemand von euch debuggen oder hat schon sein
script oder einen anderen Ansatz, ich bin leider kein perl held
http://archives.neohapsis.com/archives/postfix/2002-12/3008.html
#!/usr/bin/perl -w
# Author: Jason Eric Pierce
# Date: 2002-12-23
my $postfixspool = '/var/spool/postfix';
my $sendmail = '/usr/sbin/sendmail';
my $postcat = '/usr/sbin/postcat';
my $postsuper = '/usr/sbin/postsuper';
my $cat = '/bin/cat';
my $queueid = shift || die "usage: bouncemsg queueid\n";
my $msg = '';
my $recipient = '';
my $body = '';
my $error = '';
my $errorfile = "$postfixspool/defer/" . substr($queueid, 0, 1) . '/' .
substr($queueid, 1, 1) . "/$queueid";
my $messagefile = "$postfixspool/deferred/" . substr($queueid, 0, 1) . '/'
. substr($queueid, 1, 1) . "/$queueid";
if (-e $messagefile) {
$msg = `$postcat $messagefile`;
}
$msg || die "Problem opening file $messagefile for queueid
$queueid.\nStopped";
if (-e $errorfile) {
$error = `$cat $errorfile`;
}
if ($msg =~ /\n\*\*\* MESSAGE CONTENTS.+\n((?:.*\n)+)\*\*\* HEADER
EXTRACTED.+\nreturn_receipt.+\nerrors_to: (.+)/) {
print "Sending bounce message...\n";
$body = $1;
$recipient = $2;
$body =~ s/\n\.\n/\n\.\.\n/g;
$error =~ s/\n\.\n/\n\.\.\n/g;
open(SENDMAIL, "|$sendmail -f \\<\\> $recipient");
print SENDMAIL << "MESSAGETEXT_BOUNCEMSG_END";
From: MAILER-DAEMON (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
To: $recipient
Message undeliverable.
Reason:
$error
Original message follows:
$body
MESSAGETEXT_BOUNCEMSG_END
print(SENDMAIL ".\n");
close(SENDMAIL);
print "Sent bounce message.\nDeleting message from queue...\n";
$delmsg = `$postsuper -d $queueid 2>&1`;
print "Output of postsuper -d $queueid:\n$delmsg\n";
if ($delmsg =~ /postsuper: $queueid: removed\npostsuper: Deleted: 1
message/) {
print "Deleted message from queue.\nAll done.\n\n";
}
else {
print "Problem deleting from the queue.\n";
}
}
else {
print "Could not parse contents of message for $queueid";
}
------------
MfG Robert
Mehr Informationen über die Mailingliste Postfixbuch-users