{"id":128,"date":"2015-10-05T00:31:17","date_gmt":"2015-10-04T15:31:17","guid":{"rendered":"http:\/\/www8281uo.sakura.ne.jp\/blog\/?p=128"},"modified":"2015-10-05T00:31:17","modified_gmt":"2015-10-04T15:31:17","slug":"varspoolmail-%e3%81%ab%e5%b1%8a%e3%81%84%e3%81%9f%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92%e5%87%a6%e7%90%86%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www8281uo.sakura.ne.jp\/blog\/?p=128","title":{"rendered":"\/var\/spool\/mail\/ \u306b\u5c4a\u3044\u305f\u30e1\u30fc\u30eb\u3092\u51e6\u7406\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<h3>\u6982\u8981<\/h3>\n<p>cron \u3067\u51e6\u7406\u3057\u305f\u7d50\u679c\u304c\u30e1\u30fc\u30eb\u3067\u9001\u3089\u308c\u3066\u304f\u308b\u3068\u304d\u306b \/var\/spool\/mail\/username \u306b\u5c4a\u304f\u3002mbox \u5f62\u5f0f\u3067\u66f8\u304d\u8fbc\u307e\u308c\u3066\u3001\u3053\u308c\u306f mailx \u3067\u8aad\u3093\u3060\u308a\u6d88\u3057\u305f\u308a\u3067\u304d\u308b\u3002\u3060\u3051\u3069\u3001mailx \u306f\u5bfe\u8a71\u5f0f\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u81ea\u52d5\u3067\u4e2d\u8eab\u3092\u898b\u3066\u51e6\u7406\u3057\u305f\u308a\u3067\u304d\u306a\u3044\u3002<\/p>\n<p>\u30e1\u30fc\u30eb\u306e\u6570\u304c\u5927\u91cf\u306b\u306a\u308b\u3068\uff08\u4f8b\u3048\u3070\u6bce\u5206\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u56de\u3057\u3066\u305f\u308a\u3059\u308b\u3068\uff09\u30c1\u30a7\u30c3\u30af\u4e0d\u80fd\u306b\u306a\u308b\u3057\u3001\u304b\u3068\u3044\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u306e\u306f\u3061\u3087\u3063\u3068\u30fb\u30fb\u30fb\u307f\u305f\u3044\u306a\u6642\u306b\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p>procmail \u3068\u304b\u3067\u53d7\u4fe1\u6642\u306b\u51e6\u7406\u3059\u308b\u3068\u3044\u3046\u624b\u3082\u3042\u308b\u3068\u601d\u3046\u3051\u3069\u3001\u4eca\u56de\u306f\u307e\u3068\u3081\u3066\u30d0\u30c3\u30c1\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u3092\u63a2\u3057\u3066\u307f\u305f\u3002<\/p>\n<p>\u52d5\u4f5c\u74b0\u5883\u306f CentOS 7 + Python 2.7\u3002<\/p>\n<h3>\u5927\u96d1\u628a\u306a\u624b\u9806<\/h3>\n<ol>\n<li>GNU Mailutils \u306e movemail \u3067 \/var\/spool\/mail\/username \u3092\u5225\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\uff08\u30db\u30fc\u30e0\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\uff09\u306b\u79fb\u52d5\n<ul>\n<li>\/var\/spool\/mail\/ \u306f\u30e6\u30fc\u30b6\u6a29\u9650\u3067\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308c\u306a\u3044\u306e\u3067\u3001mbox \u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3059\u308b\u3068\u304d\u306b\u30ed\u30c3\u30af\u304c\u53d6\u308c\u306a\u3044\u3068\u3044\u3046\u554f\u984c\u304c\u3042\u308b\u306e\u3067\u3001\u4e88\u3081\u30e1\u30fc\u30eb\u3092\u79fb\u52d5<\/li>\n<\/ul>\n<\/li>\n<li>mbox \u3092\u89e3\u91c8\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u7b49\u3092\u4f7f\u3063\u3066 mail \u3092\u89e3\u91c8\u3057\u3066\u51e6\u7406\n<ul>\n<li>\u4f7f\u3048\u308b\u30c4\u30fc\u30eb\u306f\u3044\u308d\u3044\u308d\u3042\u308b\u3068\u601d\u3046\u304c\u4eca\u56de\u306f python \u3092\u4f7f\u7528<\/li>\n<li>cron \u304b\u3089\u9001\u3089\u308c\u3066\u304f\u308b\u30e1\u30fc\u30eb\u306b\u5bfe\u3057\u3066\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3092\u66f8\u3044\u3066\u7279\u5b9a\u306e\u6761\u4ef6\uff08\u30a8\u30e9\u30fc\u7b49\uff09\u3092\u6e80\u305f\u3059\u30e1\u30fc\u30eb\u3060\u3051\u3092\u6b8b\u3059\u3001\u3068\u304b\u7279\u5b9a\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u51fa\u3059\u3001\u3068\u304b\u306e\u4f7f\u3044\u65b9\u3092\u60f3\u5b9a<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>GNU Mailutils \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>CentOS \u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u306f\u306a\u3055\u305d\u3046\u3060\u3063\u305f\u306e\u3067<a href=\"http:\/\/mailutils.org\/\">\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u30b3\u30f3\u30d1\u30a4\u30eb\u30fb\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002configure -&gt; make -&gt; make install \u306e\u3044\u3064\u3082\u306e\u6d41\u308c\u3067 OK\u3002<\/p>\n<h3>\u30e1\u30fc\u30eb\u51e6\u7406\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f8b<\/h3>\n<ul>\n<li>$MAIL \u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u524d\u63d0\uff08\/var\/spool\/mail\/username \u3068\u304b\u306b\u306a\u3063\u3066\u3044\u308b\u306f\u305a\uff09<\/li>\n<li>$HOME\/mail\/INBOX \u3092\u30e1\u30fc\u30eb\u306e\u79fb\u52d5\u5148\u3068\u3057\u305f\uff08\u4e88\u3081 $HOME\/mail \u3092\u4f5c\u3063\u3066\u304a\u304f\uff09<\/li>\n<li>GNU Mailutils \u306e\u30c4\u30fc\u30eb\u306b\u306f\u30d1\u30b9\u3092\u901a\u3057\u3066\u304a\u304f<\/li>\n<li>\u3053\u306e\u307e\u307e\u306f\u52d5\u304b\u306a\u3044\u306e\u3067\u3054\u6ce8\u610f<\/li>\n<\/ul>\n<pre>#!\/usr\/bin\/env python\n\nimport os\nimport subprocess\nimport mailbox\n\ndef chkMsg(msg):\n    subject = msg[\"subject\"]\n    body = msg.get_payload()\n\n    # \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5185\u5bb9\u306b\u3088\u3063\u3066\u8fd4\u308a\u5024\u3092\u5909\u3048\u308b\n    if \u524a\u9664:\n        return 0\n    else:\n        return 1\n\nmboxpath = os.environ[\"HOME\"] + \"\/mail\/INBOX\"\nsubprocess.call([\"movemail\", os.environ[\"MAIL\"], mboxpath])\n\nmbox = mailbox.mbox(mboxpath)\nto_remove = []\nfor key, msg in mbox.iteritems():\n    if chkMsg(msg) == 0:\n        print \"Removing: \", key\n        to_remove.append(key)\n\nmbox.lock()\ntry:\n    for key in to_remove:\n        mbox.remove(key)\nfinally:\n    mbox.flush()\n    mbox.close()\n\nsubprocess.call([\"mail\", \"-f\", mboxpath])<\/pre>\n<h3>\u53c2\u8003<\/h3>\n<ul>\n<li><a href=\"http:\/\/docs.python.jp\/2\/library\/email.message.html\">18.1.1. email.message: \u96fb\u5b50\u30e1\u30fc\u30eb\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u8868\u73fe<\/a><\/li>\n<li><a href=\"http:\/\/docs.python.jp\/2\/library\/mailbox.html\">18.4. mailbox \u2014 \u69d8\u3005\u306a\u5f62\u5f0f\u306e\u30e1\u30fc\u30eb\u30dc\u30c3\u30af\u30b9\u64cd\u4f5c<\/a><\/li>\n<li><a href=\"http:\/\/bugs.python.org\/issue7359\">Issue 7359: mailbox cannot modify mailboxes in system mail spool<\/a><\/li>\n<li><a href=\"http:\/\/ja.pymotw.com\/2\/mailbox\/\">mailbox \u2013 \u30e1\u30fc\u30eb\u30a2\u30fc\u30ab\u30a4\u30d6\u306e\u30a2\u30af\u30bb\u30b9\u3068\u64cd\u4f5c<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 cron \u3067\u51e6\u7406\u3057\u305f\u7d50\u679c\u304c\u30e1\u30fc\u30eb\u3067\u9001\u3089\u308c\u3066\u304f\u308b\u3068\u304d\u306b \/var\/spool\/mail\/username \u306b\u5c4a\u304f\u3002mbox \u5f62\u5f0f\u3067\u66f8\u304d\u8fbc\u307e\u308c\u3066\u3001\u3053\u308c\u306f mailx \u3067\u8aad\u3093\u3060\u308a\u6d88\u3057\u305f\u308a\u3067\u304d\u308b\u3002\u3060\u3051\u3069\u3001mailx \u306f\u5bfe\u8a71 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-128","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=128"}],"version-history":[{"count":0,"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions"}],"wp:attachment":[{"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www8281uo.sakura.ne.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}