{"id":6580,"date":"2023-01-27T14:05:31","date_gmt":"2023-01-27T05:05:31","guid":{"rendered":"https:\/\/www.lancard.com\/blog\/?p=6580"},"modified":"2025-03-12T11:23:58","modified_gmt":"2025-03-12T02:23:58","slug":"dovecot-push_notification-log","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2023\/01\/27\/dovecot-push_notification-log\/","title":{"rendered":"Dovecot\u306epush_notification\u3092\u4f7f\u3063\u3066\u30a4\u30d9\u30f3\u30c8\u30ed\u30b0\u3092\u53d6\u308b"},"content":{"rendered":"\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<a href=\"https:\/\/www.lancard.com\/blog\/2023\/01\/20\/dovecot-push_notification-before-build\/\">\u524d\u56de<\/a>\u306fDovecot\u3092\u30bd\u30fc\u30b9\u304b\u3089\u30d3\u30eb\u30c9\u3057\u3066Lua\u304c\u52d5\u304f\u307e\u3067\u3092\u3084\u308a\u307e\u3057\u305f\u3002\n\n\n\n\u4eca\u56deLua\u304c\u5927\u4f53\u52d5\u304f\u611f\u3058\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u30a4\u30d9\u30f3\u30c8\u3054\u3068\u306e\u30c7\u30fc\u30bf\u3092\u9001\u308a\u307e\u3059\u3002\n<\/div>\n<\/div>\n\n\n\n\n<!--more-->\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<h2 class=\"wp-block-heading\">Dovecot<\/h2>\n\n\n\n10-mail.conf\u306f\u524d\u56de\u306e\u307e\u307e\u3067\u3059\u3002\n<\/div>\n<\/div>\n\n\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/usr\/local\/etc\/dovecot\/conf.d\/10-mail.conf<\/li>\n<\/ul>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>mail_plugins = $mail_plugins quota mail_lua notify push_notification push_notification_lua<\/code><\/pre>\n\n\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/usr\/local\/etc\/dovecot\/conf.d\/90-plugin.conf<\/li>\n<\/ul>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>plugin {\n  push_notification_driver = lua:file=\/home\/vmb\/dovecot-push.lua\n  push_lua_url = http:\/\/localhost\/push.php\n}<\/code><\/pre>\n\n\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/home\/vmb\/dovecot-push.lua<\/li>\n<\/ul>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/lua\nlocal client = nil\nlocal json = require \"json\"\n\nfunction script_init()\n  client = dovecot.http.client({debug=True, timeout=10000})\n  return 0\nend\n\nlocal function table_get(t, k, d)\n  return t&#91;k] or d\nend\n\nfunction datapost(url, ctx, data)\n  local user = ctx.user\n  data.username = table_get(user, \"username\", \"\")\n  data.home = table_get(user, \"home\", \"\")\n  data.service = table_get(user, \"service\", \"\")\n  data.session_id = table_get(user, \"session_id\", \"\")\n  --\n  local rq = client:request({url=url, method=\"POST\"})\n  rq:add_header(\"content-type\", \"application\/json\")\n  rq:set_payload(json.encode(data))\n  local code = rq:submit():status()\n  return code\nend\n\n-- start\nfunction dovecot_lua_notify_begin_txn(user)\n  return {user=user, event=dovecot.event(), ep=user:plugin_getenv(\"push_lua_url\"), states={}, messages={}}\nend\n\n-- mailbox\nfunction dovecot_lua_notify_event_mailbox_create(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_mailbox_delete(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_mailbox_rename(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_mailbox_subscribe(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_mailbox_unsubscribe(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\n\n-- message\nfunction dovecot_lua_notify_event_message_new(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_message_append(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_message_read(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_message_trash(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_message_expunge(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\n\n-- flags\nfunction dovecot_lua_notify_event_flags_set(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\nfunction dovecot_lua_notify_event_flags_clear(ctx, data)\n  datapost(ctx.ep, ctx, data)\nend\n\n-- end\nfunction dovecot_lua_notify_end_txn(ctx)\n  -- nothing\nend<\/code><\/pre>\n\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n\u5404function\uff08mailbox, message, flags\uff09\u3092\u5b9a\u7fa9\u3059\u308b\u4e8b\u3067\u3001\u30a4\u30d9\u30f3\u30c8\u3054\u3068\u306b\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u3067\u3059\u3002\u30a4\u30d9\u30f3\u30c8\u3054\u3068\u306e\u5dee\u7570\u3092\u6c17\u306b\u305b\u305a\u306b\u6e08\u3080\u3088\u3046\u3001\u5168\u90e8\u9001\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\n<\/div>\n<\/div>\n\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n\u6700\u521d\u306fjson.encode()\u3067\u306a\u304fhttp_util.dict_to_query()\u3092\u4f7f\u3063\u3066\u3044\u305f\u3093\u3067\u3059\u304c\u3001string\u578b\u4ee5\u5916\u3092\u53d7\u3051\u4ed8\u3051\u306a\u3044\uff08number\u3067\u3055\u3048\u99c4\u76ee\uff09\u4e8b\u3068\u3001\u4e00\u6b21\u5143\u914d\u5217\u306b\u52a0\u5de5\u3057\u76f4\u3059\u5fc5\u8981\u304c\u6709\u3063\u3066\u3001\u4e00\u5fdc\u52d5\u304d\u306f\u3057\u305f\u3082\u306e\u306e\u3069\u3053\u304b\u3067\u5f15\u3063\u304b\u304b\u308a\u305d\u3046\u306a\u306e\u3067\u3001\u8ae6\u3081\u3066\u6368\u3066\u307e\u3057\u305f\u3002\n<\/div>\n<\/div>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Web\u5074<\/h2>\n\n\n\n\nDocumentRoot\u4e0b\u306bpush.php\u3092\u4f5c\u308a\u307e\u3059\u3002\n\n\n\n\n<ul class=\"wp-block-list\">\n<li>http:\/\/localhost\/push.php<\/li>\n<\/ul>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ data\n$content = file_get_contents('php:\/\/input');\nif($_SERVER&#91;\"CONTENT_TYPE\"] == \"application\/json\"){\n    $Data = json_decode($content, true);\n    $json = $content;\n}else{\n    $Data = $_GET + $_POST;\n    $json = json_encode($Data);\n}\n\/\/ log\n$res = false;\nif(isset($Data&#91;\"name\"], $Data&#91;\"username\"], $Data&#91;\"mailbox\"])){\n    $con = @pg_connect(\"user=mail dbname=mail password=testpass\");\n    if($con){\n        $INSQL = array(\"eventname\"=&gt;$Data&#91;\"name\"], \"username\"=&gt;$Data&#91;\"username\"], \"mailbox\"=&gt;$Data&#91;\"mailbox\"], \"data\"=&gt;$json);\n        $res = pg_insert($con, \"notifications\", $INSQL);\n    }\n}<\/code><\/pre>\n\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\nLua\u304b\u3089\u9001\u308b\u306e\u306fJSON\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u306e\u305f\u3081\u3001php:\/\/input\u3067\u53d7\u3051\u3066json_decode\u3057\u3066\u3044\u307e\u3059\u3002<br>\uff08CONTENT_TYPE\u3067\u5206\u3051\u308b\u5fc5\u8981\u306f\u7121\u3044\u3067\u3059\u304c\u3001\u3069\u3061\u3089\u3067\u3082\u53d7\u3051\u3089\u308c\u308b\u3088\u3046\u306b\u306f\u3057\u3066\u3044\u307e\u3059\uff09\n\n\n\n<h2 class=\"wp-block-heading\">PostgreSQL<\/h2>\n\n\n\n\u30a4\u30d9\u30f3\u30c8\u4fdd\u5b58\u7528\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE notifications (\n    id bigserial PRIMARY KEY,\n    eventname text NOT NULL,\n    mailbox text,\n    username text,\n    data text,\n    created timestamp without time zone DEFAULT now()\n);<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\nRoundCube\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3001\u9069\u5f53\u306b\u30d5\u30e9\u30b0\u3092\u5916\u3057\u305f\u308a\u30e1\u30fc\u30eb\u3092\u79fb\u52d5\u3055\u305b\u305f\u308a\u3057\u3066\u3001psql\u30b3\u30de\u30f3\u30c9\u3067\u30c7\u30fc\u30bf\u3092\u898b\u3066\u307f\u307e\u3059\u3002\n<\/div>\n<\/div>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>mail=&gt; select eventname,username,mailbox,created from notifications ORDER BY created;\n   eventname    |          username          | mailbox |          created           \n----------------+----------------------------+---------+----------------------------\n FlagsClear     | aikawa@virtual.localdomain | INBOX   | 2023-01-26 14:21:23.636366\n MessageAppend  | aikawa@virtual.localdomain | INBOX   | 2023-01-26 14:21:37.172475\n MessageExpunge | aikawa@virtual.localdomain | Test    | 2023-01-26 14:21:37.182596<\/code><\/pre>\n\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n\u3053\u308c\u3067\u30c7\u30fc\u30bf\u3092DB\u306b\u8a18\u9332\u51fa\u6765\u308b\u4e8b\u304c\u78ba\u8a8d\u51fa\u6765\u307e\u3057\u305f\u3002\n<\/div>\n<\/div>\n\n\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n\u30e1\u30fc\u30eb\u3092\u79fb\u52d5\u3055\u305b\u308b\u3068\u3001MessageAppend\u3001\u6b21\u306bMessageExpunge\u304c\u767a\u751f\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u4e00\u3064\u306e\u52d5\u4f5c\u3067\u8907\u6570\u306e\u901a\u77e5\u304c\u98db\u3076\u4e8b\u3082\u6709\u308b\u3088\u3046\u3067\u3059\u3002\n<\/div>\n<\/div>\n\n\n\n\n\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6580&amp;t=Dovecot%E3%81%AEpush_notification%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B0%E3%82%92%E5%8F%96%E3%82%8B&amp;s=100&amp;p[url]=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6580&amp;p[images][0]=&amp;p[title]=Dovecot%E3%81%AEpush_notification%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B0%E3%82%92%E5%8F%96%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6580&amp;text=Dovecot%E3%81%AEpush_notification%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B0%E3%82%92%E5%8F%96%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&amp;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6580&amp;title=Dovecot%E3%81%AEpush_notification%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B0%E3%82%92%E5%8F%96%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&amp;v=3&amp;t=Dovecot%E3%81%AEpush_notification%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B0%E3%82%92%E5%8F%96%E3%82%8B&amp;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6580\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Dovecot%E3%81%AEpush_notification%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B0%E3%82%92%E5%8F%96%E3%82%8B&amp;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6580\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306fDovecot\u3092\u30bd\u30fc\u30b9\u304b\u3089\u30d3\u30eb\u30c9\u3057\u3066Lua\u304c\u52d5\u304f\u307e\u3067\u3092\u3084\u308a\u307e\u3057\u305f\u3002 \u4eca\u56deLua\u304c\u5927\u4f53\u52d5\u304f\u611f\u3058\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u30a4\u30d9\u30f3\u30c8\u3054\u3068\u306e\u30c7\u30fc\u30bf\u3092\u9001\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6580","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/6580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=6580"}],"version-history":[{"count":25,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/6580\/revisions"}],"predecessor-version":[{"id":6606,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/6580\/revisions\/6606"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=6580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=6580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=6580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}