Tag: PHP デコメール クラス

概要

  1. メールデータをMail_mimeDecodeでdecode
  2. Null_Mimeクラスで各種データ取り出し

サンプル

  • http://null.style.coocan.jp/phpclass/deco/test.php
  • サンプルソース
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html lang="ja">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <title>メール解析結果</title>
    <style type="text/css">
    <!--
    h1 { background: #adf; margin: 1px; }
    h2 { background: #cdf; margin: 1px; }
    h3 { background: #ddf; margin: 1px; }
    -->
    </style>
    </head>
    <body>
    <h1>メール解析結果</h1>
    <?php
    
    ini_set('display_errors', '1');
    error_reporting(E_ALL);
    set_include_path('..' . PATH_SEPARATOR . '/usr/local/lib/php');
    
    require_once 'Null/Mime.php';
    
    $filename = '20071004100450';
    if (!file_exists($filename)) {
        exit('file not found');
    }
    
    $nmail = new Null_Mime();
    if (!$nmail->loadFromFile($filename)) {
        exit('parse error');
    }
    
    $date = $nmail->getDate();
    $from = $nmail->getFrom();
    $from = $from === false ? false : $nmail->getAddress($from);
    $from = $from === false ? '' : implode(',', $from);
    $to   = $nmail->getTo();
    $to   = $to === false ? false : $nmail->getAddress($to);
    $to   = $to === false ? '' : implode(',', $to);
    printf("<h2>Date:</h2>%s<br>%s<br>\n", $date, date('Y/m/d H:i:s', strtotime($date)));
    printf("<h2>From:</h2>%s<br>\n", $from);
    printf("<h2>To:</h2>%s<br>\n", $to);
    printf("<h2>Subject:</h2>%s<br>\n", $nmail->getSubject());
    printf("<h2>Type:</h2>%s<br>\n", $nmail->getContentTypeSecondary());
    printf("<h2>TextBody:</h2>%s<br>\n", nl2br($nmail->getTextBody()));
    
    $html = $nmail->getHtmlBody();
    $html = preg_replace('/(cid:([^\">\ ]+))/', 'tmp/$2', $html);
    printf("<h2>HtmlBody:</h2>%s<br>\n", $html);
    
    echo "<h2>Attachment:</h2>\n";
    $res = $nmail->getAttachmentFiles();
    if (count($res) > 0) {
        foreach ($res as $file) {
            printf("<h3>%s</h3>\n", $file);
            $img = $nmail->getAttachmentFile($file);
            $tmp = sprintf('tmp/%s', $file);
            file_put_contents($tmp, $img);
            printf("<img src=\"tmp/%s\">\n", $file);
        }
    }
    
    echo "<h2>Content:</h2>\n";
    $res = $nmail->getContentFiles();
    if (count($res) > 0) {
        foreach ($res as $file) {
            printf("<h3>%s</h3>\n", $file);
            $img = $nmail->getContentFile($file);
            $tmp = sprintf('tmp/%s', $file);
            file_put_contents($tmp, $img);
            printf("<img src=\"tmp/%s\">\n", $file);
        }
    }
    
    ?>
    </body>
    </html>

添付ファイル: fileMime.php 327件 [詳細]

Last-modified: 2009-07-31 (金) 18:19:22 (2945d)