]> git.donarmstrong.com Git - debbugs.git/commitdiff
[project @ 2005-03-16 20:23:20 by cjwatson]
authorcjwatson <>
Thu, 17 Mar 2005 04:23:21 +0000 (20:23 -0800)
committercjwatson <>
Thu, 17 Mar 2005 04:23:21 +0000 (20:23 -0800)
Add Debbugs::MIME::de_rfc1522() function, modified slightly from a patch by
Don Armstrong <don@debian.org>. Decodes RFC1522-style mail header encoding
to UTF-8.

Requires libunicode-maputf8-perl Debian package.

Debbugs/MIME.pm
debian/control

index eeaeb7faa843c77b7c327eac0af64c2b6b715820..fac17f5ab387c1c28e01699f097b425474f759e6 100644 (file)
@@ -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?= <don@donarmstrong.com>')
+
+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;
index b3d321b841a2eb2e67c8c4a3d6d1ed431b2c7a73..18db7b572a5071ad250eebf4f5970c4593aac77f 100644 (file)
@@ -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