| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package AkelosFramework 13 * @subpackage AkActionMailer 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 */ 18 19 include_once(AK_CONTRIB_DIR.DS.'pear'.DS.'Mail'.DS.'mimeDecode.php'); 20 21 class AkMailEncoding extends Mail_mimeDecode 22 { 23 /** 24 * PEAR's header decoding function is buggy and is not enough tested, so we 25 * override it using the Akelos charset transcoding engine to get the result 26 * as UTF-8 27 */ 28 function _decodeHeader($encoded_header) 29 { 30 $encoded_header = str_replace(array('_',"\r","\n =?"),array(' ',"\n","\n=?"), 31 preg_replace('/\?\=([^=^\n^\r]+)?\=\?/', "?=$1\n=?",$encoded_header)); 32 33 $decoded = $encoded_header; 34 if(preg_match_all('/(\=\?([^\?]+)\?([BQ]{1})\?([^\?]+)\?\=?)+/i',$encoded_header,$match)){ 35 foreach ($match[0] as $k=>$encoded){ 36 $charset = strtoupper($match[2][$k]); 37 $decode_function = strtolower($match[3][$k]) == 'q' ? 'quoted_printable_decode' : 'base64_decode'; 38 $decoded_part = trim(Ak::recode($decode_function($match[4][$k]), AK_ACTION_MAILER_DEFAULT_CHARSET, $charset, true)); 39 40 $decoded = str_replace(trim($match[0][$k]), $decoded_part, $decoded); 41 } 42 } 43 return trim(preg_replace("/(%0A|%0D|\n+|\r+)/i",'',$decoded)); 44 } 45 46 function decode() 47 { 48 $this->_include_bodies = $this->_decode_bodies = $this->_decode_headers = true; 49 50 $structure = $this->_decode($this->_header, $this->_body); 51 if ($structure === false) { 52 $structure = $this->raiseError($this->_error); 53 } 54 55 return $structure; 56 } 57 58 59 //// 60 61 function _encodeAddress($address_string, $header_name = '', $names = true) 62 { 63 $headers = ''; 64 $addresses = Ak::toArray($address_string); 65 $addresses = array_map('trim', $addresses); 66 foreach ($addresses as $address){ 67 $address_description = ''; 68 if(preg_match('#(.*?)<(.*?)>#', $address, $matches)){ 69 $address_description = trim($matches[1]); 70 $address = $matches[2]; 71 } 72 73 if(empty($address) || !$this->_isAscii($address) || !$this->_isValidAddress($address)){ 74 continue; 75 } 76 if($names && !empty($address_description)){ 77 $address = "<$address>"; 78 if(!$this->_isAscii($address_description)){ 79 $address_description = '=?'.AK_ACTION_MAILER_DEFAULT_CHARSET.'?Q?'.$this->quoted_printable_encode($address_description, 0).'?='; 80 } 81 } 82 $headers .= (!empty($headers)?','.AK_MAIL_HEADER_EOL.' ':'').$address_description.$address; 83 } 84 85 return empty($headers) ? false : (!empty($header_name) ? $header_name.': '.$headers.AK_MAIL_HEADER_EOL : $headers); 86 } 87 88 function _isValidAddress($email) 89 { 90 return preg_match(AK_EMAIL_REGULAR_EXPRESSION, $email); 91 } 92 93 94 } 95 96 97 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |