{"id":4661,"date":"2023-06-14T11:39:49","date_gmt":"2023-06-14T03:39:49","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=4661"},"modified":"2023-06-14T11:39:49","modified_gmt":"2023-06-14T03:39:49","slug":"postfix-%e4%bd%bf%e7%94%a8%e8%99%9b%e6%93%ac%e4%bd%bf%e7%94%a8%e8%80%85-4-%e4%bf%a1%e4%bb%b6%e8%a7%a3%e6%9e%90%ef%bc%8c%e8%ae%93%e7%b6%b2%e9%a0%81%e7%9c%8b%e5%be%97%e6%87%82","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=4661","title":{"rendered":"Postfix \u4f7f\u7528\u865b\u64ec\u4f7f\u7528\u8005 \u2013 4. \u4fe1\u4ef6\u89e3\u6790\uff0c\u8b93\u7db2\u9801\u770b\u5f97\u61c2"},"content":{"rendered":"<p>--<\/p>\n<p>\u9019\u662f\u4e00\u5c01\u7531 Google Gmail \u5bc4\u51fa\u7684\u4fe1\u4ef6\u539f\u59cb\u78bc\uff0c\u4e3b\u65e8\u662f sdf \u5167\u5bb9 sdf<\/p>\n<pre class=\"height-set:true height:400 lang:default decode:true \">From pc@hoyo.idv.tw  Sun May 20 14:01:45 2018\r\nReceived: from mail-pl0-x236.google.com (unknown [IPv6:2607:f8b0:400e:c01::236])\r\n\tby sm.hoyo.idv.tw (Postfix) with ESMTP id C94B9C2B30A2C\r\n\tfor &lt;oenru2@sm.hoyo.idv.tw&gt;; Sun, 20 May 2018 06:01:44 +0000 (UTC)\r\nDKIM-Filter: OpenDKIM Filter v2.11.0 sm.hoyo.idv.tw C94B9C2B30A2C\r\nAuthentication-Results: sm.hoyo.idv.tw;\r\n\tdkim=pass (2048-bit key) header.d=hoyo-idv-tw.20150623.gappssmtp.com header.i=@hoyo-idv-tw.20150623.gappssmtp.com header.b=\"0n6iLjVc\"\r\nReceived: by mail-pl0-x236.google.com with SMTP id ay10-v6so6907782plb.1\r\n        for &lt;oenru2@sm.hoyo.idv.tw&gt;; Sat, 19 May 2018 23:01:44 -0700 (PDT)\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed\/relaxed;\r\n        d=hoyo-idv-tw.20150623.gappssmtp.com; s=20150623;\r\n        h=mime-version:from:date:message-id:subject:to;\r\n        bh=zmipbNoRU4Htj2PidOeINnUwMC3J2OqqDT0EdnBpO08=;\r\n        b=0n6iLjVcN\/rZCA1gQDpF3kxCdnzz2JQZ\/mhpx6nV0G4MIlBdeCg4Mx+RI3uGwCH1\/Z\r\n         mfrPSYZA9ncuTyNlry0sMH69sk5zlVx8LI0PJFsSruyBSDtShq6UmYG2mCIJvZYrLlRL\r\n         3nvM9ngH68JpgD757YaiVhOm79cAf57qAvEWo7e6+riwi5mbF2CowHc+p4EmBm9t763b\r\n         lM7SLR3ColpTCDywstq6eZBeEAkB\/EFlkCAoE8y2NOKgwx0VT97GwLpFxWIDMRP2assr\r\n         GSeSauui1zpHmpGRZEnwt7wUTT3HwiDq9PsOtvl+vPmHUxeT79Xkd00\/x\/hU5X8X+AJy\r\n         K4yA==\r\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed\/relaxed;\r\n        d=1e100.net; s=20161025;\r\n        h=x-gm-message-state:mime-version:from:date:message-id:subject:to;\r\n        bh=zmipbNoRU4Htj2PidOeINnUwMC3J2OqqDT0EdnBpO08=;\r\n        b=rviNB4QgamZtGALFTsAHCgBQ\/Wp4cMphhOkMYweAIdvOyk3MysPfWd4LbykdrQF64P\r\n         w+BDnzLZhuRWYFQKJvclkWUZn8CLEnzlfFos69CjbXKXEBy+z363SUQFZ\/6CArYC7+A2\r\n         sQAA118UStijV1XWnrcRT\/ceGd\/+n1mB3bGCqHE1gjb3LurByzDYeX9rOqqR7ZgLA3l7\r\n         o89VBl\/5TXDWE6xu22qWH3tyIRf\/32NwMQAVkO7QReFyqbA9wrbUMVqr\/EFPDDerALJu\r\n         E2rRggwoxlApJR0+ha\/RmMWfAxjNXNFxcQtUm0WyQO5DJA90dTAHnWUVPjVSC1eMN7bx\r\n         LEbw==\r\nX-Gm-Message-State: ALKqPwfwoP\/JRc6Y0ecepyjG0h7QrVq0v2mjHOlXNuz3uxuFUgUWnmh4\r\n\tg7Tx\/pY2EuoZUD7ThKmdGgjm0ZRwc4M+mRls7dcrOfgD\r\nX-Google-Smtp-Source: AB8JxZrm9IAfiocxS9p7XvPFJMCBP3tD8bpUuR57yCkbKJ4\/dHRVHA9B3eIqV1svUQCqR7BRj6JIt26G8J3Yjz8DEck=\r\nX-Received: by 2002:a17:902:3103:: with SMTP id w3-v6mr15405047plb.37.1526796103596;\r\n Sat, 19 May 2018 23:01:43 -0700 (PDT)\r\nMIME-Version: 1.0\r\nReceived: by 10.100.181.171 with HTTP; Sat, 19 May 2018 23:01:43 -0700 (PDT)\r\nFrom: =?UTF-8?B?6buD5b+X6LOi?= &lt;pc@hoyo.idv.tw&gt;\r\nDate: Sun, 20 May 2018 14:01:43 +0800\r\nMessage-ID: &lt;CAJ060EoTYq_UGkp-SVkvh6KUdk2JOBHFUrWPwkokijNg0sB9XA@mail.gmail.com&gt;\r\nSubject: sdf\r\nTo: oenru2@sm.hoyo.idv.tw\r\nContent-Type: multipart\/alternative; boundary=\"000000000000664f74056c9ceba4\"\r\n\r\n--000000000000664f74056c9ceba4\r\nContent-Type: text\/plain; charset=\"UTF-8\"\r\n\r\nsdf\r\n\r\n--000000000000664f74056c9ceba4\r\nContent-Type: text\/html; charset=\"UTF-8\"\r\n\r\n&lt;div dir=\"ltr\"&gt;sdf&lt;br&gt;&lt;\/div&gt;\r\n\r\n--000000000000664f74056c9ceba4--<\/pre>\n<p>SMTP \u672c\u4f86\u5728\u6536\u5230\u9019\u5c01\u4fe1\u6642\uff0c\u6703\u89e3\u6790 To: \u7b49\u5167\u5bb9\u78ba\u5b9a\u9019\u5c01\u4fe1\u662f\u8981\u7d66\u8ab0\uff0c\u7136\u5f8c\u5c07\u4fe1\u4ef6\u6b78\u5230\u8a72\u4f7f\u7528\u8005\u7684\u6a94\u6848\u6216\u8cc7\u6599\u593e\u5167\uff0c\u4f7f\u7528\u8005\u4f7f\u7528\u8b80\u4fe1\u8edf\u9ad4\u6642\u5c31\u6703\u9032\u884c\u5167\u5bb9\u89e3\u8b80\uff0c\u5c07\u5bc4\u4fe1\u4eba\u3001\u6536\u4ef6\u4eba\u3001\u4e3b\u65e8\u3001\u5167\u5bb9\u7b49\u4e00\u822c\u8cc7\u8a0a\u5217\u51fa<\/p>\n<p>\u53ef\u662f\u7576\u6211\u5011\u8981\u628a\u4fe1\u4ef6\u5448\u73fe\u5728\u7db2\u9801\u4e0a\u6642\uff0c\u5c31\u5fc5\u9808\u5148\u628a\u4fe1\u4ef6\u5167\u5bb9\u300c\u7ffb\u8b6f\u300d\u6210\u7db2\u9801\u53ef\u4ee5\u986f\u793a\u7684\u7d50\u679c\uff0c\u4f8b\u5982\u00a0?UTF-8?B?6buD5b+X6LOi?= \u9019\u7a2e RFC2047 \u7684\u7de8\u78bc\u65b9\u5f0f\uff0c\u9084\u6709\u5c07\u4e0d\u540c\u7684\u5b57\u5143\u7de8\u78bc\u7d71\u4e00\u8f49\u6210 UTF-8 \u7b49\u7b49\u7b49\u4e4b\u985e\u7684\u5de5\u4f5c<\/p>\n<p>--<\/p>\n<h2>PHP \u7684\u4fe1\u4ef6\u89e3\u6790\u51fd\u5f0f\u5eab<\/h2>\n<ul>\n<li><a href=\"http:\/\/php.net\/manual\/en\/ref.mailparse.php\" target=\"_blank\" rel=\"noopener\">Mailparse Functions<\/a><\/li>\n<\/ul>\n<p>\u5e78\u904b\u7684\u662f PHP \u4e0d\u6127\u662f\u6210\u719f\u7684\u8a9e\u8a00\uff0c\u4ec0\u9ebc\u98a8\u6d6a\u90fd\u898b\u904e\uff0c\u91dd\u5c0d\u4fe1\u4ef6\u6709\u4e86\u5c08\u9580\u7684\u89e3\u6790\u51fd\u5f0f\u5eab\uff0c\u4e0d\u5e78\u7684\u662f\u9019\u662f\u00a0PECL \u6240\u4ee5\u9700\u8981\u53e6\u5916\u5b89\u88dd\u8f09\u5165<\/p>\n<p>--<\/p>\n<h2>\u5b89\u88dd\u3001\u8f09\u5165\u00a0Mailparse<\/h2>\n<ul>\n<li><a href=\"https:\/\/ma.ttias.be\/installing-the-pecl-pear-mailparse-module-for-php-on-centos\/\" target=\"_blank\" rel=\"noopener noreferrer\">Installing the PECL\/PEAR mailparse module for PHP on CentOS<\/a><\/li>\n<li><a href=\"https:\/\/www.howtoinstall.me\/ubuntu\/18-04\/php-mailparse\/\" target=\"_blank\" rel=\"noopener\">How to Install php-mailparse in Ubuntu 18.04<\/a><\/li>\n<\/ul>\n<p><strong>Ubuntu<\/strong><\/p>\n<pre class=\"lang:default decode:true \"># apt install php-dev\r\n# apt install php-mailparse<\/pre>\n<p><strong>CentOS 7 + PHP 7.2<\/strong><\/p>\n<pre class=\"lang:default decode:true\"># yum install php-pear php-devel\r\n# pear channel-update pecl.php.net\r\n# yum install http:\/\/dl.fedoraproject.org\/pub\/epel\/7\/x86_64\/Packages\/r\/re2c-0.14.3-2.el7.x86_64.rpm\r\n# pear install pecl\/mailparse<\/pre>\n<p><strong>CentOS 6 + php5.3<\/strong><\/p>\n<p>\u5b89\u88dd mailparse<\/p>\n<pre class=\"lang:default decode:true\"># yum install re2c\r\n# pear install pecl\/mailparse-2.1.6<\/pre>\n<p>--<\/p>\n<p>\u8f09\u5165 extension \uff0c\u6a94\u6848\u5fc5\u9808\u81ea\u5df1\u7522\u751f<\/p>\n<pre class=\"lang:default decode:true \">vi \/etc\/php.d\/40-mailparse.ini\r\nextension=mailparse.so<\/pre>\n<p>\u91cd\u65b0\u555f\u52d5 httpd<\/p>\n<pre class=\"lang:default decode:true \"># systemctl restart httpd<\/pre>\n<p>CentOS 6<\/p>\n<pre class=\"lang:default decode:true\">\/etc\/rd.d\/init.d\/httpd restart<\/pre>\n<p>--<\/p>\n<h2>Hoyo \u81ea\u5df1\u5beb\u7684\u89e3\u6790\u7a0b\u5f0f<\/h2>\n<p>\u672c\u4f86\u662f\u7528\u00a0<a href=\"https:\/\/github.com\/peterkahl\/MIME-mail-parser\" target=\"_blank\" rel=\"noopener\">MIME-mail-parser<\/a>\u00a0\u9019\u500b\u5225\u4eba\u5beb\u7684\u76f4\u63a5\u5957\uff0c\u5f8c\u4f86\u56e0\u70ba X \u548c XX \u4ee5\u53ca XXX \u7a2e\u7a2e\u7684\u539f\u56e0\uff0c\u5728\u6d88\u97f3\u4e86\u7121\u6578\u6b21\u4e4b\u5f8c\u679c\u65b7\u81ea\u5df1\u5beb<\/p>\n<pre class=\"height-set:true height:400 lang:php decode:true \">&lt;?php\r\nmb_internal_encoding('UTF-8');\r\n\r\n\r\nclass HoyoMailParser\r\n{\r\n    function __construct($a)\r\n    {\r\n        define( 'FilePath', '\/tmp' );\r\n\r\n        $info = array();\r\n        $section = array();\r\n        $header = array();\r\n        $j = 0;\r\n\r\n        $mail = mailparse_msg_create();\r\n        mailparse_msg_parse($mail, $a);\r\n        $struct = mailparse_msg_get_structure($mail);\r\n        \/\/print_r($struct);\r\n\r\n        foreach($struct as $st) {\r\n            $section[] = mailparse_msg_get_part($mail, $st);\r\n        }\r\n\r\n        foreach( $section as $k=&gt;$s ){\r\n            $info[] = mailparse_msg_get_part_data($s);\r\n        }\r\n        \/\/print_r($info);\r\n\r\n        \/\/ \u4fe1\u4ef6 header\r\n        $h = $info[0]['headers'];\r\n        foreach( $h as $k=&gt;$v ){\r\n            \/\/echo $v .\"---\\r\\n\";\r\n            if ( is_string($v) ) $header[$k] = mb_decode_mimeheader($v);\r\n        }\r\n        $this-&gt;Header = $header;\r\n        \/\/print_r( $header );\r\n\r\n        for( $i=0; $i&lt;count($struct) ;$i++ ){\r\n\r\n            \/\/ \u63a5\u6536 part data\r\n            $GLOBALS[\"catchData\"] = '';\r\n            mailparse_msg_extract_part($section[$i], $a, \"catchData\");\r\n            $tempData = $GLOBALS[\"catchData\"];\r\n\r\n            \/\/  [transfer-encoding] =&gt; 8bit\r\n            if ( $info[$i]['headers']['transfer-encoding'] =='8bit' ){\r\n                $tempData = mb_decode_mimeheader($tempData);\r\n            }\r\n\r\n            \/\/ \u6587\u5b57\u7de8\u78bc\u8f49\u63db\r\n            if ( strtolower($info[$i]['charset']) !='utf-8' ){\r\n                $tempData = mb_convert_encoding( $tempData, \"UTF-8\", $info[$i]['charset'] );\r\n            }\r\n\r\n            \/\/ HTML\r\n            if ( preg_match('\/text\\\/html\/i', $info[$i]['headers']['content-type'] ) ){\r\n                $this-&gt;Body['HTML'] = $tempData;\r\n            }\r\n\r\n            \/\/ \u7d14\u6587\u5b57\r\n            if ( preg_match('\/text\\\/plain\/i', $info[$i]['headers']['content-type'] ) ){\r\n                $this-&gt;Body['Plain'] = $tempData;\r\n            }\r\n\r\n            \/\/ \u6a94\u6848\u9644\u4ef6\r\n            if ( $info[$i]['headers']['x-attachment-id'] !='' ){\r\n\r\n                \/\/ \u5132\u5b58\u6a94\u6848\r\n                $ta = explode('.', mb_decode_mimeheader($info[$i]['headers']['content-type']) );\r\n                $afs = trim( array_pop($ta), '\"' );\r\n                file_put_contents( FilePath .'\/'. $info[$i]['headers']['x-attachment-id'] .'.'. $afs , $tempData);\r\n\r\n                \/\/ \u662f\u5426\u662f\u5167\u5d4c\u5716\u7247\r\n                if ( preg_match('\/inline\/i', $info[$i]['headers']['content-disposition']) ){\r\n                    $this-&gt;Body['HTML'] = str_replace('cid:'.$info[$i]['headers']['x-attachment-id'], 'data:'.$info[$i]['content-type'].';base64,'. base64_encode($GLOBALS[\"catchData\"]), $this-&gt;Body['HTML']);\r\n\r\n                    $this-&gt;Body['File'][$j] = array(\r\n                        'Filename'=&gt; mb_decode_mimeheader($info[$i]['disposition-filename']),\r\n                        'FileContent' =&gt; base64_encode($GLOBALS[\"catchData\"])\r\n                    );\r\n                    $j++;\r\n                }\r\n\r\n                \/\/ \u4e00\u822c\u9644\u4ef6\r\n                if ( $info[$i]['content-disposition'] =='attachment' ) {\r\n\r\n                    $this-&gt;Body['File'][$j] = array(\r\n                        'Filename'=&gt; mb_decode_mimeheader($info[$i]['disposition-filename']),\r\n                        'FileContent' =&gt; base64_encode($GLOBALS[\"catchData\"])\r\n                    );\r\n                    $j++;\r\n                }\r\n            }\r\n        }\r\n\r\n        return $this;\r\n    }\r\n}\r\n\r\nfunction catchData($part) {\r\n    \/\/ \u6a94\u6848\u5927\u65bc ?? \u6216\u591a\u6b21\u57f7\u884c\u76f4\u5230\u7d50\u675f  \u56e0\u6b64\u5728\u6b64\u53ea\u8981\u5c07\u8cc7\u6599\u62fc\u63a5\u5373\u53ef\r\n    $GLOBALS[\"catchData\"] .= $part;\r\n}<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4661\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;838&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- \u9019\u662f\u4e00\u5c01\u7531 Google...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4661\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;838&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4661"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4661"}],"version-history":[{"count":11,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4661\/revisions"}],"predecessor-version":[{"id":12338,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4661\/revisions\/12338"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}