Satish@Stag has asked for the wisdom of the Perl Monks concerning the following question:
use Carp; use Email::MIME; use File::Basename; use Net::POP3; use File::Find; my $server = '192.168.100.254'; my $receiveruname = 'admin'; my $password = 'admin'; my $attachment_dir = 'D:\\Attachments\\'; my $pop = Net::POP3->new($server); croak "Couldn't connect to the server.\n\n" unless $pop; my $num_messages = $pop->login( $receiveruname, $password ); croak "Connection trouble network password user ..." unless defined $num_messages; for my $i ( 1 .. $num_messages ) { my $aref = $pop->get($i); my $em = Email::MIME->new( join '', @$aref ); for ( my @parts = $em->parts ) { print $_->content_type, "\n"; next unless $_->content_type =~ m(^application/octet-s +tream)i; my $filename = basename( $_->filename || '' ); my $basefilename = $filename || 'UNNAMED'; my $filesize = -s "$filename" ; print "\nFilesize of $filename = $filesize \n" +; if ( $filename eq "null" ) { $pop->delete($i); # To avoid down +loading file "null" of 0KB } else { open my $fh, ">", "$attachment_dir/$fi +lename" or croak $!; binmode $fh; print $fh $_->body; $pop->delete($i); } } } $pop->quit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to find the size of an attachment in a POP3 server
by rhesa (Vicar) on Sep 05, 2007 at 11:34 UTC | |
by bart (Canon) on Sep 05, 2007 at 12:14 UTC | |
by Satish@Stag (Novice) on Sep 07, 2007 at 07:46 UTC |