View Full Version : class.pop3.php
FreshMedia
01-31-2008, 05:36 AM
function mime_encode($text,$charset=null,$enc='uft-8') { //Thank in part to afterburner
is it correct? :)
BUT this code wont work property:
mails in KOI8-R parses empty :((( have any solutions?
afterburner
02-04-2008, 03:56 AM
I was just going through the new code to see the changes and I noticed this : if($encoding && 0) { //Convert text to desired mime encoding... on line 155 in class.pop3.php
You should remove the "&& 0" to make the new changes work ;)
But I think it would be better just to use this:
if($encoding)
if(!strcasecmp($struct->parameters[0]->attribute,'CHARSET') && strcasecmp($struct->parameters[0]->value,'US-ASCII')) {
$charset=trim($struct->parameters[0]->value);
$text=@iconv($charset,$encoding,$text);
}
}
instead of
if($encoding && 0) { //Convert text to desired mime encoding...
if($struct->parameters[0]
&& !strcasecmp($struct->parameters[0]->attribute,'CHARSET') && strcasecmp($struct->parameters[0]->value,'US-ASCII')) {
$charset=trim($struct->parameters[0]->value);
}
$text=$this->mime_encode($text,$charset,$encoding);
}
It's more generic, it allows decoding from all possible encodings. (I found that mb_decode_string does not always work correctly, so I decided not to use it).
P.S. This is the version I use in a site that has about 500 000 unique visitors a day and about 10 000 000 reloads every day and it's has performed flawlessly (and we have A LOT of feedback). I suggest dropping the mime_encode function and implementing it the easy way I did :)
FreshMedia
02-04-2008, 05:36 AM
afterburner, thanks!!!
peter
02-04-2008, 11:30 AM
afterburner,
Thank you once again...I somehow forgot to remove " && 0". before the release!!
The problem with your mod is the fact that "iconv" extension is not available in all php installations.
FreshMedia
02-05-2008, 02:58 AM
Peter, it's great :) but i've start coding my personal ticket system, with more flexible authorization, each departament have personal templates and notify options. Think about this features :)
afterburner
02-05-2008, 03:37 AM
afterburner,
Thank you once again...I somehow forgot to remove " && 0". before the release!!
The problem with your mod is the fact that "iconv" extension is not available in all php installations.
Yes, you're right, but what I wanted was to just point the way, after you guys helped me find the best way to do it for myself. I was not able to give any more feedback, but I should have told you that I found this easier way that worked better - I mean without using any of the "mb" PHP functions and so on. It's simpler and it uses only what is given by the headers, so it's more reliable in my opinion. About "iconv" not available anywhere - there were other "mb" (multibyte) functions that do similar things if I remember... If you decide to implement my idea again (directly using the conversion of charsets - withounf mb_detect_encoding) you could throw in a check to see which one is available - "iconv" or maybe another mb function. In 99% of the cases there will be at least one.
peter
02-05-2008, 03:47 AM
Afterburner,
It is already implemented in mime_encode function called from getPart as shown below;
function mime_encode($text,$charset=null,$enc='uft-8') { //Thanks in part to afterburner
$encodings=array('UTF-8','WINDOWS-1251', 'ISO-8859-5', 'ISO-8859-1');
if(function_exists("iconv") and $text) {
if($charset)
return iconv($charset,$enc.'//IGNORE',$text);
elseif(function_exists("mb_detect_encoding"))
return iconv(mb_detect_encoding($text,$encodings),$enc,$t ext);
}
return utf8_encode($text); //blind encoding?
}
afterburner
02-05-2008, 11:37 AM
Forgive me for being blind :o:o I thought I examined that function but apparently the coffee was not enough...