I am having an issue with email attachments saving as 0 bytes when being fetched. I setup mailhandler with the quick-setup module, changed the mail box to IMAP with my settings. Changed the Feeds Node processor to my content type then added the mapping attachments to a file field using the image widget. The node is created with the correct mappings but the image_#.jpeg is 0 bytes. Manual image upload works correctly.

I am currently using the latest dev sources for Feeds and CTools. Any help would be greatly appreciated.

CommentFileSizeAuthor
#8 mailhandler-1597384-8.patch961 bytesdanepowell

Comments

danepowell’s picture

Title: Email Image Attachment 0 bytes » Image attachments have 0 bytes
Category: support » bug
Priority: Normal » Major

Sorry about that. Come to think of it, I think I've since this bug before as well. I'll try to investigate but I don't have much time at the moment- if you are able to dig deeper and even contribute a patch, I'd appreciate it (and this will get solved faster! =D )

xvx’s picture

From syslog it is dropping "No Data!!" I also tested on the test mbox modules/mailhandler/tests/attachment1_mbox and the README_#.txt file is also showing up 0 bytes. So I'm guessing it has something to do with the get_parts function in /modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php. I'll continue to investigate to see if there is an issue here.

Can someone that has attachments working please let me know what version of PHP you are running, my current version is PHP 5.2.17. I just want to rule out any issues with php_imap

danepowell’s picture

I haven't had a chance to look at either issue in depth, but is it possible that this is a duplicate of #1482966: Attachments failing in multisite setups?

xvx’s picture

It looks like that patch is for 7.x, but it still looks something like this was committed to the 6.x 2.5 branch.

if ($attachment->filename !== 'unnamed_attachment') {
$file = file_save_data($attachment->data, file_directory_temp() . '/' . mb_decode_mimeheader($attachment->filename));
$message['attachments'][] = new FeedsEnclosure($file, $attachment->filemime);

It's writing the file, with the proper filename, to /tmp/ but without data in it.

rsutaria’s picture

I'm having the same problem. MailHandler is correctly creating a node, but the attachment which has been mapped to an Image field is showing 0 bytes.

My PHP version is 5.2.17 and I'm on a shared hosted server (bluehost).

The MailHandler v I'm using is 7.x-2.5

P.S.: I'm also getting the "No Data!!" error in the logs. I also just applied this patch given here:
http://drupal.org/node/1555792#comment-5953776

But that has not helped. Any ideas?

naurisr’s picture

In 7.x-2.5 I fixed this by replacing

        $sub_parts = $this->get_parts($stream, $msg_number, $max_depth, $depth + 1,
          $sub_structure, $prefix . ($index + 1)); 

with

        $sub_parts = $this->get_parts($stream, $msg_number, $max_depth, $depth + 1,
          $sub_structure, ($index + 1)); 

in MailhandlerPhpImapRetrieve.class.php

rsutaria’s picture

thank you thank you so much!! :)

The fix you've suggested totally works! Thanks Naurisr!

danepowell’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new961 bytes

Let's see if this patch based on #6 passes testing. In the future, please keep in mind that patches are preferred to manual examples (like #6), since patches will automatically get tested. Thanks.

Status: Needs review » Needs work

The last submitted patch, mailhandler-1597384-8.patch, failed testing.

danepowell’s picture

Hrm, it looks like all Mailhandler tests are failing at the moment. I'll try to fix that tomorrow and then re-queue #8 for testing.

danepowell’s picture

Status: Needs work » Needs review

#8: mailhandler-1597384-8.patch queued for re-testing.

danepowell’s picture

Title: Image attachments have 0 bytes » Parts not retrieved correctly
Status: Needs review » Needs work

Marked #164278: imap_fetchbody() error -- no data? as dupe. This same bug I think results in a 'No data!!' error in the dblog.

danepowell’s picture

Status: Needs work » Fixed

Should be fixed in 6.x-2.x and 7.x-2.x:
http://drupalcode.org/project/mailhandler.git/commit/be81392
http://drupalcode.org/project/mailhandler.git/commit/6e71f71

As I suspected, the patch in #8 was a bit of a hack and would probably cause problems with more complex multipart messages. So I solved it in a slightly different way.

danepowell’s picture

I did some more investigation and it turns out this is a regression caused by #1555792: Single-part media emails ignored

danepowell’s picture

Title: Parts not retrieved correctly » File attachments have zero bytes

Renamed issue title to better reflect the effects of the issue.

Makku01’s picture

I am using 6.x .
I just tried the latest dev and the attachments are there but they are doubled, every attachment of the original mail is now attached 2 times to the new node.

also there is a problem with the textfield, it stops at the first unusual character (here:'ü')

switched back to 6.x 2.5 and the texfield was processed fine, but attachments not :-(

jurgenhaas’s picture

I have had the same problem and can confirm that the commit in http://drupalcode.org/project/mailhandler.git/commit/6e71f71 has resolved it in my 7.x-2.5 installation.

snehi’s picture

Thanks for making this patch available.

bkenro’s picture

For my D6 site, http://drupalcode.org/project/mailhandler.git/commit/be81392 works fine.
Thanks for the patch!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kevin.klika’s picture

Running current version of mailhandler and experienced this issue. Cleanly applied #8 and everything works now.

rosso69’s picture

Working with MailHandler 7.x-2.9+20-dev my files are all 0 bytes.
None of the patches above worked for me.

Using a clean Drupal 7.26 version with lates feeds (dev)

Try to put files in a public directory and upload_filesize is bigger then the attachted file.

When i manually create a node and attach the file it work. When i mail small files, it also works.
Bigger files are not imported. I cannot see any relation between upload_max_filesize and the filesize of the attachments.

rosso69’s picture

I noticed that it has to do with character decoding. Plain ascii file with a couple of "a" in it work file, even large files.
How can i import a file without looking at coding?

replicaobscura’s picture

Issue summary: View changes

I seem to be having this same issue today on the latest release of the module. The patch in #8 is no longer relevant with the current code as far as I can see.

On one mailbox (Gmail) it works fine, and on another (Rackspace hosted mail) I get 0-byte attachments with the same files. Is anyone else still experiencing this?