Bad display of accents in Subject

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		*
*****************************************
0
g
3/18/2017 6:19:21 PM
perl.beginners 29225 articles. 3 followers. Follow

1 Replies
46 Views

Similar Articles

[PageSpeed] 31

On Wed, Mar 22, 2017 at 08:34:32AM -0700, $Bill wrote:
> Date: Wed, 22 Mar 2017 08:34:32 -0700
> From: $Bill <dbecoll@gmail.com>
> To: G�rard ROBIN <g.robin3@free.fr>
> Subject: Re: Bad display of accents in Subject
> User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101
>  Thunderbird/45.8.0
> 
> My response didn't show up in my usenet reader, so just in case:
> 
> First reply:
> 
> 
> use MIME::QuotedPrint;
> my $subject =
>   q{=?iso-8859-1?Q?L'=E9t=E9_=E7a_sera_bient?= =?iso-8859-1?Q?=F4t?=};
> my $result = '';
> while ($subject =~ s/=\?iso-8859-1\?Q\?(.*?)\?=/$1/s) {
>     my $sub = $1;
>     $sub = MIME::QuotedPrint::decode_qp($sub);
>     $result .= $sub;
> }
> # $result should have what you started with
> 
> 
> Second reply (simpler/better solution):
> 
> use Encode::MIME::Header;
> my $subject =
>   q{=?iso-8859-1?Q?L'=E9t=E9_=E7a_sera_bient?= =?iso-8859-1?Q?=F4t?=};
> my $result = decode ('MIME-Header', $subject);

Thank you to those who answered me.

Bill
The second solution works like a charm however I added:
use Encode qw(is_utf8 encode decode);
and qq{$subject} to interpolate $subject.

I am stuck with the first solution ...

Thank you again.

-- 
Gerard
_________________________________________
*****************************************
*  Created with "mutt 1.7.2-1"		*
*  under Debian Linux STRETCH  9.0	*
*  Registered Linux User #388243	*
*  https://Linuxcounter.net		*
*****************************************
0
g
3/23/2017 10:57:25 PM
Reply: