Changeset View
Changeset View
Standalone View
Standalone View
scripts/mail/mail_handler.php
| Show All 32 Lines | $args->parse( | ||||
| )); | )); | ||||
| $parser = new MimeMailParser(); | $parser = new MimeMailParser(); | ||||
| $parser->setText(file_get_contents('php://stdin')); | $parser->setText(file_get_contents('php://stdin')); | ||||
| $content = array(); | $content = array(); | ||||
| foreach (array('text', 'html') as $part) { | foreach (array('text', 'html') as $part) { | ||||
| $part_body = $parser->getMessageBody($part); | $part_body = $parser->getMessageBody($part); | ||||
| if (strlen($part_body) && !phutil_is_utf8($part_body)) { | |||||
| $part_headers = $parser->getMessageBodyHeaders($part); | $part_headers = $parser->getMessageBodyHeaders($part); | ||||
| if (!is_array($part_headers)) { | |||||
| $part_headers = array(); | |||||
| } | |||||
| $content_type = idx($part_headers, 'content-type'); | $content_type = idx($part_headers, 'content-type'); | ||||
| if ( | if (preg_match('/charset="(.*?)"/', $content_type, $matches) || | ||||
| !phutil_is_utf8($part_body) && | preg_match('/charset=(\S+)/', $content_type, $matches)) { | ||||
| (preg_match('/charset="(.*?)"/', $content_type, $matches) || | |||||
| preg_match('/charset=(\S+)/', $content_type, $matches)) | |||||
| ) { | |||||
| $part_body = phutil_utf8_convert($part_body, 'UTF-8', $matches[1]); | $part_body = phutil_utf8_convert($part_body, 'UTF-8', $matches[1]); | ||||
| } | } | ||||
| } | |||||
| $content[$part] = $part_body; | $content[$part] = $part_body; | ||||
| } | } | ||||
| $headers = $parser->getHeaders(); | $headers = $parser->getHeaders(); | ||||
| $headers['subject'] = iconv_mime_decode($headers['subject'], 0, 'UTF-8'); | $headers['subject'] = iconv_mime_decode($headers['subject'], 0, 'UTF-8'); | ||||
| $headers['from'] = iconv_mime_decode($headers['from'], 0, 'UTF-8'); | $headers['from'] = iconv_mime_decode($headers['from'], 0, 'UTF-8'); | ||||
| if ($args->getArg('process-duplicates')) { | if ($args->getArg('process-duplicates')) { | ||||
| Show All 38 Lines | |||||