PEAR::Mail_mimeDecodeã§æ¥æ¬èªã®ã¡ã¼ã«æ·»ä»ãã¡ã¤ã«ååå¾
ã¡ã¼ã«ã«æ·»ä»ãã¦æ¥æ¬èªãå
¥ã£ãå称ã®ãã¡ã¤ã«éã£ã¦ãPEAR::Mail_mimeDecodeãã§åå¾ãããã¨ãããæååããã¦ãããã
æ£ç¢ºã«ã¯ãã³ã¼ããããã¦ãªãã£ãã¨ãããããã
ãPEAR::Mail_mimeDecodeããåå ã¨ããããã§ããªãã£ãã¨ãããããã
ãã¹ãããç°å¢ã§ã¯
$decoder = new Mail_mimeDecode($mail); $decoded = $decoder->decode($params); $fileName = $decoded->parts[$idx]->ctype_parameters['name'];
ã£ã¦ãã£ã¦åã£ã¦ããã$fileNameããæå·ç¶æ
ã
ãã®å¾ã«
$fileName = mb_convert_encoding($fileName, 'UTF-8', 'ISO-2022-JP');
ã¨ããã£ã¦ãå
¨ãæå³ç¡ãã
ãã©åãã¦ãæåã®ä¸ã«è¦è¦ããããããªæååãæ··ãã£ã¦ããããªã¼
ã£ã¦äºã§ä¸åº¦URLãã³ã¼ããã¦ããæåã³ã¼ããã¨ã³ã³ã¼ããã¦ãããã¨ã«ã
$fileName = urldecode($fileName); $fileName = mb_convert_encoding($fileName, 'UTF-8', 'ISO-2022-JP');
ã£ã¦ãã£ãããã¾ããã£ãã
ãã¨
- ãctype_secondaryããããã欲ããæ¡å¼µåãåããªã
- ãã¡ã¤ã«åã¯ã¡ã¼ã«ã¿ã¤ãã«ããåå¾ãã¦2ã¤ç®ä»¥éã¯é£çªä»ãã
- ã¡ã¼ã«ã¿ã¤ãã«ãæªè¨å®ã®å ´åã«æ·»ä»ãã¡ã¤ã«ã®ãªãªã¸ãã«å称使ã
ã¨ãã£ã¦ãããã¨ãããæçµçã«ã¯ä»¥ä¸ã®ãããªæãã«ã
// ãã³ã¼ãå¦ç $decoder = new Mail_mimeDecode($mail); $decoded = $decoder->decode($params); // ãããé¨åãã¼ã¿åå¾ $headers = $decoded->headers; $headFrom = mb_convert_encoding($headers['from'], 'UTF-8', 'ISO-2022-JP'); preg_match('/[0-9a-zA-Z_\.\-]+@[0-9a-zA-Z_\.\-]+/', $headFrom, $matchs); $from = $matchs[0]; $to = mb_convert_encoding($headers['to'], 'UTF-8', 'ISO-2022-JP'); $subject = mb_convert_encoding($headers['subject'], 'UTF-8', 'ISO-2022-JP'); $file = null; $fileType = null; $fileName = null; if (!empty($decoded->parts)) { // bodyãåå¾ $body = $decoded->parts[0]->body; $body = mb_convert_encoding($body, 'UTF-8', 'ISO-2022-JP'); $index = 1; for ($idx = 1; $idx < count($decoded->parts); $idx++) { $file = $decoded->parts[$idx]->body; //$fileType = $decoded->parts[$idx]->ctype_secondary; â ä»åã¯ä½¿ããªãããå¥æ¹æ³ã§æ¡å¼µåã$extããåå¾ã $name = ''; $ext = ''; $indexed = false; $fileName = isset($decoded->parts[$idx]->ctype_parameters['name']) ? $decoded->parts[$idx]->ctype_parameters['name'] : $decoded->parts[$idx]->ctype_parameters['name*']; // â ãã¡ã¤ã«åãæ¥æ¬èªã®å ´åã¯ãname*ãã®æ¹ã«å ¥ã£ã¦ãã $tmpArray = explode('\'\'', $fileName, 2); // â ã''ãã®å·¦å´ã«æåã³ã¼ãå ¥ã£ã¦ããã©ä»åã¯ä»¥ä¸ã«ãã¿æ¸ãã§ã if (count($tmpArray) > 1) { $fileName = array_pop($tmpArray); $fileName = urldecode($fileName); $fileName = mb_convert_encoding($fileName, 'UTF-8', 'ISO-2022-JP'); } $tmpArray = explode('.', $fileName, 2); if (count($tmpArray) > 1) { $ext = '.'.array_pop($tmpArray); } //$name = array_pop($tmpArray); â ãããåãã¦ããã¡ã¤ã«åãªãã§ä»åã¯ä½¿ããªãã if ($subject == '') { $name = preg_replace('/[.].+/', '', $fileName); } else { $name = $subject; if ($index == 1) { $name = $subject; } else { $name = "{$subject}({$index})"; } $indexed = true; } /********************/ /* ããã«å®å¦çè¨è¿° */ /********************/ if ($indexed) { $index++; } } } else { // æ·»ä»ãã¡ã¤ã«ãç¡ãå ´å $body = $decoded->body; /********************/ /* ããã«å®å¦çè¨è¿° */ /********************/ }
å人çãªè¦ä»¶ããããçµãã§ããã©ã¾ãæµãã¯ã