{"id":943,"date":"2021-11-09T17:42:02","date_gmt":"2021-11-09T08:42:02","guid":{"rendered":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/?p=943"},"modified":"2021-11-17T16:59:49","modified_gmt":"2021-11-17T07:59:49","slug":"post-943","status":"publish","type":"post","link":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/archives\/943","title":{"rendered":"\u96fb\u5b50\u30e1\u30fc\u30eb\u3068\u9023\u52d5\u3059\u308b\u30b7\u30b9\u30c6\u30e0\u306e\u958b\u767a"},"content":{"rendered":"<p>\u5c0f\u5b66\u6821\u304b\u3089\u306e\u9023\u7d61\u304c\u96fb\u5b50\u30e1\u30fc\u30eb\u306b\u306a\u308a\u3001\u914d\u5e03\u7269\u304cPDF\u30d5\u30a1\u30a4\u30eb\u306b\u306a\u308a\u307e\u3057\u305f\u3002PDF\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u308b\u306e\u304c5\u65e5\u4ee5\u5185\u3067\u3001\u4fdd\u5b58\u3059\u308b\u306e\u3092\u5fd8\u308c\u308b\u3068\u9762\u5012\u306a\u3053\u3068\u306b\u306a\u308a\u305d\u3046\u3067\u3059\u3002\u307e\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u5185\u5bb9\u3068\u7121\u95a2\u4fc2\u3067\u3001\u63a2\u3059\u306e\u304c\u5927\u5909\u305d\u3046\u306a\u306e\u3067\u96fb\u5b50\u30e1\u30fc\u30eb\u3092\u81ea\u52d5\u7684\u306b\u51e6\u7406\u3059\u308b\u30b7\u30b9\u30c6\u30e0\u3092\u3064\u304f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\u5bb6\u5ead\u306e\u5c45\u9593\u306e\u30d1\u30bd\u30b3\u30f3\u306e\u304a\u6c17\u306b\u5165\u308a\u306b\u3044\u308c\u3066\u304a\u3051\u3070\u7c21\u5358\u306b\u30c1\u30a7\u30c3\u30af\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u8981\u4ef6<\/h2>\n<ul>\n<li>\u7279\u5b9a\u30a2\u30c9\u30ec\u30b9\u304b\u3089\u306e\u96fb\u5b50\u30e1\u30fc\u30eb\u3092\u53d7\u4fe1\u3059\u308b<\/li>\n<li>\u96fb\u5b50\u30e1\u30fc\u30eb\u5185\u306e\u30ea\u30f3\u30af\u3092\u691c\u51fa\u3057\u3066\u3001\u30ea\u30f3\u30af\u5148\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/li>\n<li>\u30a6\u30a7\u30d6\u3067\u96fb\u5b50\u30e1\u30fc\u30eb\u3068PDF\u3092\u8868\u793a\u3059\u308b<\/li>\n<\/ul>\n<h2>\u30d5\u30a1\u30a4\u30eb\u69cb\u6210<\/h2>\n<ul>\n<li>\n<h4>receive.php<\/h4>\n<p>procmail\u306b\u3088\u3063\u3066\u8d77\u52d5\u3055\u308c\u308b\u3002\u6a19\u6e96\u5165\u529b\u304b\u3089\u30e1\u30fc\u30eb\u3092\u53d7\u3051\u53d6\u308a\u3001\u6307\u5b9a\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4fdd\u5b58\u3059\u308b\u3002\u30e1\u30fc\u30eb\u672c\u6587\u4e2d\u306ePDF\u3078\u306e\u30ea\u30f3\u30af\u3092\u63a2\u3057\u3066\u3001\u305d\u308c\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002\u73fe\u5728\u306e\u3068\u3053\u308d\u8907\u6570\u306ePDF\u30d5\u30a1\u30a4\u30eb\u304c\u542b\u307e\u308c\u308b\u3053\u3068\u306f\u306a\u3044\u304c\u3001\u305d\u3053\u307e\u3067\u306f\u5bfe\u5fdc\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3002<\/li>\n<li>\n<h4>index.php<\/h4>\n<p>\u53d7\u4fe1\u3057\u305f\u30e1\u30fc\u30eb\u306e\u4e00\u89a7\u3092\u8868\u793a\u3059\u308b\u3002\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u304c\u8d77\u52d5\u3059\u308b\u3002\u30e1\u30fc\u30eb\u4fdd\u5b58\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4e2d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u3001\u65b0\u3057\u3044\u9806\u306b\u8868\u793a\u3059\u308b\u3002<\/li>\n<li>\n<h4>functions.php<\/h4>\n<p>\u30e1\u30fc\u30eb\u306e\u5185\u5bb9\u3092\u89e3\u6790\u3059\u308b\u95a2\u6570\u3001\u30e1\u30fc\u30eb\u30fbPDF\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u8a2d\u5b9a\u306a\u3069\u3001receive.php\u3068index.php\u3067\u5171\u901a\u3059\u308b\u51e6\u7406\u3092\u66f8\u304f\u3002<\/li>\n<\/ul>\n<h2>\u30b3\u30fc\u30c9<\/h2>\n<h3>\/var\/www\/mailsys<\/h3>\n<p>\u3053\u308c\u3092\u30b7\u30b9\u30c6\u30e0\u306e\u57fa\u672c\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3068\u3059\u308b\u3002\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc(apache)\u3068\u30e1\u30fc\u30eb\u53d7\u4fe1\u8005\u304c\u8aad\u307f\u66f8\u304d\u3067\u304d\u308b\u3088\u3046\u306a\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u304c\u5fc5\u8981\u3002<\/p>\n<h3>.procmail<\/h3>\n<p>\u5c0f\u5b66\u6821\u304b\u3089\u306e\u304a\u77e5\u3089\u305b\u30e1\u30fc\u30eb\u3092\u53d7\u4fe1\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u306e\u30db\u30fc\u30e0\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u304a\u304f\u3002<\/p>\n<pre class=\"code\">:0 Hc\n* ^From:.*xxxxx@mamail.jp\n|\/usr\/bin\/php -f \/var\/www\/mailsys\/receive.php\n<\/pre>\n<p>:0 \u306b\u7d9a\u304fH\u306f\u30e1\u30fc\u30eb\u306e\u30d8\u30c3\u30c0\u30fc\u90e8\u5206\u3060\u3051\u3092\u632f\u308a\u5206\u3051\u6761\u4ef6\u306b\u4f7f\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002c\u306f\u30e1\u30fc\u30eb\u306e\u30b3\u30d4\u30fc\u3092\u632f\u308a\u5206\u3051\u306e\u5bfe\u8c61\u3068\u3059\u308b\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002c\u304c\u3064\u3044\u3066\u3044\u306a\u3044\u3068\u51e6\u7406\u306b\u5931\u6557\u3057\u305f\u3068\u304d\u306b\u5931\u308f\u308c\u3066\u3057\u307e\u3046\u3002<br \/>\n*\u306b\u7d9a\u304f^From:.*xxxxx@mamail.jp\u306f\u632f\u308a\u5206\u3051\u6761\u4ef6\u3092\u610f\u5473\u3059\u308b\u3002^From\u3067\u9001\u4fe1\u5143\u304c\u4e00\u81f4\u3059\u308b\u3082\u306e\u3092\u632f\u308a\u5206\u3051\u308b\u3002<br \/>\n|\u306b\u7d9a\u304f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u6a19\u6e96\u5165\u529b\u306b\u30e1\u30fc\u30eb\u3092\u6e21\u3059\u3002\u4eca\u56de\u306fPHP\u3067\u66f8\u3044\u305freceive.php\u306e\u6a19\u6e96\u5165\u529b(STDIN)\u306b\u30e1\u30fc\u30eb\u672c\u6587\u304c\u6e21\u3055\u308c\u308b\u3002<\/p>\n<h3>http.conf<\/h3>\n<p><pre class='code'>Alias \/mailsys \/var\/www\/mailsys\n&lt;Directory &quot;\/var\/www\/mailsys&quot;&gt;\n    Order deny,allow\n    Allow from all\n    Deny from all\n&lt;\/Directory&gt;<\/pre><br \/>\n\u5b9f\u969b\u306b\u306f\/etc\/httpd\/conf.d\/\u4ee5\u4e0b\u306b\u9069\u5f53\u306a\u540d\u524d(mailsys.conf)\u3067\u4fdd\u5b58\u3059\u308b\u3002http:\/\/example.com\/mailsys\/ \u306b\u30d6\u30e9\u30a6\u30b6\u30fc\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002<\/p>\n<h3>functions.php<\/h3>\n<pre class='code'>&lt;?php\nrequire_once(&quot;Zend\/Mail\/Message.php&quot;);\nrequire_once(&quot;Zend\/Http\/Client.php&quot;);\n\ndefine(&#039;APPLICATION_DIR&#039;, &#039;\/var\/www\/mailsys&#039;);\ndefine(&#039;MAIL_DIR&#039;, APPLICATION_DIR . &#039;\/mail\/&#039;);\ndefine(&#039;FILE_DIR&#039;, APPLICATION_DIR . &#039;\/file\/&#039;);\n\nfunction getMails($offset = 0, $limit = 20){\n    $mails = array();\n    $files = array_reverse(glob(MAIL_DIR . &quot;*&quot;));\n    foreach(array_slice($files, $offset, $limit) as $mail){\n        $mails[] = parse($mail);\n    }\n    return $mails;\n}\n\nfunction receive(){\n    $path = sprintf(&quot;%s%s.mamail&quot;, MAIL_DIR, time());\n    while(file_exists($path)) $path .= &#039;.&#039; . time();\n    saveFile($path, stream_get_contents(STDIN));\n\n    $Hc = new Zend_Http_Client;\n    $mail = parse($path);\n\n    printf(&quot;Date: %s\\n&quot;, $mail[&#039;date&#039;]);\n    printf(&quot;Subject: %s\\n&quot;, $mail[&#039;subject&#039;]);\n\n    foreach($mail[&#039;files&#039;] as $file){\n        $response = $Hc-&gt;setUri($file[&#039;url&#039;])-&gt;request(Zend_Http_Client::GET);\n        if(&#039;application\/pdf&#039; == $response-&gt;getHeader(&#039;content-type&#039;)){\n            saveFile(FILE_DIR . $file[&#039;file&#039;], $response-&gt;getBody());\n            printf(&quot;File: %s\\n&quot;, $file[&#039;file&#039;]);\n        }\n    }\n}\n\nfunction parse($file){\n    $Mail = new Zend_Mail_Message(array(&#039;file&#039; =&gt; $file));\n    mb_internal_encoding(&#039;ISO-2022-JP&#039;);\n    $mail = array(&#039;subject&#039; =&gt; &#039;no subject&#039;, &#039;from&#039; =&gt; &#039;no from&#039;, &#039;date&#039; =&gt; date(&#039;Y-m-d H:i:s&#039;));\n    foreach(array(&#039;subject&#039;, &#039;from&#039;, &#039;date&#039;) as $header){\n        try{\n            $mail[$header] = myconvert(mb_decode_mimeheader($Mail-&gt;getHeader($header)));\n            if(&#039;date&#039; == $header){\n                $mail[$header] = strtotime($mail[$header]);\n            }\n        }catch(Zend_Mail_Exception $e){\n            printf(&quot;%s %s&quot;, get_class($e), $file);\n        }\n    }\n    mb_internal_encoding(&#039;UTF-8&#039;);\n    $mail[&#039;body&#039;] = myconvert($Mail-&gt;getContent());\n    $mail[&#039;files&#039;] = array();\n\n    foreach(explode(&quot;\\n&quot;, $mail[&#039;body&#039;]) as $line){\n        if(preg_match(&quot;\/(https:\\\/\\\/www.mamail.jp\\\/.*(mamail[0-9]*\\.pdf))\/&quot;, $line, $match)){\n            $mail[&#039;files&#039;][] = array(&#039;url&#039; =&gt; trim($match[1]), &#039;file&#039; =&gt; trim($match[2]));\n        }\n    }\n    return $mail;\n}\n\nfunction myconvert($text){\n    return mb_convert_encoding($text, &#039;UTF-8&#039;, &#039;ISO-2022-JP&#039;);\n}\n\nfunction saveFile($path, $content){\n    file_put_contents($path, $content);\n    chmod($path, 0644);\n}<\/pre>\n<h3>receive.php<\/h3>\n<pre class='code'>&lt;?php\nrequire_once(&quot;functions.php&quot;);\nreceive();<\/pre>\n<h3>index.php<\/h3>\n<pre class='code'>&lt;?php\nini_set(&#039;display_errors&#039;, &#039;On&#039;);\n\nrequire_once(&quot;functions.php&quot;);\nif(isset($_GET[&#039;file&#039;])){\n    $path = FILE_DIR . basename($_GET[&#039;file&#039;]);\n    if(is_readable($path)){\n        header(&#039;content-type: application\/pdf&#039;);\n        readfile($path);\n    }\n    exit;\n}\n\nrequire_once(&quot;Zend\/View.php&quot;);\n$View = new Zend_View(array(\n    &#039;scriptPath&#039; =&gt; &#039;.&#039;,\n));\n\n$View-&gt;mails = getMails(0, 20);\necho $View-&gt;render(&#039;index.tpl&#039;);<\/pre>\n<h3>index.tpl<\/h3>\n<pre class='code'>&lt;?php\necho $this-&gt;doctype();\n?&gt;\n&lt;html&gt;\n    &lt;head&gt;\n    &lt;meta charset=&quot;utf-8&quot;&gt;\n    &lt;title&gt;mailsys&lt;\/title&gt;\n    &lt;style type=&#039;text\/css&#039;&gt;&lt;!--\n        dt {\n            border-top : 1px solid black;\n            font-weight: bold;\n            margin-top: 1em;\n        }\n        dd {\n            white-space: pre-wrap;\n            padding: 5px;\n            background-color: #EEE;\n            font-size: small;\n            border-radius: 5px;\n        }\n    --&gt;&lt;\/style&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n    &lt;dl&gt;\n    &lt;?php foreach($this-&gt;mails as $mail){\n        $dt = array(\n            date(&#039;Y-m-d:&#039;, $mail[&#039;date&#039;]),\n            $mail[&#039;subject&#039;],\n            join(&quot; &quot;, array_map(\n                function ($file){\n                    return sprintf(&quot;&lt;a href=&#039;?file=%s&#039;&gt;PDF&lt;\/a&gt;&quot;, basename($file[&#039;file&#039;]));\n                },\n                $mail[&#039;files&#039;]\n            )),\n        );\n        printf(&quot;&lt;dt&gt;%s&lt;\/dt&gt;&lt;dd&gt;%s&lt;\/dd&gt;\\n&quot;, join(&quot; &quot;, $dt), trim($mail[&#039;body&#039;]));\n    }\n    ?&gt;\n    &lt;\/dl&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<h2>\u8ab2\u984c<\/h2>\n<ul>\n<li>\u30e1\u30fc\u30eb\u304c\u5897\u3048\u305f\u3068\u304d\u306e\u30da\u30fc\u30b8\u30f3\u30b0\u3002\u3053\u308c\u3092\u5b9f\u73fe\u3059\u308b\u306b\u306findex.tpl\u306b\u30e1\u30fc\u30eb\u7dcf\u6570\u3092\u6e21\u3059\u5fc5\u8981\u304c\u3042\u308b\u3002GET\u306e\u5f15\u6570\u3068\u3057\u3066page\u304c\u308f\u305f\u308b\u3088\u3046\u306b\u3057\u3066\u3001getMails\u3078\u306e\u5f15\u6570\u3092\u8abf\u6574\u3059\u308b\u3002<\/li>\n<li>\u30e1\u30fc\u30eb\u672c\u6587\u3082\u3057\u304f\u306fPDF\u5185\u5bb9\u306e\u691c\u7d22\u3002\u30e1\u30fc\u30eb\u672c\u6587\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u3044\u308c\u308b\u3068\u3059\u308b\u3068\u3001\u30b7\u30b9\u30c6\u30e0\u304c\u8907\u96d1\u306b\u306a\u308b\u3002\u691c\u7d22\u30a6\u30a3\u30f3\u30c9\u30a6\u3001\u4e00\u89a7\u8868\u793a\u3082\u5c11\u3057\u9762\u5012\u3002<\/li>\n<li>\u914d\u5e03\u66f8\u985e\u304cPDF\u306b\u6c7a\u3081\u6253\u3061\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3068\u304d\u306econtent-type\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u4fdd\u5b58\u3059\u308c\u3070\u3044\u3044\u304c\u3001\u4e0a\u8a18\u3068\u3069\u3046\u3088\u3046\u30b7\u30b9\u30c6\u30e0\u304c\u8907\u96d1\u306b\u306a\u308b\u3002<\/li>\n<li>\u30e1\u30fc\u30eb\u306e\u65e5\u672c\u8a9e\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u304c\u6c7a\u3081\u6253\u3061\u306b\u306a\u3063\u3066\u3044\u308b\u3002MIME\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u305f\u3082\u306e\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u9069\u5207\u306a\u65b9\u6cd5\u304c\u308f\u304b\u3089\u306a\u3044\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u5b66\u6821\u304b\u3089\u306e\u9023\u7d61\u304c\u96fb\u5b50\u30e1\u30fc\u30eb\u306b\u306a\u308a\u3001\u914d\u5e03\u7269\u304cPDF\u30d5\u30a1\u30a4\u30eb\u306b\u306a\u308a\u307e\u3057\u305f\u3002PDF\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u308b\u306e\u304c5\u65e5\u4ee5\u5185\u3067\u3001\u4fdd\u5b58\u3059\u308b\u306e\u3092\u5fd8\u308c\u308b\u3068\u9762\u5012\u306a\u3053\u3068\u306b\u306a\u308a\u305d\u3046\u3067\u3059\u3002\u307e\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u5185\u5bb9\u3068\u7121\u95a2\u4fc2\u3067\u3001\u63a2\u3059\u306e\u304c\u5927\u5909\u305d\u3046\u306a\u306e\u3067\u96fb\u5b50\u30e1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,7],"tags":[],"_links":{"self":[{"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/posts\/943"}],"collection":[{"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/comments?post=943"}],"version-history":[{"count":19,"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/posts\/943\/revisions"}],"predecessor-version":[{"id":964,"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/posts\/943\/revisions\/964"}],"wp:attachment":[{"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/media?parent=943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/categories?post=943"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/tags?post=943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}