Mailhandler 1.x had a dependent module, Mailsave, which did a lot of heavy lifting in terms of extracting e-mail attachments and adding them to various file-holding containers (Image, Upload, ImageField, etc.). With Mailhandler's move to Feeds, this becomes a lot easier, and it seems like it should be part of the main module itself.

So, I've created a submodule that provides this ability:

  • It exposes all possible fields on a node by adding the targets FeedsNodeProcessor would normally add*,
  • It adds a new source, Attachments, which contains all the non-body attachments (i.e. real files like images and PDFs and such), and
  • It processes the "mimeparts" part of the message object to convert the data it sees there into real file and adds those files back to the message object as FeedEnclosure objects

The end result is that all attachments are added to a FileField (or ImageField) target during import.

Attached is a patch to provide a new submodule, mailhandler_attachments, which depends on mailhandler_node. I believe the functionality it provides could be worked into Mailhandler itself without too much trouble, but I didn't want to commit to that without seeing the results from #141211: CCK custom content type fields and scheduling using mailhandler, which seems to indicate a massive rewrite of the Processor and Parser classes is imminent.

Mailhandler Attachments requires the patches to the following two issues to function:

(* This is a necessary step as MailhandlerNodeProcessor extends FeedsProcessor instead of FeedsNodeProcessor, and should be removed should the changes in #141211: CCK custom content type fields and scheduling using mailhandler be implemented)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mark Trapp’s picture

I made a mistake in my issue references; the correct issue regarding the changes to the Parser and Processor is #921774: Support CCK creation using Feeds and Mailhandler, not #141211: CCK custom content type fields and scheduling using mailhandler.

mfb’s picture

tracking

Ian Ward’s picture

Mark, I agree this should go into mailhandler_node once #921774: Support CCK creation using Feeds and Mailhandler is sorted out. Also, the only module that I know of that uses the mailhandler 'postsave' hook is mailsave. It looks like this would completely replace the need to use mailsave, and may eliminate the need for the 'postsave' hook (which I do not yet see how to implement without further patching FeedsNodeProcessor).

PhilW50’s picture

Has this been tested? And does it work? I am having trouble saving attachments (they are not there) with Mailhandler and mailsave and would like to try this patch. Install instructions? Drupal 6.19 and mailhandler 6.x-1.11. Is this only for MH 2.0?

Mark Trapp’s picture

@Ian:

I think the Mailhandler hooks are an annoying red herring; every use-case I've tried implementing with the hooks took several hours trying to figure out what information Mailhandler knows about, only to find out later the right way to do it in Feeds. I've implemented about a half-dozen custom Mailhandler submodules doing all sorts of things and none of them have needed the hooks. It seems like all the Mailhandler hooks should be removed in favor of Feeds hooks.

We were discussing on #924016: Port Mailsave to Mailhandler 2.x that there might still be a need for Mailsave; Mailsave 1.x also provides cleaning filters for various wireless carriers that are not addressed by my patch. Feeds makes cleaning really easy too, but it likely doesn't make sense to keep cleaning filters for each specific mail provider in Mailhandler core.

@PhilW50:

I've tested it over the past few days, and the code has been deployed on a production server: I'd welcome more testing though.

It's a patch, but the patch merely adds a new module to the Mailhandler directory. It does require Mailhandler 2.x, which is currently unstable. Both this patch and Mailhandler 2.x will likely change soon, so unless you absolutely need this functionality and are willing to keep up-to-date with active development, it probably doesn't make sense to use for anything other than testing just yet.

geek-merlin’s picture

@mark:
>It seems like all the Mailhandler hooks should be removed in favor of Feeds hooks.
definitely +1

@mark, @ian:
you might also want to look at #943344: Transformers

Mark Trapp’s picture

FileSize
2.29 KB

Rerolled the patch to add the Mailhandler Attachments module based on the changes in #921774: Support CCK creation using Feeds and Mailhandler.

Requirements:

Ian Ward’s picture

One thought - is there any reason this needs to depend on mailhandler_node? Mapping files to nodes is probably the most common case, but I suppose you could map mails to users and attachments could be mapped to user picture, just as an example.

Mark Trapp’s picture

@Ian: no, there isn't; I've rerolled the patch to depend on Mailhandler instead of Mailhandler Node. I've also attached a patch that adds the functionality directly to MailhandlerParser now that the refactor is complete.

Requirements for both patches:

Ian Ward’s picture

Status: Needs review » Fixed

Awesome. I committed the second one - directly into MailhandlerParser.

Ian Ward’s picture

Status: Fixed » Active

Hmm, but this should stay open as a pointer to #926616: FeedsEnclosure::getFile() should allow files to exist in the temp directory until that one is committed.

Mark Trapp’s picture

Sweet. Yeah: I think it won't be committed until it's been ported to Drupal 7; I haven't had time to get into Drupal 7 yet. Hopefully this weekend.

Mark Trapp’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.