PHP Classes

Wrong base64 decoding

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Wrong base64 decoding  >  (Un) Subscribe thread alerts  
Subject:Wrong base64 decoding
Summary:File attachments corrupted if not multipart email
Messages:6
Author:Vincenzo
Date:2007-07-18 12:56:08
Update:2007-07-30 23:37:32
 

  1. Wrong base64 decoding   Reply   Report abuse  
Picture of Vincenzo Vincenzo - 2007-07-18 12:56:08
Hi,
i use your library to get mail attachments files.

It worked very well for all mail parsed, but one day my customer sent me a mail that is NOT multipart. There is only one part, that is the file attached.

Your lib apparently decoded fine the file but i found error in subsequent file manipulation: the file is corrupted.

This only happens when there is only one part in the mail, no matter if client is a webmail interface or outlook.

This is a print_r of the decoded message:

[CODE]
[Headers] => Array
(
[return-path:] => <[email protected]>
[x-original-to:] => [email protected]
[delivered-to:] => [email protected]
[received:] => Array
(
[0] => from vsmtp2.tin.it (vsmtp2.tin.it [212.216.176.222]) by speakageline.info (Postfix) with ESMTP id E17F599430B for <[email protected]>; Wed, 18 Jul 2007 09:45:16 +0200 (CEST)
[1] => from pswm16.cp.tin.it (192.168.70.64) by vsmtp2.tin.it (7.3.122) id 467668F6002CB31B for [email protected]; Wed, 18 Jul 2007 09:52:27 +0200
)

[message-id:] => <[email protected]>
[date:] => Wed, 18 Jul 2007 08:52:25 +0100 (GMT+01:00)
[from:] => "[email protected]" <[email protected]>
[reply-to:] => "[email protected]" <[email protected]>
[to:] => [email protected]
[subject:] => da webmail a [email protected]
[mime-version:] => 1.0
[content-type:] => APPLICATION/OCTET-STREAM; name="Parata in partenza.3gp"
[content-transfer-encoding:] => base64
[x-originating-ip:] => 88.36.92.165
[content-disposition:] => attachment; filename="Parata in partenza.3gp"; size=426158
)

[Parts] => Array
(
)

[FileName] => Parata in partenza.3gp
[FileDisposition] => attachment
[BodyFile] => /var/tmp/GF26490/1
[BodyPart] => 1
[BodyLength] => 426152
[/CODE]

Notice that the lib saved a file with size of 426152 bytes, but headers in mail show a size of 426158 bytes.

I copied/pasted the base64 encoded text in this service http://www.motobit.com/util/base64-decoder-encoder.asp and i got a file sized 426158 bytes, not corrupted.

I tried to debug into the library but is too complicated for me (i suspect that the bug is in some substring calculation for the base64_decode func parameter).

If you need the original mail file i will send you (i have 4 different mails with same problem).

Anyway, this lib is powerful as is simple to use: very good work!!!

NB: there is only one piece not decoded, the filename when is quoted-printable:

[CODE]
[FileName] => =?UTF-8?Q?Vale_c=27=C3=A8=2E3gp?=
[FileDisposition] => attachment
[BodyFile] => /var/tmp/GF29779/1
[BodyPart] => 1
[BodyLength] => 247733
[/CODE]

  2. Re: Wrong base64 decoding   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-18 19:26:50 - In reply to message 1 from Vincenzo
The problem may be caused with magic quotes. It is hard to tell if without a real example.

Do you have a small example of a message that is decoded with problems? If it is small, you can paste it here, otherwise, please send it to me by e-mail.

  3. Re: Wrong base64 decoding   Reply   Report abuse  
Picture of Vincenzo Vincenzo - 2007-07-20 02:48:16 - In reply to message 2 from Manuel Lemos

Mails are near 7MB in total (4).

I sent you a mail with a link to download them.

Thank you a lot.

  4. Re: Wrong base64 decoding   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-20 23:05:29 - In reply to message 3 from Vincenzo
I tried decoding all the 4 messages you sent me. The attachments were saved to files. All of them have 426158 bytes. I even opened the messages in Thunderbird and it saved the attached files exactly like that.

Are you sure you are not using an old version of the class that may had bugs that caused that problem?

I used the version 1.26 that is available on the site . Meanwhile I uploaded a newer version that fixed a bug that were not affecting parsing your messages. Try the newer version and see if the problem is solved.

  5. Re: Wrong base64 decoding   Reply   Report abuse  
Picture of Vincenzo Vincenzo - 2007-07-26 15:25:34 - In reply to message 4 from Manuel Lemos

Downloaded new version, but same result...

[FileName] => Parata in partenza.3gp
[FileDisposition] => attachment
[BodyFile] => /var/tmp/GF14353/1
[BodyPart] => 1
[BodyLength] => 426152

Can be a php issue?

I'm using:

PHP 5.2.0-8+etch1 (cli) (built: Mar 7 2007 23:34:21)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies

If you want, i can enable a ssh shell to my host.


  6. Re: Wrong base64 decoding   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-30 23:37:32 - In reply to message 5 from Vincenzo
Maybe it is a issue with that PHP version your are using. Can you try with the latest PHP 5.2 or PHP 4.4 version?