From d3ae61a22bd97c6cbe9d7010591b2222b19bfde4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 18 Oct 2010 18:27:33 +0200 Subject: [PATCH] Text vor E-Mailversand von Perls internen Encoding nach UTF-8 encoden, sofern notwendig --- SL/Mailer.pm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/SL/Mailer.pm b/SL/Mailer.pm index 9ef0b085b..17981331d 100644 --- a/SL/Mailer.pm +++ b/SL/Mailer.pm @@ -31,6 +31,7 @@ package Mailer; use Email::Address; +use Encode; use SL::Common; use SL::MIME; @@ -103,14 +104,14 @@ sub send { $num_sent++; my $boundary = time() . "-$$-${num_sent}"; $boundary = "LxOffice-$self->{version}-$boundary"; - my $domain = $self->{from}; + my $domain = $self->recode($self->{from}); $domain =~ s/(.*?\@|>)//g; my $msgid = "$boundary\@$domain"; my $form = $main::form; my $myconfig = \%main::myconfig; - my $email = $myconfig->{email}; + my $email = $self->recode($myconfig->{email}); $email =~ s/[^\w\.\-\+=@]//ig; my %temp_form = ( %{ $form }, 'myconfig_email' => $email ); @@ -127,12 +128,15 @@ sub send { foreach my $item (qw(to cc bcc)) { next unless ($self->{$item}); + $self->{$item} = $self->recode($self->{$item}); $self->{$item} =~ s/\</{$item} =~ s/\$<\$/{$item} =~ s/\>/>/g; $self->{$item} =~ s/\$>\$/>/g; } + $self->{from} = $self->recode($self->{from}); + my $headers = ''; foreach my $item (qw(from to cc bcc)) { next unless ($self->{$item}); @@ -151,7 +155,7 @@ sub send { } } - $headers .= sprintf("Subject: %s\n", $self->mime_quote_text($self->{subject}, 60)); + $headers .= sprintf("Subject: %s\n", $self->mime_quote_text($self->recode($self->{subject}), 60)); print OUT qq|${headers}Message-ID: <$msgid> X-Mailer: Lx-Office $self->{version} @@ -166,7 +170,7 @@ MIME-Version: 1.0 print OUT qq|--${boundary} Content-Type: $self->{contenttype}; charset="$self->{charset}" -$self->{message} +| . $self->recode($self->{message}) . qq| |; } @@ -223,7 +227,7 @@ Content-Disposition: attachment; filename="$filename"\n\n|; } else { print OUT qq|Content-Type: $self->{contenttype}; charset="$self->{charset}" -$self->{message} +| . $self->recode($self->{message}) . qq| |; } @@ -262,5 +266,12 @@ sub encode_base64 ($;$) { return $res; } +sub recode { + my $self = shift; + my $text = shift; + + return $::locale->is_utf8 ? Encode::encode('utf-8-strict', $text) : $text; +} + 1; -- 2.20.1