[PHP] RE: RE: Sending MIME emails with base64 encoded attachments

2002-02-06 Thread Svarc, Petr
Title: RE: RE: Sending MIME emails with base64 encoded attachments





FINAL SOLUTION!


Hello


Ok. It's me, the last time :-)


> Let say I have a small 4byte file with content "AB#0C" 
> (ascii: #65,#66,#0,#67)
> I load it (using binary save fread into $txt)
> When I try to get third character (#0), quess what I get:
> $x = ord(substr($txt,2,1))
> 
> $x IS NOT 0!
> $x IS 92, which mean backslash. Fourth char is 48, which 
> means "0" and the fifth #67.
> 
> So, PHP replaces any #0 with "\0" in every string internally.


OK. THIS is true just for string obtained by fread()
Strings created internally are OK.


So the solution is:
1) get the string from the file using $str=fread($file,filesize($filename));
2) I realize that in string obtained by fread() the following characters are changed:
    #0 () -> #92#48 (\0)
    #34 (") -> #92#34 (\")
    #39 (') -> #92#39 (\')
    #92 (\) -> #92#92 (\\)
3) So solution is before put text into base64_encode procedure, do the following:
    $str=str_replace(chr(92).chr(48),chr(0),$str);
    $str=str_replace(chr(92).chr(34),chr(34),$str);
    $str=str_replace(chr(92).chr(39),chr(39),$str);
    $str=str_replace(chr(92).chr(92),chr(92),$str);
4) Now you can encode it.


It works.


Futhermore, I was trying to store some string to file using fwrite() method.
fwrite() works fine for all characters except backslash, where you have to
send there double backslash.
So fwrite($file,chr(0)) writes really #0, 
but for writing #92 you have to call fwrite($file,chr(92).chr(92));
For writing #0 you can also call fwrite($file,chr(92).chr(48));
(   and similary for all four cases stated above in point 3)   )



So, a thing, that's all for now


Have a nice day...


Petr Svarc




This electronic message transmission contains information from TMP Worldwide
and is confidential or privileged.  The information is intended to be for the use of
the individual or entity named above. If you are not the intended recipient, 
be aware that any disclosure, copying, distribution, or use of the contents of this
information is prohibited. If you have received this electronic transmission in error,
please notify us by telephone immediately at +44 (0)20 7406 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] RE: Sending MIME emails with base64 encoded attachments

2002-02-06 Thread Svarc, Petr
Title: RE: Sending MIME emails with base64 encoded attachments





Hello.


That's me, again.


I found a reason of my problem..not solution.


PHP use Cstyle string, where end of string si #0.


Let say I have a small 4byte file with content "AB#0C" (ascii: #65,#66,#0,#67)
I load it (using binary save fread into $txt)
When I try to get third character (#0), quess what I get:
$x = ord(substr($txt,2,1))


$x IS NOT 0!
$x IS 92, which mean backslash. Fourth char is 48, which means "0" and the fifth #67.


So, PHP replaces any #0 with "\0" in every string internally.


Which wouldn't be do bad, BUT:
INTERNAL base64_encode AND base64_decode FUNCTIONS FORGET IT!


That's the reason why I can't read any base64 encoded attachment with external email client.
WHAT A SHAME FOR PHP
(or for me if I'm wrong :-)



What do you thing about that?
Do PHP develop centre know about it?
Does exists any patch?


One possible solution is:
- Write custom base64 encoding/decoding, which will handle the problem (maybe encoding is enough)...


Does somebody have such a function?
Or do you see any other solution?
Or am I completely wrong? :-o



Regards



Petr Svarc




This electronic message transmission contains information from TMP Worldwide
and is confidential or privileged.  The information is intended to be for the use of
the individual or entity named above. If you are not the intended recipient, 
be aware that any disclosure, copying, distribution, or use of the contents of this
information is prohibited. If you have received this electronic transmission in error,
please notify us by telephone immediately at +44 (0)20 7406 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Sending MIME emails with base64 encoded attachments

2002-02-06 Thread Svarc, Petr
Title: Sending MIME emails with base64 encoded attachments





Hello there


My base64 encoded attachments in MIME emails come corrupted.


I using PHP4 on SuSe Linux.
I'm sending an MIME email (I generatate all the headers and so on) with attachments.
The first part is7bit text, 2nd part is mime-type I get from file and encoding: base64
The file I need to attach I read from disc using $txt=fread($file,filesize($filename)); the file is opened
by $file=fopen($filename,"r").
Then I encode the content with:
$txt=base64_encode($txt)
and split it with:
$txt=chunk_split($txt,56,"\r\n")


When I then send it, the mail arrives, but the attached file (e.g. *.zip) is corrupted.
Attachment is a little bit larger than original.
In original there are #0 (char. ascii 0), in attachment they come as "\0" (#92#48).


Attachments like text files (even with characters behind #127) are OK, they come without any corruption.


I tried to write small test.php, where I just load file, base64_encode it and then base64_decode it, and it's OK.


Seems to me that PHP use "another" base64 coding than all email clients
OR
The way how I read the file is bad, so base64_encode gets a little different data, but is still able to get it back on the local

OR
I don't know :-(



Please, help, if you can.


Many thanks



Petr Svarc




This electronic message transmission contains information from TMP Worldwide
and is confidential or privileged.  The information is intended to be for the use of
the individual or entity named above. If you are not the intended recipient, 
be aware that any disclosure, copying, distribution, or use of the contents of this
information is prohibited. If you have received this electronic transmission in error,
please notify us by telephone immediately at +44 (0)20 7406 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php