Index: mailhandler_attachments/mailhandler_attachments.info
===================================================================
RCS file: mailhandler_attachments.info
diff -N mailhandler_attachments.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mailhandler_attachments/mailhandler_attachments.info	21 Oct 2010 00:50:37 -0000
@@ -0,0 +1,5 @@
+name = "Mailhandler Attachments"
+description = "Processes attachments from Mailhandler"
+core = "6.x"
+package = "Mailhandler"
+dependencies[] = "mailhandler_node"
Index: mailhandler_attachments/mailhandler_attachments.module
===================================================================
RCS file: mailhandler_attachments.module
diff -N mailhandler_attachments.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mailhandler_attachments/mailhandler_attachments.module	21 Oct 2010 00:50:37 -0000
@@ -0,0 +1,61 @@
+<?php
+
+/**
+ * @file
+ * Integrates with the Mailhandler module to save attachments from e-mails.
+ */
+
+/**
+ * Implements hook_feeds_parser_sources_alter().
+ *
+ * Adds a new mapping source, Attachments, that will contain the e-mail 
+ * attachments.
+ */
+function mailhandler_attachments_feeds_parser_sources_alter(&$sources, $content_type) {
+  $sources['attachments'] = array(
+    'title' => t('Attachments'),
+    'description' => t('IMAP message attachments'),
+  );
+}
+
+/**
+ * Implements hook_feeds_after_parse().
+ */
+function mailhandler_attachments_feeds_after_parse(FeedsImporter $importer, FeedsSource $source) {
+  $messages = array();
+
+  while ($item = $source->batch->shiftItem()) {
+    // Since importers are general-use, only act if we find Mailhandler's
+    // signature mimeparts.
+    if ($item['mimeparts']) {
+
+      $item['attachments'] = array();
+
+      foreach ($item['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);
+          $item['attachments'][] = new FeedsEnclosure($file, $attachment->filemime);
+        }
+      }
+    }
+
+    $messages[] = $item;
+  }
+
+  $source->batch->setItems($messages);
+}
