Mailhander is up and working. I can email in nodes and they get added fine with no errors. Ideally I would like a cck imagefield item with the node. No luck I get the error below. I have tried emailing from different clients and accounts but the same error persists.

I applied the update patch http://drupal.org/node/315381 with this module but get errors before I get to that part of the upload.

Invalid argument supplied for foreach() in /public_html/sites/all/modules/mailsave/mailsave.module on line 307.

I also applied this patch which did not help. http://drupal.org/node/304720

Any ideas?

Comments

bryanb229’s picture

Same thing is happening to me.

Investigating further later this afternoon.

bryanb229’s picture

Any luck with this?

I am at a total loss, but still working on figuring out what is going on with the mimeparts.

acb’s picture

ditto here. No problem on another site running 6.x-1.8w mailsave 6.x-1.3

Odd.

acb’s picture

(double-post; sorry)

alexgreyhead’s picture

Subscribing (or at least, attempting to! :)

robert.oconnell’s picture

subscribe

robert.oconnell’s picture

Hmm... It looks like a recent change to mailhandler had broken the mimepart handling: http://drupal.org/node/718344.
Using the latest development release of mailhandler allowed me to get past this current error.
Now I am getting a different problem
Fatal error: Call to undefined function imagefield_check_directory() in /home/theoco1/public_html/sites/all/modules/mailsave/mailsave_to_imagefield/mailsave_to_imagefield.module on line 105

hedinfoto’s picture

Still broken :-( Using FTP & image field import on my iPhone. That solution is too complicated for our PR people who this is really for. You would figure that this would be corner stone of submitting images to drupal 6 from phones.

acb’s picture

in mailsave_to_imagefield.module,

I have found that changing

      foreach (module_implements('file_insert') as $module) {
        $function = $module .'_file_insert';
        $function((object) $file);
      }

to

      foreach (module_implements('file_insert') as $module) {
        $function = $module .'_file_insert';
//CHANGED
        $function($file);
      }

helped matters, and I can upload images with this as my mailsave to image_Field code (note additional function at bottom, too)

<?php
// $Id: mailsave_to_imagefield.module,v 1.3 2007/11/27 22:03:44 stuartgreenfield Exp $
/**
* This module interacts with mailsave
* It creates CCK imagefield items from attached images
* This module contributed by Moonshine (drupal.org/user/133705)
*/

/**
* Implementation of hook_help().
*/
function mailsave_to_imagefield_help($section) {
  switch ($section) {
    case 'admin/help#mailsave_to_imagefield':
      $output .= '<p>'. t('This module is a plug-in for mailsave. If an incoming e-mail contains image attachments then they will be converted to CCK imagefield items (inside the first CCK imagefield field listed on the node). If there are no imagefields in the node then then no processing occurs.');
      return $output;
  }
}

/**
* Implementation of hook_perm
*/
function mailsave_to_imagefield_perm() {
  return array(
    'convert to imagefield',
   );
}

/**
* Implementation of hook_mailsave().
* Try to convert images to imagefields
*/
function mailsave_to_imagefield_mailsave($node, $result, $i, $header, $mailbox) {

  // See if conversion to image is needed
  _mailsave_to_imagefield_attempt_image($node);

  // Return the (possibly updated!) updated node
  return $node;
}

/**
* Attempt to find images in the node and convert them to CCK imagefileds if they exit
*/
function _mailsave_to_imagefield_attempt_image(&$node) {

  // If $node->mailsave_attachments is empty or imagefield not installed just return
  if (!$node->mailsave_attachments || !module_exists('imagefield')) {
    return;
  }

  // If user doesn't have image conversion permissions just return
  if (!user_access('convert to imagefield')) {
    // mailsave modules don't need to flag that the user doesn't have attach permission
    // it just ignores the process silently
    //watchdog('mailsave', t('User doesn\'t have permission for Mailsave To Imagefield'));
    return;
  }

  // Query to find a CCK Imagefield attached to the node type
  $cck_info = content_types($node->type);
  $cck_imagefield = FALSE;
  $cck_multiple = FALSE;
  $cck_image_extensions = '';

  if (is_array($cck_info['fields'])) {
    foreach ($cck_info['fields'] as $cck_field => $field_info) {
//CHANGED
      if ($field_info['widget']['type'] == 'imagefield_widget') {
        $cck_imagefield = $cck_field;
        $cck_multiple = $field_info['multiple'];
        $cck_image_extensions = $field_info['widget']['file_extensions'];
        break;
      }
    }
  }

  if (!$cck_imagefield) {
    watchdog('mailsave', t('No CCK Imagefields found for content type %type.', array ('%type' => $node->type)));
    return;
  }

  // Begin processing attachments
  foreach ($node->mailsave_attachments as $key => $file) {

    // Check to see if it's a image type that the imagefield will take
    // Note - current official release of imagefield doesn't include cck_image_extensions, this only appears in
    // branch 5--2 onwards. So we check that the extension list is empty, or the extension is otherwise allowed
    /// but we also check the mime type is image/. This might cause problems for some webmail type clients that
    // report image uploads as octet streams, but will have to do for now!

    if ( (trim($cck_image_extensions) == '' || strpos($cck_image_extensions, _file_ext($file['filename'])) !== FALSE ) && strpos(strtolower($file['filemime']), 'image/') === 0 )  {

      // Let's scale the image per the imagefield max settings
      if ($field_info['widget']['max_resolution']) {
        $file = _imagefield_scale_image($file, $field_info['widget']['max_resolution']);
      }

      // If there are tokenized as part of imagefield 2.x let's use them
      if (function_exists('token_replace')) {
        global $user;
        $widget_image_path = token_replace($field_info['widget']['file_path'], 'user', $user);
      }
      else {
        $widget_image_path = $field_info['widget']['file_path'];
      }

      // Let's create the directory path if it hasn't been created already
      $directory = file_create_path($widget_image_path);
      file_check_directory($directory, FILE_CREATE_DIRECTORY);

      $destination = file_destination(file_create_path($widget_image_path .'/'. $file['filename']), FILE_EXISTS_RENAME);
      file_move($file['filepath'], $destination);

      // Build the array for the image found
      $file['list'] = 0;
      $file['data'] = array('description' => '', 'alt' => $file['filename'], 'title' => '');
      $file['uid'] = $node->uid;
      $file['filepath'] = $destination;
      $file['status'] = 1;
      $file['timestamp'] = time();

      drupal_write_record('files', $file);

      foreach (module_implements('file_insert') as $module) {
        $function = $module .'_file_insert';
//CHANGED
       $function($file);
      }

      // Add the image info to the imagefield array
      $node->{$cck_imagefield}[] = $file;

      // Lets remove the CCK image we found from attachments
      // We will leave the temp file though, as imagefield will need it
      unset($node->mailsave_attachments[$key]);

      // if this isn't a multiple image CCK imagefield then let's exit
      if (!$cck_multiple) return;
    }
  }
}

/*
* Find the file extension for a given attachement
*/
function _file_ext($filename) {
  $filename = strtolower($filename) ;
  $parts = explode('.', $filename);
  $ext = $parts[(sizeof($parts) - 1)];
  return $ext;
}


//ADDED BELOW

function _imagefield_scale_image($file, $resolution = 0) {
  $info = image_get_info($file['filepath']);
  if ($info) {
    list($width, $height) = explode('x', $resolution);
    if ($width && $height) {
      $result = image_scale($file['filepath'], $file['filepath'], $width, $height);
      if ($result) {
        $file['filesize'] = filesize($file['filepath']);
        drupal_set_message(t('The image %filename was resized to fit within the maximum allowed resolution of %resolution pixels', array('%resolution' => $resolution, '%filename' => $file['filename'])));
      }
    }
  }
  return $file;
}
hedinfoto’s picture

This new patch works Great! Thank you!