All pastes #16936 Raw Edit

Anonymous

public text v1 · immutable
#16936 ·published 2005-07-05 13:14 UTC
rendered paste body
#!/usr/bin/perl 
use strict;
use warnings;
use POSIX qw(strftime);
use IO::File;
use Mail::Message;
use Email::Valid;
use Mail::Message::Attachment::Stripper;

my $mail = Mail::Message->read(\*STDIN);
my $stripper = Mail::Message::Attachment::Stripper->new($mail);

my $now_string = strftime "%F_%H:%M:%S", localtime;

my Mail::Message $msg = $stripper->message;
my @attachments       = $stripper->attachments;

#my $msg_file = new IO::File "/home/pr/tmp/att/" . $now_string . "--message", "w" or die "Can not create msg file!";
#print $msg_file $msg;

# looks through attachments, we are interested in text/plain attachs named Kontakty
  foreach my $a( @attachments) {
  next if ($a->{content_type} !~ /text\/plain/i && $a->{filename} !~ /kontakty/i) ;
    # uloznime attachmenty do history storage
     my $f = new IO::File "/home/pr/tmp/att/" . $now_string . "--" . $a->{filename}, "w" or die "Can not create history file!";
     print $f $a->{payload};

# extract mail adresses
$_ = $a->{payload};
tr/A-Z/a-z/;

# splitnem stream for Email::Valid and verify
@_ = split();
foreach ($_) {
  $_ = Email::Valid->address($_);
};

# save into final file
my $senders_file = new IO::File "/home/pr/tmp/att/.rzp_senders.txt", "w" or die "Can not create rzp_senders file!";

# make mail notication about update
print "Pokus o aktualizaci @ $now_string temito udaji:\n\n---\n";
foreach (@_) {
  print $senders_file "$_\n";
  print "$_\n";
};
print "---\n";
};