rev 1495 - in trunk/mariachi: . lib/Mariachi

[prev] [thread] [next] [lurker] [Date index for 2004/04/02]

From: richardc
Subject: rev 1495 - in trunk/mariachi: . lib/Mariachi
Date: 10:05 on 02 Apr 2004
Author: richardc
Date: 2004-04-02 10:05:42 +0100 (Fri, 02 Apr 2004)
New Revision: 1495

Modified:
   trunk/mariachi/Build.PL
   trunk/mariachi/lib/Mariachi/Message.pm
Log:
use Email::MIME to strip attachments

Modified: trunk/mariachi/Build.PL
===================================================================
--- trunk/mariachi/Build.PL	2004-03-23 00:20:25 UTC (rev 1494)
+++ trunk/mariachi/Build.PL	2004-04-02 09:05:42 UTC (rev 1495)
@@ -15,9 +15,10 @@
         'AppConfig'       => '1.55',
         'Class::Accessor' => 0,
         'Date::Parse'     => 0,
+        'Email::Find'     => 0,
         'Email::Folder'   => '0.5',
+        'Email::MIME'     => 0,
         'Email::Thread'   => 0,
-        'Email::Find'     => 0,
         'File::Basename'  => 0,
         'File::Copy'      => 0,
         'File::Find::Rule' => 0,

Modified: trunk/mariachi/lib/Mariachi/Message.pm
===================================================================
--- trunk/mariachi/lib/Mariachi/Message.pm	2004-03-23 00:20:25 UTC (rev 1494)
+++ trunk/mariachi/lib/Mariachi/Message.pm	2004-04-02 09:05:42 UTC (rev 1495)
@@ -1,6 +1,6 @@
 use strict;
 package Mariachi::Message;
-use Email::Simple;
+use Email::MIME;
 use Digest::MD5 qw(md5_hex);
 use Date::Parse qw(str2time);
 use Text::Original ();
@@ -30,14 +30,26 @@
     my $source = shift;
 
     my $self = $class->SUPER::new;
-    my $mail = Email::Simple->new($source) or return;
+    my $mail = Email::MIME->new($source) or return;
 
     $self->linked({});
     $self->_header({});
     $self->header_set( $_, $mail->header($_) ) for
       qw( message-id from subject date references in-reply-to );
-    $self->body( $mail->body );
 
+    # gather up the text/plain chunks for now - later we may want to
+    # save the non-html attachments and present them in some way
+    my $body;
+    for ($mail->parts) {
+        if ($_->content_type =~ m{^text/plain\b}) {
+            $body .= $_->body;
+        }
+        else {
+            $body .= "[ detached attachment " . $_->filename . " ]\n";
+        }
+    }
+    $self->body( $body );
+
     $self->header_set('message-id', $self->_make_fake_id)
       unless $self->header('message-id');
 

Generated at 13:57 on 01 Jul 2004 by mariachi 0.52