1 |
dpavlin |
58 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
# re-bounce message from mbox |
4 |
|
|
# |
5 |
|
|
# Dobrica Pavlinusic <dpavlin@rot13.org> |
6 |
|
|
|
7 |
|
|
use strict; |
8 |
|
|
|
9 |
|
|
use Email::Folder::Mbox; |
10 |
|
|
use Email::MIME::Attachment::Stripper; |
11 |
|
|
use Email::Send; |
12 |
|
|
use Data::Dumper; |
13 |
|
|
|
14 |
|
|
my $mbox = shift || die "usage: $0 mbox_with_bounces\n"; |
15 |
|
|
my $smtp_server = shift || 'dmz1.pliva.hr'; |
16 |
|
|
|
17 |
|
|
my $box = new Email::Folder::Mbox($mbox) || die "can't open folder $mbox: $!"; |
18 |
|
|
|
19 |
|
|
print "working on $mbox\n"; |
20 |
|
|
|
21 |
|
|
while ( my $mail = $box->next_message ) { |
22 |
|
|
|
23 |
|
|
my $stripper = Email::MIME::Attachment::Stripper->new($mail); |
24 |
|
|
|
25 |
|
|
if (! $stripper) { |
26 |
|
|
warn "WARNING: can't parse message:\n$mail\n"; |
27 |
|
|
next; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
foreach my $att ( $stripper->attachments ) { |
31 |
|
|
if ($att->{content_type} eq 'message/rfc822') { |
32 |
|
|
#print $att->{payload},"\n", '-' x 76, "\n"; |
33 |
|
|
send SMTP => $att->{payload}, $smtp_server; |
34 |
|
|
} |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
} |