コード例 #1
0
ファイル: harpy.php プロジェクト: kozo/harpy
 /**
  * メール受信時の処理
  * 
  * @access public
  * @author sakuragawa
  */
 function execute()
 {
     ini_set('memory_limit', -1);
     // 前処理
     $this->beforefilter();
     // メールの読み込み
     $source = file_get_contents("php://stdin");
     if (empty($source)) {
         return;
     }
     // \nをつけてるのは、そのままだとSoftbankの空メールが取得できなかったから
     $source .= "\n";
     $this->hookMail($source);
     // メールをデコード
     //$this->out($this->params2);
     $Decoder = new Mail_mimeDecode($source);
     $mail = $Decoder->decode($this->mailMimeDecodeParams);
     // Fromを取得
     $from = $this->_parseAddress($mail, 'from');
     $this->hookFromAddress($from);
     // Toを取得
     $to = $this->_parseAddress($mail, 'to');
     $this->hookToAddress($to);
     // 本文・添付等をパース
     $this->_parseBody($mail);
     $this->afterfilter();
     // Toを取得
     /*$to = $this->_getTo($mail);
       $this->getTo($to);*/
 }
コード例 #2
0
 function GetMessage($message_id, $external_id = 0)
 {
     if (!isset($this->_messageCash[$message_id])) {
         $raw_message = $this->_pop3->getMsg($message_id);
         require_once SYS . '/system/class/email/mime/mimeDecode.php';
         $params['include_bodies'] = true;
         $params['decode_bodies'] = true;
         $params['decode_headers'] = true;
         $decoder = new Mail_mimeDecode($raw_message);
         $msg = $decoder->decode($params);
         //				Dump($msg, true);
         $msg->external_id = $external_id;
         if (isset($msg->headers['date'])) {
             $msg->Moment = strtotime($msg->headers['date']);
         } else {
             $msg->Moment = 0;
         }
         $msg = $this->ProcessMessageBody($msg);
         if (strtoupper($msg->charset) == 'KOI8-R') {
             $msg->body = convert_cyr_string($msg->body, 'koi8-r', 'Windows-1251');
             $msg->headers['subject'] = convert_cyr_string($msg->headers['subject'], 'koi8-r', 'Windows-1251');
             $msg->charset = 'Windows-1251';
         }
         $this->_messageCash[$message_id] = $msg;
         $this->got_inner_body = null;
     }
     return $this->_messageCash[$message_id];
 }
コード例 #3
0
ファイル: class.mailparse.php プロジェクト: supaket/helpdesk
 function decode()
 {
     $params = array('crlf' => "\r\n", 'input' => $this->mime_message, 'include_bodies' => $this->include_bodies, 'decode_headers' => $this->decode_headers, 'decode_bodies' => $this->decode_bodies);
     $this->splitBodyHeader();
     $this->struct = Mail_mimeDecode::decode($params);
     return PEAR::isError($this->struct) || !(count($this->struct->headers) > 1) ? FALSE : TRUE;
 }
コード例 #4
0
ファイル: emailtopdf.php プロジェクト: swk/bluebox
 public static function processemail($emailsrc, $pdfout, $coverfile = '')
 {
     $combfilelist = array();
     # Process the email
     $emailparts = Mail_mimeDecode::decode(array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => true, 'input' => file_get_contents($emailsrc), 'crlf' => "\r\n"));
     # Process the cover if it exists
     if ($coverfile !== '') {
         $combfilelist[] = self::processpart(file_get_contents($coverfile), mime_content_type($coverfile));
     }
     # Process the parts
     $combfilelist = array_merge($combfilelist, self::processparts($emailparts));
     # Create an intermediate file to build the pdf
     $tmppdffilename = sys_get_temp_dir() . '/e2p-' . (string) abs((int) (microtime(true) * 100000)) . '.pdf';
     # Build the command to combine all of the intermediate files into one
     $conbcom = str_replace(array_merge(array('INTFILE', 'COMBLIST'), array_keys(self::$driver_paths)), array_merge(array($tmppdffilename, implode(' ', $combfilelist)), array_values(self::$driver_paths)), self::$mime_drivers['gs']);
     exec($conbcom);
     # Remove the intermediate files
     foreach ($combfilelist as $combfilename) {
         unlink($combfilename);
     }
     # Write the intermediate file to the final destination
     $intfileres = fopen($tmppdffilename, 'rb');
     $outfileres = fopen($pdfout, 'ab');
     while (!feof($intfileres)) {
         fwrite($outfileres, fread($intfileres, 8192));
     }
     fclose($intfileres);
     fclose($outfileres);
     # Remove the intermediate file
     unlink($tmppdffilename);
 }
コード例 #5
0
function testMimeDecode($file, $new_file)
{
    if (!defined('LOGLEVEL')) {
        define('LOGLEVEL', LOGLEVEL_DEBUG);
    }
    if (!defined('LOGUSERLEVEL')) {
        define('LOGUSERLEVEL', LOGLEVEL_DEVICEID);
    }
    printf("TEST MIME DECODE\n");
    $mobj = new Mail_mimeDecode(file_get_contents($file));
    $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
    $handle = fopen($new_file, "w");
    fwrite($handle, build_mime_message($message));
    fclose($handle);
    foreach ($message->headers as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $vk => $vv) {
                printf("Header <%s> <%s> <%s>\n", $k, $vk, $vv);
            }
        } else {
            printf("Header <%s> <%s>\n", $k, $v);
        }
    }
    $text = $html = "";
    Mail_mimeDecode::getBodyRecursive($message, "plain", $text);
    Mail_mimeDecode::getBodyRecursive($message, "html", $html);
    printf("TEXT Body <%s>\n", $text);
    printf("HTML Body <%s>\n", $html);
}
コード例 #6
0
ファイル: transport.php プロジェクト: bitweaver/switchboard
function transport_email_receive($pMsg)
{
    global $gBitUser, $gBitSystem;
    // prolly dont need this
    // $connectionString = '{'.$gBitSystem->getConfig('transport_email_server','imap').':'.$gBitSystem->getConfig('transport_email_port','993').'/'.$gBitSystem->getConfig('transport_email_protocol','imap').'/ssl/novalidate-cert}';
    // Parse msg - get header, body, attachments, to, from, reply header
    if (include_once 'PEAR.php') {
        if (require_once 'Mail/mimeDecode.php') {
            $params['include_bodies'] = true;
            $params['decode_bodies'] = true;
            $params['decode_headers'] = true;
            $decoder = new Mail_mimeDecode($pMsg);
            if ($data = $decoder->decode($params)) {
                if ($handler($data)) {
                    transport_email_expunge($pMsg);
                }
            } else {
                //error
            }
        } else {
            //error
        }
    } else {
        //error
    }
}
コード例 #7
0
ファイル: KtaiMail.php プロジェクト: KimuraYoichi/PukiWiki
 /**
  * メールをデコード
  *
  * @access public
  * @param string メールの生データ
  */
 function decode($raw_mail)
 {
     $params['include_bodies'] = true;
     $params['decode_bodies'] = true;
     $params['decode_headers'] = true;
     $params['input'] = $raw_mail;
     $this->mail =& Mail_mimeDecode::decode($params);
 }
コード例 #8
0
ファイル: Parser.class.php プロジェクト: pombredanne/tuleap
 public function parse($input)
 {
     $decoder = new Mail_mimeDecode($input, "\r\n");
     $structure = $decoder->decode(array('include_bodies' => true, 'decode_bodies' => true));
     $raw_mail = (array) $structure;
     $raw_mail['body'] = $this->getBody($structure);
     return $raw_mail;
 }
コード例 #9
0
{
    private $paramsDecode = array('decode_headers' => TRUE, 'include_bodies' => TRUE, 'decode_bodies' => TRUE);
    private $_decoded;
    private $_email;
    private $spf;
    private $body;
    private $subject;
    private $fromEmail;
コード例 #10
0
function decodeEmail($input)
{
    $params['include_bodies'] = true;
    $params['decode_bodies'] = true;
    $params['decode_headers'] = true;
    $decoder = new Mail_mimeDecode($input);
    $structure = $decoder->decode($params);
    return $structure;
}
コード例 #11
0
ファイル: ParseLetter.php プロジェクト: amanukian/test
 public function process()
 {
     $this->init();
     ini_set('memory_limit', -1);
     $debug = app()->request->getParam('debug');
     $params = [];
     //SUPPLIER_PRICES_DIR
     $incoming = $debug ? file_get_contents($this->_rootPath . DS . "eml" . DS . "test.eml") : app()->request->getParam('@letter');
     if (!$incoming) {
         $this->log('не корректное получение письма', true);
     }
     $params = ['include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => true];
     $decoder = new Mail_mimeDecode($incoming);
     $result = $decoder->decode($params);
     preg_match_all('/\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+/', $result->headers["from"], $matches);
     $mail = $matches[0];
     //array with from emails
     if (!$mail) {
         $this->log("не установлен отправитель письма от {$result->headers['from']}", true);
     }
     $this->email = $mail[0];
     // временный тестовый лог
     if (isset($result->headers["subject"]) && is_array($result->headers["subject"])) {
         $this->log("ОШИБКА в ParseLetter-e \nДата: " . CJSON::encode($result), true);
     }
     // Пример: Subject: [supplierId 9255]
     if (isset($result->headers["subject"]) && strpos($result->headers["subject"], 'supplierId') !== false) {
         $subject = $result->headers["subject"];
         preg_match_all('/\\[.*?(\\d+)\\]/i', $subject, $matches);
         $idSupplier = $matches[1][0];
     } else {
         $query = app()->db->createCommand()->select('id_supplier, email')->from('supplier_email c')->join('supplier s', 'c.id_supplier = s.id')->where('email = "' . $this->email . '"')->andWhere('follow_manual = 1')->queryRow();
         $idSupplier = $query['id_supplier'];
     }
     if (!$idSupplier) {
         // $this->log("{$this->email} :: не установлен поставщик или для поставщика отключена настройка 'Следить вручную'", true); //временно выключаем
         Yii::app()->end();
     }
     $this->idSupplier = trim($idSupplier);
     $this->_destFileDir = $this->_rootPath . $this->idSupplier . DS . 'new';
     File::checkPermissions($this->_destFileDir);
     setlocale(LC_ALL, 'ru_RU.UTF8');
     if (isset($result->parts)) {
         foreach ($result->parts as $key => $part) {
             if ($part->ctype_primary == 'multipart') {
                 foreach ($part->parts as $k => $v) {
                     $this->mainProccess($v);
                 }
             } else {
                 $this->mainProccess($part);
             }
         }
     }
 }
コード例 #12
0
ファイル: msgParser.php プロジェクト: trabisdementia/xuups
 function &_parseMsg(&$msg)
 {
     $arr = array();
     //Parse out attachments/HTML
     $this->_params['input'] = $msg['msg'];
     $structure = Mail_mimeDecode::decode($this->_params);
     $body = $this->_getBody($structure);
     $arr['hash'] = $this->_parseTicketID($structure->headers['subject']);
     $arr['msg'] = $this->_parseBody($body);
     $arr['mime_struct'] = $structure;
     $arr = array_merge($arr, $this->_parseFrom($structure->headers['from']));
     return $arr;
 }
コード例 #13
0
ファイル: Outlook.php プロジェクト: raz0rsdge/horde
 /**
  * Returns a parsed MIME message
  *
  * @param string $text   The text of the message
  *
  * @return array An array with the MIME parsed headers and body.
  */
 function _mimeParse(&$text)
 {
     /* Taken from Horde's MIME/Structure.php */
     require_once 'Mail/mimeDecode.php';
     /* Set up the options for the mimeDecode class. */
     $decode_args = array();
     $decode_args['include_bodies'] = true;
     $decode_args['decode_bodies'] = false;
     $decode_args['decode_headers'] = false;
     $mimeDecode = new Mail_mimeDecode($text, MIME_PART_EOL);
     if (!($structure = $mimeDecode->decode($decode_args))) {
         return false;
     }
     /* Put the object into imap_parsestructure() form. */
     MIME_Structure::_convertMimeDecodeData($structure);
     return array($structure->headers, $ret =& MIME_Structure::parse($structure));
 }
コード例 #14
0
 public function parse($raw)
 {
     $this->raw = $raw;
     // http://pear.php.net/manual/en/package.mail.mail-mimedecode.decode.php
     $decoder = new Mail_mimeDecode($this->raw);
     $this->decoded = $decoder->decode(['decode_headers' => true, 'include_bodies' => true, 'decode_bodies' => true]);
     $this->from = mb_convert_encoding($this->decoded->headers['from'], $this->charset, $this->charset);
     $this->to = mb_convert_encoding($this->decoded->headers['to'], $this->charset, $this->charset);
     $this->subject = mb_convert_encoding($this->decoded->headers['subject'], $this->charset, $this->charset);
     $this->date = mb_convert_encoding($this->decoded->headers['date'], $this->charset, $this->charset);
     $this->from_email = preg_replace('/.*<(.*)>.*/', "\$1", $this->from);
     if (isset($this->decoded->parts) && is_array($this->decoded->parts)) {
         foreach ($this->decoded->parts as $idx => $body_part) {
             $this->decode_part($body_part);
         }
     }
     if (isset($this->decoded->disposition) && $this->decoded->disposition == 'inline') {
         $mime_type = "{$this->decoded->ctype_primary}/{$this->decoded->ctype_secondary}";
         if (isset($this->decoded->d_parameters) && array_key_exists('filename', $this->decoded->d_parameters)) {
             $filename = $this->decoded->d_parameters['filename'];
         } else {
             $filename = 'file';
         }
         if ($this->is_valid_attachment($mime_type)) {
             $this->save_attachment($filename, $this->decoded->body, $mime_type);
         }
         $this->body = "";
     }
     // We might also have uuencoded files. Check for those.
     if (empty($this->body)) {
         $this->body = isset($this->decoded->body) ? $this->decoded->body : "";
     }
     if (preg_match("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $this->body) > 0) {
         foreach ($decoder->uudecode($this->body) as $file) {
             // $file = [ 'filename' => $filename, 'fileperm' => $fileperm, 'filedata' => $filedata ]
             $this->save_attachment($file['filename'], $file['filedata']);
         }
         // Strip out all the uuencoded attachments from the body
         while (preg_match("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $this->body) > 0) {
             $this->body = preg_replace("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", "\n", $this->body);
         }
     }
     $this->body = mb_convert_encoding($this->body, $this->charset, $this->charset);
     return $this;
 }
コード例 #15
0
 /**
  * 標準入力からメールを読み込み、必要な情報を取得する。
  *
  * @return void
  */
 function parse()
 {
     if (@$this->parsed) {
         return;
     }
     require_once DATA_PATH . '/module/Mail/mimeDecode.php';
     $fp = fopen('php://stdin', 'r');
     // From 行を解析する。
     $from_line = rtrim(fgets($fp));
     if (preg_match('/^From\\s+"?([^\\s"@]+)"?@([^\\s@]+)/', $from_line, $matches)) {
         $this->sender = $matches[1] . '@' . $matches[2];
     } else {
         trigger_error("Invalid from line: {$from_line}");
         $this->sender = null;
     }
     // 残りのヘッダーを解析する。
     $data = '';
     while (!feof($fp)) {
         $data .= fgets($fp);
         if (rtrim($data, "\r\n") == '') {
             break;
         }
     }
     $structure = Mail_mimeDecode::decode(array('input' => $data));
     $this->recipient = @$structure->headers['to'];
     // 宛先アドレスから拡張部分を取得する。
     $pos = strpos($this->recipient, MOBILE_KARA_MAIL_ADDRESS_DELIMITER);
     if ($pos !== false) {
         $extension_and_domain = substr($this->recipient, $pos + 1);
         $pos = strpos($extension_and_domain, '@');
         if ($pos !== false) {
             $this->extension = substr($extension_and_domain, 0, $pos);
         } else {
             $this->extension = $extension_and_domain;
         }
     } else {
         trigger_error("Invalid recipient: {$this->recipient}");
         $this->extension = null;
     }
     $this->parsed = true;
 }
コード例 #16
0
 function MoblogRequest($request)
 {
     $this->Object();
     $this->_message = $request["message"];
     // it is possible to specify a default user id in the POSTed email message via
     // curl, so that the amount of stuff that we need to type in the email is reduced
     // to only the user password. This basically means that email addresses configured to be used
     // by a default user and blog id cannot be used as 'gateways'
     $this->_blogId = $request["blogId"];
     $this->_user = $request["user"];
     MoblogLogger::log("From REQUEST: user = "******" - blogId = " . $this->_blogId);
     // parse the mime message
     $decode = new Mail_mimeDecode($this->_message, "\r\n");
     $structure = $decode->decode(array("include_bodies" => true, "decode_bodies" => true, "decode_headers" => true));
     // get the reply address, it might be in different headers
     if (isset($structure->headers['x-loop'])) {
         $this->_replyAddress = "";
     } else {
         $replyTo1 = $structure->headers['from'];
         $replyTo2 = $structure->headers['return-path'];
         $this->_replyAddress = $replyTo2 != "" ? $replyTo2 : $replyTo1;
     }
     // parse the body
     $this->parseBody($structure->body);
     $this->_inputEncoding = strtoupper($structure->ctype_parameters['charset']);
     MoblogLogger::log("There are " . count($structure->parts) . " MIME parts available to parse");
     $this->parseMimeParts($structure->parts);
     // if there was no subject specified, then let's see if there was something in the
     // 'subject' line...
     if ($this->_topic == "") {
         $this->_topic = $structure->headers['subject'];
         if ($this->_topic == "" || stristr($this->_topic, "pass:"******"") {
                 $this->_topic = "No Topic";
             }
         }
     }
     MoblogLogger::Log("subject is = " . $this->_topic);
 }
コード例 #17
0
 /**
  * Constructor
  *
  * @param string                                         $content Http response
  * as string
  *
  * @param WindowsAzure\Common\Internal\Http\BatchRequest $request Source batch
  * request object
  */
 public function __construct($content, $request = null)
 {
     $params['include_bodies'] = true;
     $params['input'] = $content;
     $mimeDecoder = new \Mail_mimeDecode($content);
     $structure = $mimeDecoder->decode($params);
     $parts = $structure->parts;
     $this->_contexts = array();
     $requestContexts = null;
     if ($request != null) {
         Validate::isA($request, 'WindowsAzure\\Common\\Internal\\Http\\BatchRequest', 'request');
         $requestContexts = $request->getContexts();
     }
     $i = 0;
     foreach ($parts as $part) {
         if (!empty($part->body)) {
             $headerEndPos = strpos($part->body, "\r\n\r\n");
             $header = substr($part->body, 0, $headerEndPos);
             $body = substr($part->body, $headerEndPos + 4);
             $headerStrings = explode("\r\n", $header);
             $response = new \HTTP_Request2_Response(array_shift($headerStrings));
             foreach ($headerStrings as $headerString) {
                 $response->parseHeaderLine($headerString);
             }
             $response->appendBody($body);
             $this->_contexts[] = $response;
             if (is_array($requestContexts)) {
                 $expectedCodes = $requestContexts[$i]->getStatusCodes();
                 $statusCode = $response->getStatus();
                 if (!in_array($statusCode, $expectedCodes)) {
                     $reason = $response->getReasonPhrase();
                     throw new ServiceException($statusCode, $reason, $body);
                 }
             }
             $i++;
         }
     }
 }
コード例 #18
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     debugLog('FileStorage::SendMail(..., ' . $forward . ', ' . $reply . ', ' . $parent . ')');
     $mobj = new Mail_mimeDecode($rfc822);
     $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\r\n", 'charset' => 'utf-8'));
     if ($message->ctype_primary != "multipart" || $message->ctype_secondary != "mixed") {
         debugLog('FileStorage::SendMail not multipart/mixed');
         return false;
     }
     if (!isset($message->headers['subject']) || strtolower(substr(trim($message->headers['subject']), 0, 11)) != 'filestorage') {
         debugLog('FileStorage::SendMail subject not filestorage: ' . $message->headers['subject']);
         return false;
     }
     $d = '/' . str_replace('\\', '/', substr(trim($message->headers['subject']), 11)) . '/';
     if (strpos($d, '/../') !== false) {
         return true;
     }
     debugLog('FileStorage::SendMail dir: ' . $d);
     foreach ($message->parts as $part) {
         if ($part->ctype_primary == "text" || $part->ctype_primary == "multipart") {
             continue;
         }
         debugLog('FileStorage::SendMail attachment found');
         if (isset($part->ctype_parameters["name"])) {
             $filename = $part->ctype_parameters["name"];
         } else {
             if (isset($part->d_parameters["name"])) {
                 $filename = $part->d_parameters["filename"];
             } else {
                 return false;
             }
         }
         debugLog('FileStorage::SendMail saving: ' . $filename);
         file_put_contents($this->getPath('root') . $d . $filename, $part->body);
     }
     return true;
 }
コード例 #19
0
 /**
  * Redfined here just to avoid breakage on isStatic test (first line).
  * It's just a copy/paste of parent's method
  */
 function decode($params = null)
 {
     // determine if this method has been called statically
     $isStatic = !(isset($this) && get_class($this) == __CLASS__);
     // Have we been called statically?
     // If so, create an object and pass details to that.
     if ($isStatic and isset($params['input'])) {
         $obj = new Mail_mimeDecode($params['input']);
         $structure = $obj->decode($params);
         // Called statically but no input
     } elseif ($isStatic) {
         return PEAR::raiseError('Called statically and no input given');
         // Called via an object
     } else {
         $this->_include_bodies = isset($params['include_bodies']) ? $params['include_bodies'] : false;
         $this->_decode_bodies = isset($params['decode_bodies']) ? $params['decode_bodies'] : false;
         $this->_decode_headers = isset($params['decode_headers']) ? $params['decode_headers'] : false;
         $structure = $this->_decode($this->_header, $this->_body);
         if ($structure === false) {
             $structure = $this->raiseError($this->_error);
         }
     }
     return $structure;
 }
コード例 #20
0
ファイル: rcube_mime.php プロジェクト: bbspike/sentora-core
 /**
  * Parse the given raw message source and return a structure
  * of rcube_message_part objects.
  *
  * It makes use of the PEAR:Mail_mimeDecode library
  *
  * @param string  The message source
  * @return object rcube_message_part The message structure
  */
 public static function parse_message($raw_body)
 {
     $mime = new Mail_mimeDecode($raw_body);
     $struct = $mime->decode(array('include_bodies' => true, 'decode_bodies' => true));
     return self::structure_part($struct);
 }
コード例 #21
0
ファイル: mailhandler.php プロジェクト: Grasia/bolotweet
 function parse_message($contents)
 {
     $parsed = Mail_mimeDecode::decode(array('input' => $contents, 'include_bodies' => true, 'decode_headers' => true, 'decode_bodies' => true));
     if (!$parsed) {
         return null;
     }
     $from = $parsed->headers['from'];
     $to = $parsed->headers['to'];
     $type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary;
     $attachments = array();
     $this->extract_part($parsed, $msg, $attachments);
     return array($from, $to, $msg, $attachments);
 }
コード例 #22
0
 /**
  * processes SOAP message received from client
  *
  * @param	array	$headers	The HTTP headers
  * @param	string	$data		unprocessed request data from client
  * @return	mixed	value of the message, decoded into a PHP type
  * @access   private
  */
 function parseRequest($headers, $data)
 {
     $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
     $this->requestAttachments = array();
     if (strstr($headers['content-type'], 'multipart/related')) {
         $this->debug('Decode multipart/related');
         $input = '';
         foreach ($headers as $k => $v) {
             $input .= "{$k}: {$v}\r\n";
         }
         $params['input'] = $input . "\r\n" . $data;
         $params['include_bodies'] = true;
         $params['decode_bodies'] = true;
         $params['decode_headers'] = true;
         $structure = Mail_mimeDecode::decode($params);
         foreach ($structure->parts as $part) {
             if (!isset($part->disposition) && strstr($part->headers['content-type'], 'text/xml')) {
                 $this->debug('Have root part of type ' . $part->headers['content-type']);
                 $return = parent::parseRequest($part->headers, $part->body);
             } else {
                 $this->debug('Have an attachment of type ' . $part->headers['content-type']);
                 $info['data'] = $part->body;
                 $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
                 $info['contenttype'] = $part->headers['content-type'];
                 $info['cid'] = $part->headers['content-id'];
                 $this->requestAttachments[] = $info;
             }
         }
         if (isset($return)) {
             return $return;
         }
         $this->setError('No root part found in multipart/related content');
         return;
     }
     $this->debug('Not multipart/related');
     return parent::parseRequest($headers, $data);
 }
コード例 #23
0
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
require_once 'tiki-setup.php';
$access->check_feature('feature_webmail');
$access->check_permission('tiki_p_use_webmail');
require_once 'lib/webmail/webmaillib.php';
require "lib/webmail/mimeDecode.php";
//require ("lib/webmail/pop3.php");
require "lib/webmail/net_pop3.php";
$current = $webmaillib->get_current_webmail_account($user);
//$pop3 = new POP3($current["pop"], $current["username"], $current["pass"]);
//$pop3->Open();
$pop3->connect($current["pop"]);
$pop3->login($current["username"], $current["pass"]);
$full = $pop3->getMsg($_REQUEST["msgid"]);
$smarty->assign('msgid', $_REQUEST["msgid"]);
$pop3->disconnect();
$params = array('input' => $full, 'crlf' => "\r\n", 'include_bodies' => TRUE, 'decode_headers' => TRUE, 'decode_bodies' => TRUE);
$output = Mail_mimeDecode::decode($params);
$part = $output->parts[$_REQUEST["getpart"]];
$type = $part->headers["content-type"];
$content = $part->body;
$names = explode(';', $part->headers["content-disposition"]);
$names = explode('=', $names[1]);
$file = $names[1];
header("Content-type: {$type}");
//header( "Content-Disposition: attachment; filename=$file" );
header("Content-Disposition: inline; filename={$file}");
echo "{$content}";
コード例 #24
0
ファイル: viewpart.php プロジェクト: rafaelbsd/1.2.0
            case file_exists($quarantine_dir . '/' . $message_data->date . '/' . $message_id . '/message'):
                $filename = $message_data->date . '/' . $message_id . '/message';
                break;
        }
        if (!@file_exists($quarantine_dir . '/' . $filename)) {
            die("Error: file not found\n");
        }
        $file = file_get_contents($quarantine_dir . '/' . $filename);
    }
}
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $file;
$Mail_mimeDecode = new Mail_mimeDecode($file);
$structure = $Mail_mimeDecode->decode($params);
$mime_struct = $Mail_mimeDecode->getMimeNumbers($structure);
// Make sure that part being requested actually exists
if (isset($_GET['part'])) {
    if (!isset($mime_struct[$_GET['part']])) {
        die("Part " . sanitizeInput($_GET['part']) . " not found\n");
    }
}
function decode_structure($structure)
{
    $type = $structure->ctype_primary . "/" . $structure->ctype_secondary;
    switch ($type) {
        case "text/plain":
            /*
            if (isset ($structure->ctype_parameters['charset']) &&
                strtolower($structure->ctype_parameters['charset']) == 'utf-8'
コード例 #25
0
ファイル: Base.php プロジェクト: nidhhoggr/mycoachingoffice
 function _decodeMimeMessage(&$data, &$headers, &$attachments)
 {
     global $SOAP_options;
     if (!isset($SOAP_options['Mime'])) {
         $this->_raiseSoapFault('Mime Unsupported, install PEAR::Mail::Mime', '', '', 'Server');
         return;
     }
     $params['include_bodies'] = true;
     $params['decode_bodies'] = true;
     $params['decode_headers'] = true;
     // XXX lame thing to have to do for decoding
     $decoder = new Mail_mimeDecode($data);
     $structure = $decoder->decode($params);
     if (isset($structure->body)) {
         $data = $structure->body;
         $headers = $structure->headers;
         return;
     } elseif (isset($structure->parts)) {
         $data = $structure->parts[0]->body;
         $headers = array_merge($structure->headers, $structure->parts[0]->headers);
         if (count($structure->parts) > 1) {
             $mime_parts = array_splice($structure->parts, 1);
             // prepare the parts for the soap parser
             $c = count($mime_parts);
             for ($i = 0; $i < $c; $i++) {
                 $p =& $mime_parts[$i];
                 if (isset($p->headers['content-location'])) {
                     // XXX TODO: modify location per SwA note section 3
                     // http://www.w3.org/TR/SOAP-attachments
                     $attachments[$p->headers['content-location']] = $p->body;
                 } else {
                     $cid = 'cid:' . substr($p->headers['content-id'], 1, strlen($p->headers['content-id']) - 2);
                     $attachments[$cid] = $p->body;
                 }
             }
         }
         return;
     }
     $this->_raiseSoapFault('Mime parsing error', '', '', 'Server');
 }
コード例 #26
0
 /**
  * Parses given mime HTTP response body into array. Each array element 
  * represents a change set result.
  * 
  * @param string $mimeBody The raw MIME body result.
  * 
  * @return array
  */
 public function decodeMimeMultipart($mimeBody)
 {
     $params['include_bodies'] = true;
     $params['input'] = $mimeBody;
     $mimeDecoder = new \Mail_mimeDecode($mimeBody);
     $structure = $mimeDecoder->decode($params);
     $parts = $structure->parts;
     $bodies = array();
     foreach ($parts as $part) {
         $bodies[] = $part->body;
     }
     return $bodies;
 }
コード例 #27
0
ファイル: postie-functions.php プロジェクト: donwea/nhap.org
/**
 * This function handles the basic mime decoding
 * @param string
 * @return array
 */
function DecodeMIMEMail($email)
{
    $params = array();
    $params['include_bodies'] = true;
    $params['decode_bodies'] = false;
    $params['decode_headers'] = true;
    $params['input'] = $email;
    $md = new Mail_mimeDecode($email);
    $decoded = $md->decode($params);
    if (empty($decoded->parts)) {
        $decoded->parts = array();
    }
    // have an empty array at minimum, so that it is safe for "foreach"
    return $decoded;
}
コード例 #28
0
ファイル: imap.php プロジェクト: BackupTheBerlios/z-push-svn
 function GetMessage($folderid, $id, $truncsize)
 {
     debugLog("IMAP-GetMessage: (fid: '{$folderid}'  id: '{$id}'  truncsize: {$truncsize})");
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     if ($stat) {
         $this->imap_reopenFolder($folderid);
         $mail = @imap_fetchheader($this->_mbox, $id, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $id, FT_PEEK | FT_UID);
         $mobj = new Mail_mimeDecode($mail);
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $mail, 'crlf' => "\n", 'charset' => 'utf-8'));
         $output = new SyncMail();
         // decode body to truncate it
         $body = utf8_to_windows1252($this->getBody($message));
         if (strlen($body) > $truncsize) {
             $body = substr($body, 0, $truncsize);
             $output->bodytruncated = 1;
         } else {
             $body = $body;
             $output->bodytruncated = 0;
         }
         $body = str_replace("\n", "\r\n", windows1252_to_utf8(str_replace("\r", "", $body)));
         $output->bodysize = strlen($body);
         $output->body = $body;
         $output->datereceived = isset($message->headers["date"]) ? strtotime($message->headers["date"]) : null;
         $output->displayto = isset($message->headers["to"]) ? $message->headers["to"] : null;
         $output->importance = isset($message->headers["x-priority"]) ? preg_replace("/\\D+/", "", $message->headers["x-priority"]) : null;
         $output->messageclass = "IPM.Note";
         $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : "";
         $output->read = $stat["flags"];
         $output->to = isset($message->headers["to"]) ? $message->headers["to"] : null;
         $output->cc = isset($message->headers["cc"]) ? $message->headers["cc"] : null;
         $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null;
         $output->reply_to = isset($message->headers["reply-to"]) ? $message->headers["reply-to"] : null;
         // Attachments are only searched in the top-level part
         $n = 0;
         if (isset($message->parts)) {
             foreach ($message->parts as $part) {
                 if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) {
                     $attachment = new SyncAttachment();
                     if (isset($part->body)) {
                         $attachment->attsize = strlen($part->body);
                     }
                     if (isset($part->d_parameters['filename'])) {
                         $attname = $part->d_parameters['filename'];
                     } else {
                         if (isset($part->ctype_parameters['name'])) {
                             $attname = $part->ctype_parameters['name'];
                         } else {
                             if (isset($part->headers['content-description'])) {
                                 $attname = $part->headers['content-description'];
                             } else {
                                 $attname = "unknown attachment";
                             }
                         }
                     }
                     $attachment->displayname = $attname;
                     $attachment->attname = $folderid . ":" . $id . ":" . $n;
                     $attachment->attmethod = 1;
                     $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
                     array_push($output->attachments, $attachment);
                 }
                 $n++;
             }
         }
         // unset mimedecoder & mail
         unset($mobj);
         unset($mail);
         return $output;
     }
     return false;
 }
コード例 #29
0
ファイル: maildir.php プロジェクト: karanikn/php-addressbook
 /**
  * Returns the actual SyncXXX object type.
  *
  * @param string            $folderid           id of the parent folder
  * @param string            $id                 id of the message
  * @param ContentParameters $contentparameters  parameters of the requested message (truncation, mimesupport etc)
  *
  * @access public
  * @return object/false     false if the message could not be retrieved
  */
 public function GetMessage($folderid, $id, $truncsize, $mimesupport = 0)
 {
     if ($folderid != 'root') {
         return false;
     }
     $fn = $this->findMessage($id);
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     // Parse e-mail
     $rfc822 = file_get_contents($this->getPath() . "/" . $fn);
     $message = Mail_mimeDecode::decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
     $output = new SyncMail();
     $output->body = str_replace("\n", "\r\n", $this->getBody($message));
     $output->bodysize = strlen($output->body);
     $output->bodytruncated = 0;
     // We don't implement truncation in this backend
     $output->datereceived = $this->parseReceivedDate($message->headers["received"][0]);
     $output->messageclass = "IPM.Note";
     $output->subject = $message->headers["subject"];
     $output->read = $stat["flags"];
     $output->from = $message->headers["from"];
     $Mail_RFC822 = new Mail_RFC822();
     $toaddr = $ccaddr = $replytoaddr = array();
     if (isset($message->headers["to"])) {
         $toaddr = $Mail_RFC822->parseAddressList($message->headers["to"]);
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $Mail_RFC822->parseAddressList($message->headers["cc"]);
     }
     if (isset($message->headers["reply_to"])) {
         $replytoaddr = $Mail_RFC822->parseAddressList($message->headers["reply_to"]);
     }
     $output->to = array();
     $output->cc = array();
     $output->reply_to = array();
     foreach (array("to" => $toaddr, "cc" => $ccaddr, "reply_to" => $replytoaddr) as $type => $addrlist) {
         foreach ($addrlist as $addr) {
             $address = $addr->mailbox . "@" . $addr->host;
             $name = $addr->personal;
             if (!isset($output->displayto) && $name != "") {
                 $output->displayto = $name;
             }
             if ($name == "" || $name == $address) {
                 $fulladdr = w2u($address);
             } else {
                 if (substr($name, 0, 1) != '"' && substr($name, -1) != '"') {
                     $fulladdr = "\"" . w2u($name) . "\" <" . w2u($address) . ">";
                 } else {
                     $fulladdr = w2u($name) . " <" . w2u($address) . ">";
                 }
             }
             array_push($output->{$type}, $fulladdr);
         }
     }
     // convert mime-importance to AS-importance
     if (isset($message->headers["x-priority"])) {
         $mimeImportance = preg_replace("/\\D+/", "", $message->headers["x-priority"]);
         if ($mimeImportance > 3) {
             $output->importance = 0;
         }
         if ($mimeImportance == 3) {
             $output->importance = 1;
         }
         if ($mimeImportance < 3) {
             $output->importance = 2;
         }
     }
     // Attachments are only searched in the top-level part
     $n = 0;
     if (isset($message->parts)) {
         foreach ($message->parts as $part) {
             if ($part->ctype_primary == "application") {
                 $attachment = new SyncAttachment();
                 $attachment->attsize = strlen($part->body);
                 if (isset($part->d_parameters['filename'])) {
                     $attname = $part->d_parameters['filename'];
                 } else {
                     if (isset($part->ctype_parameters['name'])) {
                         $attname = $part->ctype_parameters['name'];
                     } else {
                         if (isset($part->headers['content-description'])) {
                             $attname = $part->headers['content-description'];
                         } else {
                             $attname = "unknown attachment";
                         }
                     }
                 }
                 $attachment->displayname = $attname;
                 $attachment->attname = $id . ":" . $n;
                 $attachment->attmethod = 1;
                 $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
                 array_push($output->attachments, $attachment);
             }
             $n++;
         }
     }
     return $output;
 }
コード例 #30
0
ファイル: Base.php プロジェクト: test3metizsoft/test
 function _decodeMimeMessage(&$data, &$headers, &$attachments)
 {
     if (!@(include_once 'Mail/mimeDecode.php')) {
         return $this->_raiseSoapFault('MIME messages are unsupported, the Mail_Mime package is not installed');
     }
     $params['include_bodies'] = true;
     $params['decode_bodies'] = true;
     $params['decode_headers'] = true;
     // Lame thing to have to do for decoding.
     $decoder = new Mail_mimeDecode($data);
     $structure = $decoder->decode($params);
     if (isset($structure->body)) {
         $data = $structure->body;
         $headers = $structure->headers;
         return;
     } elseif (isset($structure->parts)) {
         $data = $structure->parts[0]->body;
         $headers = array_merge($structure->headers, $structure->parts[0]->headers);
         if (count($structure->parts) <= 1) {
             return;
         }
         $mime_parts = array_splice($structure->parts, 1);
         // Prepare the parts for the SOAP parser.
         for ($i = 0, $c = count($mime_parts); $i < $c; $i++) {
             $p = $mime_parts[$i];
             if (isset($p->headers['content-location'])) {
                 // TODO: modify location per SwA note section 3
                 // http://www.w3.org/TR/SOAP-attachments
                 $attachments[$p->headers['content-location']] = $p->body;
             } else {
                 $cid = 'cid:' . substr($p->headers['content-id'], 1, -1);
                 $attachments[$cid] = $p->body;
             }
         }
         return;
     }
     $this->_raiseSoapFault('Mime parsing error', '', '', 'Server');
 }