has anybody been successful in getting the image module to work with the mailhandler module?

being able to post images with some caption through email to the blog would be a fantastic enhancement to the site.

Comments

kika’s picture

I successfully implemented imagehandler.module for Drupal 4.0. Since mailhandler and image module has changed a lot since, you probably need retune the function. It currently supports only JPG.

<?php

function imagehandler_mailhandler($node, $stream, $msg_number, $mailbox) {
  $image = mailhandler_get_part($stream, $msg_number, "IMAGE/JPEG");  
  if ($image) {
    $node->type = "image";
    $node->format = "jpg";
    $node->body = mailhandler_get_part($stream, $msg_number, "TEXT/PLAIN");  
    $node->image_id = md5(rand());  
    $node->image_name =  $node->title.".jpg";
    $node->thumb_name = _image_thumbname($node);

    $dest = fopen(_image_tempname($node),"w");                                       
    fputs($dest,$image,strlen($image));                                                                       
    fclose($dest); 

    watchdog("message", "Retreived image $node->image_name from incoming mail");

  }
  return $node;   
}

?>
moshe weitzman’s picture

that is cool. what other tricks have you developed and not yet shared?

Anonymous’s picture

Where do you put this?
I tried making it a module, but I don't see how to get it to pull from the mailhandler module. When I put the function in mailhandler, it broke.

Thanks!

moshe weitzman’s picture

this function belongs in an imagehandler.module file. See the Developer's Handbook pages on module development.