Index: mailhandler_attachments/mailhandler_attachments.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_attachments/mailhandler_attachments.info
diff -N mailhandler_attachments/mailhandler_attachments.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mailhandler_attachments/mailhandler_attachments.info	29 Sep 2010 23:28:36 -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: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_attachments/mailhandler_attachments.module
diff -N mailhandler_attachments/mailhandler_attachments.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mailhandler_attachments/mailhandler_attachments.module	29 Sep 2010 23:28:36 -0000
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * @file
+ * Integrates with the Mailhandler module to save attachments from e-mails.
+ */
+
+/**
+ * Alter function for mailhandler_node_processor_targets().
+ *
+ * Adds targets from FeedNodeProcessor because MailhandlerNodeProcessor extends
+ * FeedsProcessor instead of FeedsNodeProcessor.
+ *
+ * @see http://drupal.org/node/921774
+ */
+function mailhandler_attachments_mailhandler_node_processor_targets_alter(&$targets, $content_type) {
+  drupal_alter('feeds_node_processor_targets', $targets, $content_type);
+}
+
+/**
+ * Alter function for mailhandler_parser_sources().
+ *
+ * Adds a new mapping source, Attachments, that will contain the e-mail 
+ * attachments.
+ */
+function mailhandler_attachments_mailhandler_parser_sources_alter(&$sources) {
+  $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);
+}
