note 11220 modified in function.imap-header by didou

From: Date: Thu, 27 May 2004 12:06:15 +0000
Subject: note 11220 modified in function.imap-header by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70176@lists.php.net to get a copy of this message
I've got a problem when facing some encoded subject or from header like: =?big5?B?uXG4o7ZXpEg3MTEw?= or =?iso-8859-1?Q?A7=EB=B2=BC=B6=7D=A9l=21?= this problem only appears when the poster is using non-Misco$oft reader, and i lastly find the way to solve. For the =?big5?B?, the encode method is base64, so you can use base64_decode to decode it to the original one, you can use the following to check and decode: <?php if(ereg("=\?.{0,}\?[Bb]\?",$strHead)){ $arrHead=split("=\?.{0,}\?[Bb]\?",$strHead); while(list($key,$value)=each($arrHead)){ if(ereg("\?=",$value)){ $arrTemp=split("\?=",$value); $arrTemp[0]=base64_decode($arrTemp[0]); $arrHead[$key]=join("",$arrTemp); } } $strHead=join("",$arrHead); } ?> For =?iso-8859-1?Q?, it uses quoted printable to encode, you can use quoted_printable_decode to decode, example: <?php if(ereg("=\?.{0,}\?Q\?",$strHead)){ $strHead=quoted_printable_decode($strHead); $strHead=ereg_replace("=\?.{0,}\?[Qq]\?","",$strHead); $strHead=ereg_replace("\?=","",$strHead); } ?> --was-- I've got a problem when facing some encoded subject or from header like: =?big5?B?uXG4o7ZXpEg3MTEw?= or =?iso-8859-1?Q?A7=EB=B2=BC=B6=7D=A9l=21?= this problem only appears when the poster is using non-Misco$oft reader, and i lastly find the way to solve. For the =?big5?B?, the encode method is base64, so you can use base64_decode to decode it to the original one, you can use the following to check and decode: if(ereg("=\?.{0,}\?[Bb]\?",$strHead)){ $arrHead=split("=\?.{0,}\?[Bb]\?",$strHead); while(list($key,$value)=each($arrHead)){ if(ereg("\?=",$value)){ $arrTemp=split("\?=",$value); $arrTemp[0]=base64_decode($arrTemp[0]); $arrHead[$key]=join("",$arrTemp); } } $strHead=join("",$arrHead); } For =?iso-8859-1?Q?, it uses quoted printable to encode, you can use quoted_printable_decode to decode, example: if(ereg("=\?.{0,}\?Q\?",$strHead)){ $strHead=quoted_printable_decode($strHead); $strHead=ereg_replace("=\?.{0,}\?Q\?","",$strHead); $strHead=ereg_replace("\?=","",$strHead); } http://www.php.net/manual/en/function.imap-header.php

« previous php.notes (#70176) next »