From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v2 1/8] utils: return perl string from decode_rfc1522
Date: Thu, 17 Nov 2022 16:06:04 +0100 [thread overview]
Message-ID: <20221117150611.253644-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20221117150611.253644-1-s.ivanov@proxmox.com>
decode_rfc1522 is a more robust version of decode_mimewords (in
scalar context) - adapt it to return a perlstring, under the
assumption that data is utf-8 encoded (holds true for ascii and
smtputf8 mails)
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
src/PMG/Utils.pm | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index cef232b..77abde4 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -1088,6 +1088,7 @@ sub decode_to_html {
return $res;
}
+# assume enc contains utf-8 and mime-encoded data a perl-string (with wide characters)
sub decode_rfc1522 {
my ($enc) = @_;
@@ -1100,7 +1101,7 @@ sub decode_rfc1522 {
my ($d, $cs) = @$r;
if ($d) {
if ($cs) {
- $res .= decode($cs, $d);
+ $res .= encode('UTF-8', decode($cs, $d));
} else {
$res .= $d;
}
@@ -1108,8 +1109,11 @@ sub decode_rfc1522 {
}
};
- $res = $enc if $@;
-
+ if ($@) {
+ $res = $enc;
+ } else {
+ $res = decode('UTF-8', $res);
+ }
return $res;
}
--
2.30.2
next prev parent reply other threads:[~2022-11-17 15:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 15:06 [pmg-devel] [PATCH pmg-api v2 0/8] ruledb - improve experience for non-ascii tests and mails Stoiko Ivanov
2022-11-17 15:06 ` Stoiko Ivanov [this message]
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 2/8] ruledb: properly substitute prox_vars in headers Stoiko Ivanov
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 3/8] fix #2541 ruledb: encode relevant values as utf-8 in database Stoiko Ivanov
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 4/8] ruledb: encode e-mail addresses for syslog Stoiko Ivanov
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 5/8] partially fix #2465: handle smtputf8 addresses in the rule-system Stoiko Ivanov
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 6/8] quarantine: handle utf8 data Stoiko Ivanov
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 7/8] pmgqm: handle smtputf8 data Stoiko Ivanov
2022-11-17 15:06 ` [pmg-devel] [PATCH pmg-api v2 8/8] statistics: handle utf8 data Stoiko Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221117150611.253644-2-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.