Can someone please help me get mailsave to work with Drupal 6.13 and 6.14? Not sure what version of Drupal the incompatibility started, but I think it's important to keep up with the core. Any ideas?
Thanks!

Comments

zeropaper’s picture

well the problems come from the ".info" file. It seems to use an old syntax.
Instead of:
dependencies = mailsave imagefield
it should be:

dependencies[] = mailsave
dependencies[] = imagefield

I hope it helps.

jjjames’s picture

Thanks I'll give that a try!

zeropaper’s picture

After a few tries... I successfully fixed mailsave_to_imagefield...
This is how the ".module" file looks by me.

/**
 * 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
    return;
  }

  // Query to find a CCK Imagefield attached to the node type
  $node_type = content_types($node->type);
  $field = FALSE;
  $multiple = FALSE;
  if (is_array($node_type['fields'])) {
    foreach ($node_type['fields'] as $field_name => $field) {
      if ($field['type'] == 'filefield' && $field['widget']['module'] == 'imagefield') {
        $multiple = $field['multiple'];
        break;
      }
    }
  }

  if (!$field) {
    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 => $attachement) {
    // Ensure we are using an object
    
    $validators = array_merge(
      filefield_widget_upload_validators($field),
      imagefield_widget_upload_validators($field)
    );
    
    // Where do we store the files?
    $files_path = filefield_widget_file_path($field, $user);
    
    // Not sure what's the best here file_copy, file_move, file_save_data... at least, it works
    $data = file_save_data(file_get_contents($attachement['filepath']), $attachement['filename']);
    if (!$data) {
      return;
    }
    // Create the file object
    $image = field_file_save_file($data, $validators, $files_path, $user);

    // Add the image info to the imagefield array
    $node->{$field_name}[] = $image;
    
    // Lets remove the CCK image we found from attachments
    unset($node->mailsave_attachments[$key]);
    
    // if this isn't a multiple image CCK imagefield then let's exit
    if (!$multiple) return;
      
  }
}

On a side note... the (actual version) of mailsave_to_imagefield uses a completely outdated version of the filefield/imagefield API... and I think (as the imagefield is now more or less) only a CCK formatter, that the mailsave_to_imagefield module should be dropped in favour of a mailsave_to_filefield and be somewhat extended to add a few admin settings.

Have fun!

kakajoe’s picture

hi
so this is work for imagefield ?? where i must to put your code ??
thanks

zeropaper’s picture

Well,
you can completely overwrite the ".module" file content (but don't forget to keep a backup)...

By the way, I tried it on a second installation (an other drupal site) but something didn't worked this time.. I'm still investigating...

pacome’s picture

subscribing !

alberto56’s picture

Status: Active » Closed (duplicate)