From a60ea76fe88a596c5e321809c8f79431dedaa9db Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Sun, 8 Feb 2026 15:06:05 +0100 Subject: [PATCH] Convert Usevote to UTF-8. Signed-off-by: Thomas Hochstein --- UVreadmail.pm | 11 +++++++++++ UVsendmail.pm | 4 +++- UVtemplate.pm | 12 +++++++----- templates/mailheader | 2 +- uvbounce.pl | 2 ++ uvcfv.pl | 2 ++ uvcount.pl | 2 ++ uvvote.pl | 3 +++ 8 files changed, 31 insertions(+), 7 deletions(-) diff --git a/UVreadmail.pm b/UVreadmail.pm index 0a1f98f..1ac4865 100644 --- a/UVreadmail.pm +++ b/UVreadmail.pm @@ -3,9 +3,12 @@ package UVreadmail; +use utf8; +use open qw(:std :encoding(UTF-8)); use strict; use UVconfig; use UVmessage; +use Encode qw(decode :fallbacks); use MIME::QuotedPrint; use MIME::Base64; use MIME::Parser; @@ -200,6 +203,7 @@ sub process { # extract address and name my $from = $head->get('From') || ''; + utf8::decode($from); # fix double encoding if ($from =~ /\s*([^<]\S+\@\S+[^>]) \((.+)\)/) { ($voter_addr, $voter_name) = ($1, $2); @@ -240,6 +244,13 @@ sub process { $body = $entity->stringify_body; } + # body: charset conversion to Perl internal representation + my $ct = $head->get('Content-Type') || ''; + if ($ct =~ /^text\/plain;.*charset=\"?([-a-zA-Z0-9]+)\"?/i) { + my $charset = $1; + $body = decode($charset, $body, FB_CROAK); + } + my $h_date = $head->get('Date') || ''; chomp $h_date; diff --git a/UVsendmail.pm b/UVsendmail.pm index a773733..e306a21 100644 --- a/UVsendmail.pm +++ b/UVsendmail.pm @@ -3,6 +3,8 @@ package UVsendmail; +use utf8; +use open qw(:std :utf8); use strict; use UVconfig; use UVtemplate; @@ -239,7 +241,7 @@ sub mimeencode { $word =~ s/\n//g; my $encword; if ($word =~ /[\x7F-\xFF]/) { - $encword = MIME::Words::encode_mimeword($word, 'Q', 'ISO-8859-1'); + $encword = MIME::Words::encode_mimeword($word, 'Q', 'UTF-8'); } elsif (length($word) > 75) { $encword = MIME::Words::encode_mimeword($word, 'Q', 'us-ascii'); } else { diff --git a/UVtemplate.pm b/UVtemplate.pm index 35f28db..c592987 100644 --- a/UVtemplate.pm +++ b/UVtemplate.pm @@ -44,6 +44,8 @@ einer Liste immer 60 Zeichen lang ist um ansehnliche Tabellen auszugeben. #---------------------------------------------------------------------- +use utf8; +use open qw(:std :utf8); use strict; use vars qw( $VERSION $functions @dirs); use UVconfig; @@ -370,10 +372,10 @@ sub _parse_rules{ sub _strip_chars{ my $line = $_[0] || return; - # führenden whitespace entfernen + # führenden whitespace entfernen $$line =~ s/^\s+//; - # kommentare bis zum nächsten Zeilenumbruch entfernen + # kommentare bis zum nächsten Zeilenumbruch entfernen $$line =~ s/^#.*$//m; } @@ -618,8 +620,8 @@ sub _parse_comment{ my $count = 1; while($string && $count) { - $string =~ s/^[^\[\]\\]+//s; # alles außer Klammern und Backslash wegwerfen - $string =~ s/^\\.//; # alles gesperrte löschen + $string =~ s/^[^\[\]\\]+//s; # alles außer Klammern und Backslash wegwerfen + $string =~ s/^\\.//; # alles gesperrte löschen $count++ if $string =~ s/^\[//; $count-- if $string =~ s/^\]//; @@ -775,7 +777,7 @@ Sonderzeichen oder Leerzeichen uebergeben werden muessen diese gequotet werden. Dazu kann ' also auch " verwendet werden. Die Funktionen geben im Allgemeinen einen String zurueck. Im Rahmen -von Listen können auch Arrays uebergeben werden. +von Listen können auch Arrays uebergeben werden. Die erste Funktion duerfte ueblicherweise 'value' sein. Sie gibt den des angegeben Schluessel zurueck, der dann von den folgenden Funktionen diff --git a/templates/mailheader b/templates/mailheader index 93746ba..684abbc 100644 --- a/templates/mailheader +++ b/templates/mailheader @@ -12,5 +12,5 @@ Message-ID: [$msgid] Date: [$date] X-Automated-Message: generated by [$usevote-version] MIME-Version: 1.0 -Content-Type: text/plain; charset\=iso-8859-1 +Content-Type: text/plain; charset\=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/uvbounce.pl b/uvbounce.pl index 0a7352f..44dfc1a 100755 --- a/uvbounce.pl +++ b/uvbounce.pl @@ -21,6 +21,8 @@ # written in C). Not all functions of Usevote/UseVoteGer 3.x are implemented! ############################################################################### +use utf8; +use open qw(:std :utf8); use strict; use Getopt::Long; use FindBin qw($Bin); diff --git a/uvcfv.pl b/uvcfv.pl index 5f09080..ee12b54 100755 --- a/uvcfv.pl +++ b/uvcfv.pl @@ -20,6 +20,8 @@ # written in C). Not all functions of Usevote/UseVoteGer 3.x are implemented! ############################################################################### +use utf8; +use open qw(:std :utf8); use strict; use Getopt::Long; use Digest::MD5 qw(md5_hex); diff --git a/uvcount.pl b/uvcount.pl index 4af9a8f..0e14c3e 100755 --- a/uvcount.pl +++ b/uvcount.pl @@ -20,6 +20,8 @@ # written in C). Not all functions of Usevote/UseVoteGer 3.x are implemented! ############################################################################### +use utf8; +use open qw(:std :encoding(UTF-8)); use strict; use Getopt::Long; use Digest::MD5 qw(md5_hex); diff --git a/uvvote.pl b/uvvote.pl index 7f23a42..c629b20 100755 --- a/uvvote.pl +++ b/uvvote.pl @@ -21,6 +21,8 @@ # written in C). Not all functions of Usevote/UseVoteGer 3.x are implemented! ############################################################################### +use utf8; +use open qw(:std :utf8); use strict; use Getopt::Long; use Text::Wrap qw(wrap $columns); @@ -330,6 +332,7 @@ sub process_vote { $voter_name = $3; $voter_name =~ s/^\s+//; # strip leading spaces $voter_name =~ s/\s+$//; # strip trailing spaces + utf8::decode($voter_name); # fix double encoding } if ($voter_name) {