function quote_header($header) { // Detect if we may need decoding (avoid regex later if not) if (strpos($header, '?=')) { $headerParts = preg_split('/,|;/', $header); $decode = true; } else { // Catch a Non-Standard(?) MIME charset encoding // This was required for a client who got many emails with // this type of encoding if (preg_match('/^(ISO-8859-\\d+)\'.*?\'(.+)/i', $header, $m)) { return iconv($m[1], 'UTF-8', rawurldecode($m[2])); } $headerParts = array($header); $decode = false; } $decoded = ''; foreach ($headerParts as $h) { if ($decode && preg_match('/\\s*=\\?([^\\?]+)\\?([QqBb])/', $h, $m)) { if (strtoupper($m[2]) == 'Q') { $h = preg_replace('/\\s*=\\?([^\\?]+)\\?[Qq]\\?([^\\?]+)?\\?=/e', 'GetMail::decode_language(\'$1\', GetMail::decode_mime_head(\'$1\', \'$2\'))', $h); } else { $h = preg_replace('/\\s*=\\?([^\\?]+)\\?[Bb]\\?([^\\?]+)?\\?=/e', 'GetMail::decode_language(\'$1\', base64_decode(\'$2\'))', $h); } } else { $h = GetMail::decode_language('', $h); } //$header = preg_replace('/(.+?)<(.*?)>/', '$1<$2>', $h); $h = str_replace(array('<', '>'), array('<', '>'), $h); $h = trim($h); $decoded .= $h; } return $decoded; }
function get_filename() { /* $filename = $this->filename ? $this->filename : $this->disposition_filename; if (!$filename) $filename = $this->content_name; // Another try if (!$filename && preg_match('/name=\s*(.+)/i', $this->headers['content-type'], $m)) { $filename = $m[1]; } */ if (!empty($this->headers['content-disposition'])) { if (preg_match('/filename=\\s*(.+)$/i', $this->headers['content-disposition'], $m)) { $filename = $m[1]; } } // try to get filename from Content-Type if missing from Content-Disposition if (empty($filename) && !empty($this->headers['content-type'])) { if (preg_match('/name=\\s*(.+)$/i', $this->headers['content-type'], $m)) { $filename = $m[1]; } } // If part is a message forwarded as an attachment (message/rfc822) // Do some extra checks if (strpos(strtolower($this->content_type), 'message/rfc822') !== false) { if (empty($filename)) { //$filename = 'Forwarded_Message.txt'; if (preg_match('/^Subject:(.+?)$/m', $this->body, $m)) { if (preg_match('/\\s*=\\?([^\\?]+)\\?([QqBb])/', $m[1], $match)) { $match[2] = strtoupper($match[2]); if ($match[2] == 'Q') { $m[1] = preg_replace('/\\s*=\\?([^\\?]+)\\?[Qq]\\?([^\\?]+)?\\?=/e', "GetMail::decode_language('\\1', GetMail::decode_mime_head('\\1', '\\2'))", $m[1]); } else { $m[1] = preg_replace('/\\s*=\\?([^\\?]+)\\?[Bb]\\?([^\\?]+)?\\?=/e', "GetMail::decode_language('\\1', base64_decode('\\2'))", $m[1]); } $filename = $m[1]; } else { $filename = GetMail::decode_language($this->get_charset, $m[1]); } if (substr($filename, -4) != '.eml') { $filename .= '.eml'; } } else { $filename = 'Fowarded Message-' . rand(10000, 99999) . '.eml'; } } else { $filename = trim($filename); $filename = preg_replace('/(^")|(";?$)/', '', $filename); if (strtolower(substr($filename, -4)) != '.eml') { $filename .= '.eml'; } return $filename; } } // Some clients break up long filenames into two parts ie filename*0="" and filename*1="" // lets see if this is the case and join them together. if (empty($filename)) { if (preg_match_all('/filename(\\*\\d+)="(.+?)"/i', $this->headers['content-disposition'], $m, PREG_PATTERN_ORDER)) { $filename = join('', $m[2]); } } // Some clients break up long filenames into two parts ie filename*0="" and filename*1="" // lets see if this is the case and join them together. if (empty($filename)) { if (preg_match_all('/name(\\*\\d+)="(.+?)"/i', $this->headers['content-type'], $m, PREG_PATTERN_ORDER)) { $filename = join('', $m[2]); } } if (empty($filename)) { return ''; } // clean up filename $filename = trim($filename); $filename = preg_replace('/(^")|(";?$)/', '', $filename); return $filename; }
function quote_header($header) { if (preg_match('/\\s*=\\?([^\\?]+)\\?([QqBb])/', $header, $m)) { if (strtoupper($m[2]) == 'Q') { $header = preg_replace('/\\s*=\\?([^\\?]+)\\?[Qq]\\?([^\\?]+)?\\?=/e', 'GetMail::decode_language(\'$1\', GetMail::decode_mime_head(\'$1\', \'$2\'))', $header); } else { $header = preg_replace('/\\s*=\\?([^\\?]+)\\?[Bb]\\?([^\\?]+)?\\?=/e', 'GetMail::decode_language(\'$1\', base64_decode(\'$2\'))', $header); } } else { $header = GetMail::decode_language('', $header); } $header = preg_replace('/(.+?)<(.*?)>/', '$1<$2>', $header); $header = str_replace(array('<', '>'), '', $header); $header = trim($header); return $header; }