From 1f0a68d97d70104d2c10ea6fbbb686faf5222f46 Mon Sep 17 00:00:00 2001 From: cjwatson <> Date: Wed, 16 Mar 2005 20:23:21 -0800 Subject: [PATCH] [project @ 2005-03-16 20:23:20 by cjwatson] Add Debbugs::MIME::de_rfc1522() function, modified slightly from a patch by Don Armstrong . Decodes RFC1522-style mail header encoding to UTF-8. Requires libunicode-maputf8-perl Debian package. --- Debbugs/MIME.pm | 50 +++++++++++++++++++++++++++++++++++++++++++------ debian/control | 2 +- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Debbugs/MIME.pm b/Debbugs/MIME.pm index eeaeb7fa..fac17f5a 100644 --- a/Debbugs/MIME.pm +++ b/Debbugs/MIME.pm @@ -2,18 +2,22 @@ package Debbugs::MIME; use strict; -use File::Path; -use MIME::Parser; -use Exporter (); -use vars qw($VERSION @ISA @EXPORT_OK); +use base qw(Exporter); +use vars qw($VERSION @EXPORT_OK); BEGIN { $VERSION = 1.00; - @ISA = qw(Exporter); - @EXPORT_OK = qw(parse); + @EXPORT_OK = qw(parse de_rfc1522); } +use File::Path; +use MIME::Parser; + +# for de_rfc1522 +use MIME::WordDecoder qw(); +use Unicode::MapUTF8 qw(to_utf8 utf8_supported_charset); + sub getmailbody ($); sub getmailbody ($) { @@ -96,4 +100,38 @@ sub parse ($) return { header => [@headerlines], body => [@bodylines]}; } +# Bug #61342 et al. + +=head2 de_rfc1522 + + de_rfc1522('=?iso-8859-1?Q?D=F6n_Armstr=F3ng?= ') + +Turn RFC-1522 names into the UTF-8 equivalent. + +=cut + +BEGIN { + # Set up the default RFC1522 decoder, which turns all charsets that + # are supported into the appropriate UTF-8 charset. + MIME::WordDecoder->default(new MIME::WordDecoder( + ['*' => sub { + my ($data, $charset) = @_; + $charset =~ s/^(UTF)\-(\d+)/$1$2/i; + return $data unless utf8_supported_charset($charset); + return to_utf8({ + -string => $data, + -charset => $charset, + }); + }])); +} + +sub de_rfc1522 ($) +{ + my ($string) = @_; + + # unmime calls the default MIME::WordDecoder handler set up at + # initialization time. + return MIME::WordDecoder::unmime($string); +} + 1; diff --git a/debian/control b/debian/control index b3d321b8..18db7b57 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Build-Depends-Indep: debhelper Package: debbugs Architecture: all -Depends: perl5 | perl, exim | mail-transport-agent, libmailtools-perl, ed, libmime-perl, libio-stringy-perl, libmldbm-perl +Depends: perl5 | perl, exim | mail-transport-agent, libmailtools-perl, ed, libmime-perl, libio-stringy-perl, libmldbm-perl, libunicode-maputf8-perl Recommends: httpd, links | lynx Suggests: spamassassin Description: The bug tracking system based on the active Debian BTS -- 2.39.5