Menu

#8 pre- and postsync hook

1.2
wont-fix
nobody
None
unknown
5
2022-06-20
2016-05-27
Escoban
No

One feature missing from offlineimap are account-wise hooks before and after mbsync has synced the mailbox. (For example, to invoke imapfilter (and/or bogofilter) before, and notmuch afterwards).

Currently, the only workaround seems a bash script, like the following:

#!/bin/sh

PRESYNC="imapfilter"
POSTSYNC="notmuch new"

mbsync="$(type 2>/dev/null -a mbsync | tail -n 1)"
mbsync=${mbsync#* * }

if [ -z "$1" ]; then
  "$mbsync"
  exit
fi

accounts=$(grep '^\s*Channel\s\+' ~/.mbsyncrc)
accounts=($(for a in ${accounts[@]}; do [ "$a" != "Channel" ] && echo "$a"; done ))

last_arg=${*: -1:1}

for account in ${accounts[*]}; do
  if [[ "$last_arg" =~ ^"$account"(:.+)?$ ]]; then
    $PRESYNC ~/.imapfilter/"$account".lua
    echo ""
  fi
done

for argument in "$@"; do
  if [[ "$argument" =~ ^-[a-zA-Z]*a[a-zA-Z]*$ ]] || [ "$argument" = "--all" ]; then
    for account in ${accounts[*]}; do
        $PRESYNC ~/.imapfilter/"$account".lua
      echo ""
    done
    break
  fi
done

$mbsync "$@"
echo ""

$POSTSYNC

Are there better ways to mimic the pre- and postsynchook 's of offlineimap? If not, recommendations to improve this script?

Discussion

  • Oswald Buddenhagen

    i think it's entirely reasonable to launch mbsync from a script - i do it myself.

    some kind of "batch notifications" would be much more interesting if mbsync was the driving agent, i.e., if it operated as a stand-alone daemon. this is vaguely planned and indefinitely postponed as of now.

    one kind of notification i'd find interesting myself is about delivery of individual messages. that way i could implement desktop notifications with a simple script calling dbus-send instead of using an external directory-watcher like gnome mail-notification. i imagine this to be configured per Store:

    # called in batches with one notification per line on stdin:
    # <box>\t<uid>\t<optional: driver specific info, e.g. the message's filepath>
    NotifierCmd "..."
    

    it's conceivable to notify also about the other sync actions (flag update (include the delta?) and deletion), possibly including outgoing (locally originated) actions, but that seems much less useful to me.

     
  • Teto

    Teto - 2018-09-01

    was this implemented in any way ? I wanted to switch from offlineimap and wrapping mbsync is ok with a single account but it's a bit more complex when you wanna run per account post hooks (in my casem notmuch).

     
  • Oswald Buddenhagen

    • status: requested --> wont-fix
     
  • Oswald Buddenhagen

    the case of selectively running post-invoke commands is covered by the --ext-exit option (will be in v1.5).

    i gave batch notifications some serious thought, and shelved the idea, as i found that a regular maildir watcher is more appropriate after all.

    and as implementing the original request of "dumb" pre- and post-commands offers no real benefits imo, i'm closing this now.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.