Hi, as stated in #1281530: Keep id of message parts from $structure I've been working on a simple image parser.

Actually it does that:
- find img tags
- save images to local dirs
- rewrite img tag src attribute to saved local image (or remove the tag)
- make avaiable the images to field mapping

Some tought:
» security: I've tried to clean out the image content (from eg embed php code) by forcing a scale with gd. It should be done throught the core image api.
» in mailhandler/plugins/MailhandlerCommandsFiles.class.php line 34

- unset($message['mimeparts']);
+ //unset($message['mimeparts']);

or the mail parts won't be available to the html command.
A nice thing could be integrate or let attachments command skip images to avoid have them both in attachments and images fields

I wait for any usage reviews!

Thanks,
Luca

CommentFileSizeAuthor
MailhandlerCommandsHtmlImages.zip3.12 KBmuka

Comments

muka’s picture

Issue summary: View changes

corrected html tags which mess the body

danepowell’s picture

You've obviously put in a lot of work on this, thanks for contributing. It does need some work like you said. On the Mailhandler side, I see that there are some configuration options but no way to set them. I've grappled in the past with how to let command parsers store configuration data. The problem is that Feeds doesn't really seem to allow for this- I've touched on this issue in the Feeds queue at #1145116: Feeds Multi Parser but perhaps I need to open a dedicated issue or focus a little more on it.

danepowell’s picture

I've committed a fix that might help you - see #1314788: Allow commands parsers to store config in db

danepowell’s picture

Title: Html Images Command » HTML images command plugin
danepowell’s picture

Title: HTML images command plugin » Handling of inline content (e.g. images)
Component: Code » Mailhandler

I wasn't too familiar with the standards for embedding images in emails, so I did some reading... it seems from http://www.ietf.org/rfc/rfc2111.txt that just about any file type can be attached to an email and referenced inline using the 'cid' tag. So I don't think we should limit this to images.

I think the best way to handle this is to grab the attachments, and if an attachment has a matching Content-ID, do a preg_replace on the email body to replace cid:[content-id] with the new link to the file.

danepowell’s picture

Status: Needs work » Postponed

I have this almost working in a local development branch. The only problem is that at the point where Mailhandler hands off the relevant mapping sources (message body and attachments) to feeds, it can only know the temporary URIs of attached files. I think Feeds needs to take responsibility at that point and update temporary URIs in the node body before saving the node. See #1475596: Rewrite file URIs in node body on message import

muka’s picture

Hi,
I would like to help in test and (where I can) with code, can you post a dev snapshot somewhere to work on it ?
Thanks, Luca

danepowell’s picture

I pushed the development branch to drupal.org: 7.x-2.x-1314128 . Any help is appreciated, but like I said the holdup is in Feeds now.

muka’s picture

For sure if Feeds could handle this would be much better.

But couldn't be handled with a content filter or on hook_node_view() ?
Eg. adding a specific prefix like

  //<img src='[mh:1234]'> 
  //if( /* node has feed parent */ )
  preg_match_all( '~(\[mh\:([0-9]*)\])~ium', ..., $res );
  // retirieve managed file ids in content
  $tokens = $res[1];
  $fids = $res[2]; 

  $paths = db_select("select path ...", array(":fids", $fids))->fetchCol();
  preg_replace($tokens, $paths, $content);

danepowell’s picture

Title: Handling of inline content (e.g. images) » Support for inline content (e.g. images)
Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Postponed » Patch (to be ported)
rsbecker’s picture

Is there any progress on this? When inline images arrive via mailhandler from Thunderbird here is what the tag in the node looks like:

<img align="right" alt="" height="420" hspace="5" src="part1.03020604.01080806@dcappeals.com" title="" vspace="5" width="350" />

The image is downloaded and saved in directory according to parameters set by filefield_path, and it is available on the node as a cck image field. So Drupal knows where the file is. How can we get the inline image tag changed from the mimepart to the path?

Yuri’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

For D7 I have applied the modifications in patch mentioned in #9 https://drupal.org/node/1475596
But the D7 dev version of Mailhandler still does not show the correct URLS for images in the body fields.
Did any of you actually got this working in D7?

Yuri’s picture

Ok forgot to flush cash ..and now it works! Inline images (as well as attached images) are showing.
However, the patch mentioned in #9 https://drupal.org/files/feeds-1475596-2.patch needs to be updated because the line number has changed (around line 121).
Thanks!

coreycondardo’s picture

I've patched Feeds and Installed the dev version of mail handler however when I email with an inline image the img src in the full HTML wysiwyg body field is public://mailhandler_temp/imagename.png. If I change it to sites/default/files/mailhandler_temp/drupal.png it works, but with public:// it doesn't work. Any idea what I have to do to get that working?

Thanks!
Corey

danepowell’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev

As long as the status on this is 'to be ported', please keep the version at 6.x

jetwodru’s picture

Title: Support for inline content (e.g. images) » Inline Content (eg. Images) & Attachment supported ?
Version: 6.x-2.x-dev » 7.x-2.9

Hi,
I tested the 7.x.29, found that inline images as well as attachment are still not supported, is this in progress ? thanks.

danepowell’s picture

Title: Inline Content (eg. Images) & Attachment supported ? » Support for inline content (e.g. images)
Version: 7.x-2.9 » 6.x-2.x-dev

Attachments have always been supported. Inline images are supported in 7.x-2.9, but you'll need the patch in #9. Please open a separate issue if you're having problems- let's keep this thread open only for development of a 6.x patch.

danepowell’s picture

Issue summary: View changes

corrected issues ref

leducdubleuet’s picture

Issue summary: View changes

Inline images are still not working for D7 even with version 7.x.29 and the patch for Feeds in Comment #9.
So I have opened another issue for D7 with a patch : https://drupal.org/node/2228401