Created
November 15, 2010 19:22
-
-
Save waffle2k/700811 to your computer and use it in GitHub Desktop.
gen_bounce.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# This is my "fuck you fb.com" script. It will generate a bounce | |
# message to the FB user if they try to email me. | |
use strict; | |
use lib('/home/popcorn/lib'); | |
use Email::Simple; | |
use MIME::Lite; | |
use Data::Dumper; | |
use Email::Date::Format qw( email_date ); | |
my $email_address = 'PUTYOUREMAILHERE@YOURDOMAIN'; | |
my $domain = $1 if $email_address =~ /\@(.*)/; | |
my $arrival_date = email_date( time ); | |
#################################################################### | |
my $email_txt = do { local $/; <>; }; # sluuuuurp! | |
my $email = Email::Simple->new($email_txt); | |
my $from = $email->header("From"); | |
# Generate a bounce email to that address, from postmaster | |
my $msg = MIME::Lite->new( | |
From => 'MAILER-DAEMON@' . $domain, | |
To => $from, | |
Subject => 'Undelivered Mail Returned to Sender', | |
Type => 'multipart/report' | |
); | |
$msg->attr( "content-type.report-type" => 'delivery-status' ); | |
# Generate the first part: the notification stuff | |
#################################################################### | |
my $part1 = MIME::Lite->new( | |
Type => 'text/plain', | |
Data => qq{ | |
This is the mail system at $domain. | |
I'm sorry to have to inform you that your message could not | |
be delivered to one or more recipients. It's attached below. | |
For further assistance, please send mail to postmaster. | |
If you do so, please include this problem report. You can | |
delete your own text from the attached returned message. | |
The mail system | |
}, | |
); | |
# Strip all of the fields out | |
for my $field ( @{ $part1->fields() } ){ | |
my $f = $field->[0]; | |
#print "Deleting: $f\n"; | |
$part1->delete( $f ); | |
} | |
$part1->attr( "content-description" => "Notification" ); | |
$part1->attr( "content-type" => 'text/plain' ); | |
$msg->attach( $part1 ); | |
# Generate the second part: | |
################################################################# | |
my $part2 = MIME::Lite->new( | |
Type => 'message/delivery-status', | |
Data => qq{ | |
Reproting-MTA: dns; $domain | |
Arrival-Date: $arrival_date | |
Final-Recipient: rfc822; $email_address | |
Action: failed | |
Status 5.7.1 | |
Diagnostic-Code: smtp; 571 5.7.1 <$email_address>: Recipient chooses not to receive email from fb.com | |
}, | |
); | |
# Strip all of the fields out | |
for my $field ( @{ $part2->fields() } ){ | |
my $f = $field->[0]; | |
#print "Deleting: $f\n"; | |
$part1->delete( $f ); | |
} | |
$part2->attr( "content-description" => "Delivery report" ); | |
$part2->attr( "content-type" => 'message/delivery-status' ); | |
$msg->attach( $part2 ); | |
# Generate the third part | |
################################################################## | |
my $part3 = MIME::Lite->new( | |
Type => 'message/rfc822', | |
Data => $email_txt, | |
); | |
# Strip all of the fields out | |
for my $field ( @{ $part3->fields() } ){ | |
my $f = $field->[0]; | |
#print "Deleting: $f\n"; | |
$part3->delete( $f ); | |
} | |
$part3->attr( "content-description" => "Undelivered Message" ); | |
$part3->attr( "content-type" => 'message/rfc822' ); | |
$msg->attach( $part3 ); | |
#print $msg->as_string . "\n"; | |
$msg->send; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment