Re: [PHP4BETA] imap extensions out of sync btw. php3 and php4b ?

From: Date: Sat, 11 Dec 1999 00:34:22 +0000
Subject: Re: [PHP4BETA] imap extensions out of sync btw. php3 and php4b ?
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-7783@lists.php.net to get a copy of this message
Quoting Hartmut Holzgräfe <hholzgra@media-engineering.de>: > further investigations into the differences btw. imap.c in PHP3 and > PHP4b showed that > imap support in PHP3 has moved ahead, leaving PHP4 quite a bit behind I was the one who wrote the imap_error() stuff, but I haven't had a chance to figure out how it should be implemented for php4, so if you want to take a crack at it, go ahead. > PS: anyone else in need of RFC2047-complient mail header en-/decoding ( > for our funny german umlauts ) ? There's some code in the IMP cvs tree to do this - I'll attach the encode_mime_string and decode_mime_string functions we've written. -chuck -- Charles Hagenbuch, <chagenbu@wso.williams.edu> -- "Individually, scientists no doubt have human weaknesses ... some of them may even be homosexuals and read Plato." - J. Bronowski

function eightbit ($string) { if (is_string($string)) { for ($i = 0; $i < strlen($string); $i++) { if (ord($string[$i])>>7) return true; } return false; } return false; } // eightbit() function encode_mime_string ($text, $charset) { if (eightbit($text)) { if (((strlen($text) * 3) + strlen($charset) + 7) > 76) { $text = encode_mime_string(substr($text, 0, (23 - strlen($charset))), $charset) . "\r\n\t" . encode_mime_string(substr($text, (23 - strlen($charset))), $charset); } else { $text = "=?$charset?Q?" . strtr(trim(imap_8bit($text)), ' ', '_') . '?='; } } return $text; } // encode_mime_string() function encode_mime_address ($text, $charset, $defserver) { $addr_arr = imap_rfc822_parse_adrlist($text, $defserver); $text = ''; if (is_array($addr_arr) && count($addr_arr) > 0) { while (list(,$addr) = each($addr_arr)) { if (empty($addr->personal)) $personal = ''; else $personal = encode_mime_string($addr->personal, $charset); if (strlen($text) != 0) $text .= ', '; $text .= imap_rfc822_write_address($addr->mailbox, $addr->host, $personal); } } return $text; } // encode_mime_address() /* Function to decode a MIME-encoded string, returns the original string, if not MIME */ function decode_mime_string ($string) { $pos = strpos($string, '=?'); if (!is_int($pos)) { return $string; } $preceding = substr($string, 0, $pos); // save any preceding text $search = substr($string, $pos+2, 75); // the mime header spec says this is the longest a single encoded word can be $d1 = strpos($search, '?'); if (!is_int($d1)) { return $string; } $charset = substr($string, $pos+2, $d1); $search = substr($search, $d1+1); $d2 = strpos($search, '?'); if (!is_int($d2)) { return $string; } $encoding = substr($search, 0, $d2); $search = substr($search, $d2+1); $end = strpos($search, '?='); if (!is_int($end)) { return $string; } $encoded_text = substr($search, 0, $end); $rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6)); switch ($encoding) { case 'Q': case 'q': $encoded_text = str_replace('_', '%20', $encoded_text); $encoded_text = str_replace('=', '%', $encoded_text); $decoded = urldecode($encoded_text); if (strtolower($charset) == 'windows-1251') { $decoded = convert_cyr_string($decoded, 'w', 'k'); } break; case 'B': case 'b': $decoded = urldecode(base64_decode($encoded_text)); if (strtolower($charset) == 'windows-1251') { $decoded = convert_cyr_string($decoded, 'w', 'k'); } break; default: $decoded = '=?' . $charset . '?' . $encoding . '?' . $encoded_text . '?='; break; } return $preceding . $decoded . decode_mime_string($rest); } // decode_mime_string()
« previous php.version4 (#7783) next »