note 86753 added to function.imap-fetchstructure

From: Date: Sun, 02 Nov 2008 10:34:29 +0000
Subject: note 86753 added to function.imap-fetchstructure
Groups: php.notes 
Request: Send a blank email to php-notes+get-146033@lists.php.net to get a copy of this message
I've made this two functions to decode mime headers and so far they are working just fine decoding all headers. Please let me know if you find any error. Hoppe they are usefull for you too. <? function decode_headers($cabecalho){ while (preg_match('/^(.*)=\?([^?]*)\?(Q|B)\?(.*)$/Ui', $cabecalho)){ $cabecalho = preg_replace("/(\t|\r|\n)/", "", $cabecalho); $cabecalho = preg_replace("/\?(Q|B)\?=/Ui", "?\\1? =", $cabecalho); $partes_cabecalho = explode("?=", $cabecalho); $resultado = ""; foreach ($partes_cabecalho as $texto){ $texto = preg_replace("/\?(Q|B)\?\s=/Ui", "?\\1?=", $texto); $texto = preg_replace("/\?(Q|B)\?/Ui", "=?\\1=?", $texto); if (preg_match('/^(.*)=\?([^?]*)=\?(Q|B)=\?(.*)$/Ui', $texto)){ $partes_texto = explode ("=?", $texto); $parte = descodificar_parte($partes_texto[0], $partes_texto[1]); $parte .= descodificar_parte($partes_texto[3], $partes_texto[2]); } else { $parte = $texto; } if (strtoupper($partes_texto[1]) == "UTF-8"){ $parte = utf8_decode($parte);} $resultado .= $parte; } $cabecalho = $resultado; } return trim($cabecalho); } function descodificar_parte($texto, $codificacao){ if (trim($texto) == ""){ return "";} if (ucfirst($codificacao) == "B"){ $texto = base64_decode($texto); $texto = htmlspecialchars($texto); } else if (ucfirst($codificacao) == "Q"){ $texto = str_replace("_", " ", $texto); $texto = quoted_printable_decode($texto); } return $texto; } ?> ---- Server IP: 81.92.192.129 Probable Submitter: 87.196.155.174 ---- Manual Page -- http://www.php.net/manual/en/function.imap-fetchstructure.php Edit -- https://master.php.net/note/edit/86753 Del: integrated -- https://master.php.net/note/delete/86753/integrated Del: useless -- https://master.php.net/note/delete/86753/useless Del: bad code -- https://master.php.net/note/delete/86753/bad+code Del: spam -- https://master.php.net/note/delete/86753/spam Del: non-english -- https://master.php.net/note/delete/86753/non-english Del: in docs -- https://master.php.net/note/delete/86753/in+docs Del: other reasons-- https://master.php.net/note/delete/86753 Reject -- https://master.php.net/note/reject/86753 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146033) next »