This can be very usefully for someone.
I was trying to extract pdf and encountered two major problems:
1. Server had Content-Transfer-Encoding: 7bit while perl MIME::Parser works with 8bit
2. When reading from file to array perl 5.8.8 drooped last 30 lines. So editing file was impossible.
This is solution:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Net::POP3;
use Mail::Header;
use MIME::Parser;
my $pop = Net::POP3->new("poczta",Timeout=>30)# conect to mail
or die "Can't connect to host: $!\n";
my $messages = $pop->login("demerzeli"=>"mail")
or die "Can't log in: ",$pop->message,"\n";
my $last =$pop->last();
$messages += 0;
print "inbox has $messages messages";
my $array = $pop->get(1); # write first mail to varible
$pop->quit(); #close conection
my $i=0;
foreach (@{$array}){ #varible is a pointer to array so we need to read it
if($_ =~m/Content-Transfer-Encoding: 7bit/){ # MIME parser need 8bit so we will change it
print "found";
@{$array}[$i]="Content-Transfer-Encoding: 8bit\n";
print $_;
}
$i++;
}
open (OUTPUT, ">pop3.msgb");
print OUTPUT "$_" foreach (@{$array});
close(OUTPUT);
my $outputdir = "/root/testmail/";
my $parser = new MIME::Parser;
$parser->output_dir($outputdir);
open (MAILIN, "<pop3.msgb");
my $entity = $parser->read(\*MAILIN); # extracting mail text and attachments
close MAILIN;