Index: plugins/MailhandlerParser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/plugins/Attic/MailhandlerParser.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 MailhandlerParser.inc
--- plugins/MailhandlerParser.inc	21 Oct 2010 13:00:03 -0000	1.1.2.2
+++ plugins/MailhandlerParser.inc	22 Oct 2010 04:50:30 -0000
@@ -18,6 +18,7 @@ class MailhandlerParser extends FeedsPar
       // Populate batch.
       if (!empty($messages)) {
         foreach ($messages as &$message) {
+          $this->parseAttachments($message);
           $this->parseExtensions($message);
           // Outcome is to set $message->uid
           // @TODO this will get overwritten by the FeedsNodeProcessor
@@ -39,6 +40,22 @@ class MailhandlerParser extends FeedsPar
     }
   }
 
+  /**
+   * Parse attachments from message mimeparts.
+   */
+  public function parseAttachments(&$message) {
+    $message['attachments'] = array();
+
+    foreach ($message['mimeparts'] as $attachment) {
+      // 'unnamed_attachment' files are not really attachments, but mimeparts like HTML or Plain Text.
+      // We only want to save real attachments, like images and files.
+      if ($attachment->filename !== 'unnamed_attachment') {
+        $file = file_save_data($attachment->data, file_directory_temp() . '/' . $attachment->filename);
+        $message['attachments'][] = new FeedsEnclosure($file, $attachment->filemime);
+      }
+    }
+  }
+
   /*
    * Set known sources and parse additional sources from body.
    */
@@ -47,11 +64,12 @@ class MailhandlerParser extends FeedsPar
     $parts = (array) $message['header'];
     foreach ($parts as $key => $value) {
       // Some keys are already taken, so do not overwrite them.
-      if (!in_array($key, array('header', 'origbody', 'mimeparts', 'mailbox'))) {
+      if (!in_array($key, array('header', 'origbody', 'mimeparts', 'mailbox', 'attachments'))) {
         $message[$key] = $value;
       }
     }
   }
+
   /*
    * This defines sources which user's can select to map values to.
    */
@@ -62,7 +80,7 @@ class MailhandlerParser extends FeedsPar
       'fromaddress', 'from', 'reply_toaddress', 'reply_to', 'senderaddress', 
       'sender', 'Recent', 'Unseen', 'Flagged', 'Answered', 'Deleted', 'Draft', 
       'Msgno', 'MailDate', 'Size', 'udate',
-      'origbody', 'mimeparts',
+      'origbody', 'mimeparts', 'attachments',
     );
     foreach ($parts as $part) {
       $sources[$part] = array(
