Hello,
when I run this script: (it's an excerpt)
--------------------------------------begin test1.pl-------------------------
#!/usr/bin/perl
use strict;
# use warnings;
use Getopt::Std;
use Net::POP3;
use Term::ANSIColor qw(:constants);
binmode(STDOUT, ":utf8");
my %params = ();
getopts('s:l:p:', \%params);
my $server = $params{s};
my $login = $params{l};
my $password = $params{p};
unless (defined $password) {
my $trk_loaded = 0;
eval {
require Term::ReadKey;
import Term::ReadKey;
$trk_loaded = 1;
};
print RED . ON_WHITE, 'Password: ', RESET;
ReadMode('noecho') if $trk_loaded; # input echo off
chomp($password = $trk_loaded ? ReadLine(0) : <STDIN>);
ReadMode('restore') if $trk_loaded; # input echo on
print "\n";
}
my $pop;
eval { $pop = Net::POP3->new($server) } ;
defined $pop or print <<MSG and exit;
Couldn't connect to the POP3 server $server.
MSG
my $nmails;
eval { $nmails = $pop->login($login, $password) };
defined $nmails or print <<MSG and exit;
I could connect to the server but could not log in.
MSG
##
unless ($nmails > 0) {
print "No mail for $login. Bye\n";
exit;
}
my @allmsg = ();
my @taille = ();
my @delete = ();
# my @frompour = ();
# my @subjectpour = ();
my %messages = %{$pop->list};
while ( my ($msgnum, $size) = each %messages) {
push @allmsg, $msgnum;
}
print "The number of messages for $login is: ", $#allmsg + 1, "\n";
# Get the headers.
my ($from, $to, $subject);
foreach my $msgnum (sort {$a <=> $b} @allmsg) {
my $top = $pop->top($msgnum);
next if not defined $top;
my @lines = @$top;
# Extract relevant headers.
($from) = grep /^From:/i, @lines;
($to) = grep /^To:/i, @lines;
($subject) = grep /^Subject:/i, @lines;
}
print "$subject" if defined $subject;
--------------------------------------end test1.pl------------------------
if the subject of a message contains accents, they do not display correctly.
How can we solve the problem ?
For example I get a message with the subject:
Subject: L'été ça sera bientôt
./test1.pl -s pop.server.fr -l user
The number of messages for user is: 1
Subject: =?iso-8859-1?Q?L'=E9t=E9_=E7a_sera_bient?= =?iso-8859-1?Q?=F4t?=
tia.
--
Gerard
_________________________________________
*****************************************
* Created with "mutt 1.7.2-1" *
* under Debian Linux STRETCH 9.0 *
* Registered Linux User #388243 *
* https://Linuxcounter.net *
*****************************************
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/