Skip to content

Instantly share code, notes, and snippets.

@maxkerp
Created January 28, 2021 15:05
Show Gist options
  • Save maxkerp/35a0c50081d55b616945b2f9f57cab16 to your computer and use it in GitHub Desktop.
Save maxkerp/35a0c50081d55b616945b2f9f57cab16 to your computer and use it in GitHub Desktop.
A small wrapper around sieve-connect to make it git-like to use
#!/bin/bash
# This is a small wrapper around sieve-connect making it easier to use.
set -e
MAIL_SERVER=< mail server address here>
MAIL_ACCOUNT=< mail address here>
short_sieve(){
local cmd=$1
shift
local rule_set="${*:-main}"
case $cmd in
"list" )
/usr/bin/sieve-connect -s $MAIL_SERVER -u $MAIL_ACCOUNT -m plain --list
;;
"fetch" )
/usr/bin/sieve-connect -s $MAIL_SERVER -u $MAIL_ACCOUNT -m plain --download --remotesieve "$rule_set" --localsieve "$rule_set".sieve
;;
"check" )
/usr/bin/sieve-connect -s $MAIL_SERVER -u $MAIL_ACCOUNT -m plain --checkscript --localsieve "$rule_set".sieve
;;
"push" )
/usr/bin/sieve-connect -s $MAIL_SERVER -u $MAIL_ACCOUNT -m plain --upload --localsieve "$rule_set".sieve --remotesieve "$rule_set"
;;
"activate" )
/usr/bin/sieve-connect -s $MAIL_SERVER -u $MAIL_ACCOUNT -m plain --activate --remotesieve "$rule_set"
;;
esac
}
if [[ -z "$1" ]] || [[ "$1" = '--help' ]];then
cat <<-USAGE
USAGE:
$0 command arguments
commands:
list - List all available sieve files on the remote
fetch <rule_set> - Fetch the main.sieve file from the server
check <rule_set> - Check the local main.sieve file
push <rule_set> - Push the local main.sieve file to the server
USAGE
exit 0
fi
if [[ -z "$MAIL_ACCOUNT" ]]; then
echo "MAIL_ACCOUNT not set. Set the value in the header of the script"
fi
short_sieve $1 $2
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment