Skip to content

Commit

Permalink
Support onNotify/onNotifyPost for specific imap events (a-sk#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
renatofdds authored and a-sk committed Sep 6, 2017
1 parent b567f3a commit a37456c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Execute scripts on IMAP mailbox changes (new/deleted/updated messages) using IDL
"username": "",
"password": "",
"onNotify": "/usr/bin/mbsync test-%s",
"onNotifyPost": "/usr/bin/notmuch new",
"onNotifyPost": {"mail": "/usr/bin/notmuch new && notify-send 'New mail arrived'"},
"boxes":
[
"box1",
Expand All @@ -23,8 +23,14 @@ Execute scripts on IMAP mailbox changes (new/deleted/updated messages) using IDL
```

```
onNotify: an executable to run on new mail in box
onNotifyPost: an executable to run after onNotify command
onNotify:
[string]: shell command to run on any event
[object]: shell commands to run on for each type of event
keys: "mail" for new mail, "update" for existing messages updates, "expunge" for messages deletions
onNotifyPost:
[string]: shell command to run after onNotify event
[object]: shell commands to run after onNotify for each type of event
keys: "mail" for new mail, "update" for existing messages updates, "expunge" for messages deletions
```

### extra options
Expand Down
18 changes: 10 additions & 8 deletions bin/imapnotify
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Notifier.prototype.add_box = function(box, cb, debug) {
function addConnectionListener(event, message) {
connection.on(event, function() {
self.logger.info({box: box}, message)
cb(box)
cb(box, event)
})
}
addConnectionListener('mail', 'New Mail')
Expand Down Expand Up @@ -234,13 +234,15 @@ function executeCommands(command, postCommand, cb) {
function executeOnNotify(config) {
var command = config.onNotify || config.onNewMail
, postCommand = config.onNotifyPost || config.onNewMailPost
;
return function notify(box) {
box = replace(box.toLowerCase(), '\/', '-')
command = printf(command, box)
postCommand = printf(postCommand, box)
return executeCommands(command, postCommand)
}
, commandIsEventMap = (typeof command === 'object')
, postCommandIsEventMap = (typeof postCommand === 'object')
;
return function notify(box, event) {
var formattedBox = replace(box.toLowerCase(), '/', '-')
, formattedCommand = printf(commandIsEventMap ? command[event] || '': command, formattedBox)
, formattedPostCommand = printf(postCommandIsEventMap ? postCommand[event] || '': command, formattedBox)
return executeCommands(formattedCommand, formattedPostCommand)
}
}

function runOnSig(signal, config, cb) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imapnotify",
"version": "0.4.0",
"version": "0.4.1",
"description": "Execute scripts on new messages using IDLE imap command",
"repository": {
"type": "git",
Expand Down

0 comments on commit a37456c

Please sign in to comment.