Skip to content

Instantly share code, notes, and snippets.

@iamcal
Created April 20, 2018 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamcal/c4da8844f73314a2458d9637e89fc2b3 to your computer and use it in GitHub Desktop.
Save iamcal/c4da8844f73314a2458d9637e89fc2b3 to your computer and use it in GitHub Desktop.
Process bounces in an IAMP inbox
use Mail::IMAPClient;
use Data::Dumper;
my $imap = Mail::IMAPClient->new(
Server => 'mail.mxes.net',
User => 'ACCOUNT',
Password => 'PASSWORD',
Ssl => 0,
Uid => 1,
);
my $missing = 0;
$imap->select('______BOUNCE') or die "Can't select folder";
my @msgs = $imap->messages or die "Could not messages: $@\n";
for my $uid(@msgs){
my $string = $imap->body_string($uid);
if ($string =~ m!The following message to <(.*?)> was undeliverable!){
print "$1\n";
$imap->delete_message($uid);
next;
}
if ($string =~ m!Final-Recipient: rfc822;\s*(\S+)!i){
print "$1\n";
$imap->delete_message($uid);
next;
}
if ($string =~ m!Feedback-Type: abuse!i){
if ($string =~ m!Original-Rcpt-To:\s*(\S+@\S+)!i){
print "ABUSE: $1\n";
$imap->delete_message($uid);
next;
}
}
my $env = $imap->get_envelope($uid);
if ($env->{subject} =~ m!complaint about message!i){
if ($string =~ m!X-HmXmrOriginalRecipient:\s*(\S+@\S+)!i){
print "ABUSE: $1\n";
$imap->delete_message($uid);
next;
}
}
$missing++;
#last;
}
$imap->expunge('______BOUNCE');
print "no address found for $missing messages\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment