I have been playing around with the mailhandler module as I wanted to be able to post pictures to my site via email (my wife is expecting so it seemed like a good idea for the big day!)

I couldn't seem to find a ready made solution so I've been working on my own version by modifying mailhandler so it interacts with image. What happens now is that if I post a picture with my email / phone then the post is turned in to an image node, with thumbnails etc

You can see an example post that I've generated here.

I'm fairly new to Drupal so was wondering if I've used the "right" approach...

I have modified mailhandler itself so that during mailhandler_retrieve it looks for a jpeg, and if it finds one it extracts it.

During mailhandler_node_submit if a jpeg is there then it calls a processing routine just before doing node_validate.

The bit I'm not sure about, but is getting the job done, is that processing. The routine constructs an object, as if the file had come from an upload. It then calls image_validate but instead of passing a string it hands over the object. That seems to keep all the other modules happy, and they parse the object as a valid upload.

As a result image happily constructs thumbnails. If the processing routine was successful then the node type is left as an image. If validation failed the type is reverted to whatever was originally assumed. Control passes back to mailhandler_node_submit and the job is done.

I really struggled with the upload bit, and couldn't find a write up about it. I'm not sure if the solution I've adopted is 'correct' or a convenient work around!

I don't mind too much as I'm happily posting from my phone/email, but I'm curious about the whole mechanism. I'm also wondering if I could attach other files via email and how I persuade them to attach in the same way image is doing. That's a project for another day...

Anyhow, thought I would post to see if anyone comments!

PS - I love Drupal and completely hooked! But my wife is complaining she has become a Drupal widow! Does anyone else suffer from this?!?!

________

Just five more minutes...

www.stuartandnicola.com

Comments

jasonwhat’s picture

This is a great and you should repost it here, http://drupal.org/project/mailhandler to get attention of the project owners and possibly submit a patch for the module.

Also, there is a module that posts from mobile phones or email attachments but I can't remember the name right now. I think it stopped being maintained after Drupal 4.5.

The folks at Development Seed were working on something similar and they may have finished their module, I'm not sure. You could try their contact form to get more info, http://drupal.org/user/4736/contact

jasonwhat’s picture

sangamreddi’s picture

Thanks for the nice work.
Can you provide the code, i am interested in testing it. I have similar plans.

Sunny                      
www.gleez.com | www.sandeepone.com

Stuart Greenfield’s picture

I've put the code in a zip on my site. Download from here.

There's a text file in the zip that tries to explain what I've done!

________

Just five more minutes...

www.stuartandnicola.com

sangamreddi’s picture

Thank you. I'll test it in next fewdays. Keepup the nice work.

Sunny                      
www.gleez.com | www.sandeepone.com