rev 1938 - trunk/Email-Store/lib/Email/Store

[prev] [thread] [next] [lurker] [Date index for 2005/02/22]

From: simon
Subject: rev 1938 - trunk/Email-Store/lib/Email/Store
Date: 08:04 on 22 Feb 2005
Author: simon
Date: 2005-02-22 08:04:52 +0000 (Tue, 22 Feb 2005)
New Revision: 1938

Modified:
   trunk/Email-Store/lib/Email/Store/Mail.pm
Log:
Add a UTF8 body method


Modified: trunk/Email-Store/lib/Email/Store/Mail.pm
===================================================================
--- trunk/Email-Store/lib/Email/Store/Mail.pm	2005-02-22 08:01:52 UTC (rev 1937)
+++ trunk/Email-Store/lib/Email/Store/Mail.pm	2005-02-22 08:04:52 UTC (rev 1938)
@@ -12,6 +12,7 @@
 Email::Store::Mail->columns(Primary => qw/message_id/);
 Email::Store::Mail->columns(TEMP => qw/simple/);
 use Email::Simple;
+use Email::MIME;
 use Email::MessageID;
 
 sub _simple { Email::Simple->new(shift); } # RFC2822 -> Email::Simple
@@ -54,6 +55,23 @@
     return $fake;
 }
 
+
+sub body {
+    my $mail = shift;
+    my $mime = Email::MIME->new($mail->message);
+
+    my $body = $mime->body;
+    my $charset = $mime->{ct}->{attributes}{charset};
+    if ($charset and $charset !~ /utf-?8/i) {
+        eval {
+            require Encode;
+            $body = Encode::decode($charset, $body);
+            Encode::_utf8_off($body);
+        };
+    }
+    $body;
+}
+
 1;
 
 =head1 NAME

Generated at 10:00 on 22 Feb 2005 by mariachi 0.52