aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile30
-rwxr-xr-xbin/mailcfg280
l---------etc/alot/config1
l---------etc/mailcfg1
l---------etc/mbsync/config1
l---------etc/msmtp/config1
l---------etc/notmuch/default/config1
l---------etc/notmuch/default/hooks/post-new1
8 files changed, 306 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 552e7cc..b94b8bf 100644
--- a/Makefile
+++ b/Makefile
@@ -12,14 +12,18 @@ lisp-images = \
$(XDG_DATA_HOME)/lisp-cli/sbcl.image \
derived-assets = \
- $(pod2man) \
- $(XDG_CONFIG_HOME)/ssh/id_rsa.pub \
- $(XDG_DATA_HOME)/common-lisp/source \
- $(XDG_DATA_HOME)/euandreh/e.list.txt \
+ $(pod2man) \
+ $(XDG_CONFIG_HOME)/ssh/id_rsa.pub \
+ $(XDG_CONFIG_HOME)/alot/config \
+ $(XDG_CONFIG_HOME)/mbsync/config \
+ $(XDG_CONFIG_HOME)/msmtp/config \
+ $(XDG_CONFIG_HOME)/notmuch/default/config \
+ $(XDG_CONFIG_HOME)/notmuch/default/hooks/post-new \
+ $(XDG_DATA_HOME)/common-lisp/source \
+ $(XDG_DATA_HOME)/euandreh/e.list.txt \
$(lisp-images)
-
all: $(derived-assets)
@@ -32,6 +36,22 @@ share/man/man1/z.1: bin/z
$(XDG_DATA_HOME)/common-lisp/source:
ln -s $(SRC)/libre $@
+$(XDG_CONFIG_HOME)/alot/config: bin/mailcfg
+ mailcfg alot > $@
+
+$(XDG_CONFIG_HOME)/mbsync/config: bin/mailcfg
+ mailcfg mbsync > $@
+
+$(XDG_CONFIG_HOME)/msmtp/config: bin/mailcfg
+ mailcfg msmtp > $@
+
+$(XDG_CONFIG_HOME)/notmuch/default/config: bin/mailcfg
+ mailcfg notmuchcfg > $@
+
+$(XDG_CONFIG_HOME)/notmuch/default/hooks/post-new: bin/mailcfg
+ mailcfg notmuchhook > $@
+ chmod +x $@
+
$(XDG_CONFIG_HOME)/ssh/id_rsa.pub:
gpg --export-ssh-key eu@euandre.org > $@
chmod 600 $@
diff --git a/bin/mailcfg b/bin/mailcfg
new file mode 100755
index 0000000..ea53a31
--- /dev/null
+++ b/bin/mailcfg
@@ -0,0 +1,280 @@
+#!/bin/sh
+# shellcheck disable=1090,2153
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ mailcfg ACTION
+ mailcfg -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+ ACTION one of:
+ - mbsync
+ - msmtp
+ - notmuchcfg
+ - notmuchhook
+ - alot
+
+
+ Emit the generated configuration file for the chosen email
+ program. Get the configuration files from
+ $XDG_CONFIG_HOME/mailcfg/*.env, where every *.env file is a
+ shell script that defines the variables used in this program:
+ - $NAME
+ - $LABEL
+ - $IMAP
+ - $SMTP
+ - $ADDR
+
+ One of the files also needs to define:
+ - $DEFAULT_NAME
+ - $DEFAULT_ADDR
+
+ An example of such file could be "30-andre@work.com.env":
+
+ #!/bin/sh
+ set -eu
+
+
+ NAME='André!'
+ LABEL='Work'
+ IMAP='imap.work.com'
+ SMTP='smtp.work.com'
+ ADDR='andre@work.com'
+
+
+ Examples:
+
+ Get the alot configuration file:
+
+ $ mailcfg alot
+ EOF
+}
+
+
+for flag; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+ACTION="${1:-}"
+eval "$(assert-arg "$ACTION" 'ACTION')"
+
+CFGDIR="${XDG_CONFIG_HOME:-$HOME/.config}/mailcfg"
+
+
+mbsync() {
+ cat <<-'EOF'
+ SyncState *
+ Create Both
+ Expunge Both
+ Remove Both
+ Sync All
+ EOF
+
+ for env in "$CFGDIR"/*.env; do
+ . "$env"
+ cat <<-EOF
+
+
+ ## $LABEL
+
+ IMAPAccount $LABEL
+ Host $IMAP
+ User $ADDR
+ PassCmd "pass show $ADDR"
+ SSLType IMAPS
+
+ IMAPStore ${LABEL}Remote
+ Account $LABEL
+
+ MaildirStore ${LABEL}Local
+ Path ~/Maildir/$LABEL/
+ Inbox ~/Maildir/$LABEL/INBOX
+ SubFolders Verbatim
+
+ Channel ${LABEL}Folders
+ Far :${LABEL}Remote:
+ Near :${LABEL}Local:
+ Patterns *
+
+ Group $LABEL
+ Channel ${LABEL}Folders
+ EOF
+ done
+}
+
+msmtp() {
+ cat <<-'EOF'
+ defaults
+ auth on
+ tls on
+ port 587
+ syslog on
+ logfile ~/.local/var/log/msmtp
+ EOF
+
+ for env in "$CFGDIR"/*.env; do
+ . "$env"
+ cat <<-EOF
+
+ account $LABEL
+ host $SMTP
+ from $ADDR
+ user $ADDR
+ passwordeval pass show $ADDR
+ EOF
+ done
+
+ cat <<-EOF
+
+ account default : $DEFAULT_LABEL_LC
+ EOF
+}
+
+notmuchcfg() {
+ for env in "$CFGDIR"/*.env; do
+ . "$env"
+ done
+
+ cat <<-EOF
+ [user]
+ name = $DEFAULT_NAME
+ primary_email = $DEFAULT_ADDR
+ EOF
+
+ printf 'other_email = '
+ for env in "$CFGDIR"/*.env; do
+ . "$env"
+ if [ "$ADDR" = "$DEFAULT_ADDR" ]; then
+ continue
+ fi
+ echo "$ADDR"
+ done | paste -sd';'
+
+ cat <<-'EOF'
+
+ [new]
+ tags = new;
+ ignore = .mbsyncstate;.uidvalidity
+
+ [search]
+ exclude_tags = deleted;spam
+
+ [maildir]
+ synchronize_flags = true
+ EOF
+}
+
+notmuchhook() {
+ LABELS=''
+ for env in "$CFGDIR"/*.env; do
+ . "$env"
+ if [ -z "$LABELS" ]; then
+ LABELS="$LABEL"
+ else
+ LABELS="$LABELS $LABEL"
+ fi
+ done
+ sed "s|@DIRS@|$LABELS|g" "$CFGDIR"/post-new
+}
+
+alot() {
+ cat <<-'EOF'
+ attachment_prefix = "~/Downloads/"
+
+ [bindings]
+ i = toggletags inbox
+ I = search folder:/INBOX/ AND NOT tag:killed AND NOT tag:archive
+ EOF
+ echo "
+ z archive
+ s spam
+ u unread
+ r keep
+ t track
+ " | while read -r l; do
+ if [ -z "$l" ]; then
+ continue
+ fi
+ LC="$( echo "$l" | cut -d' ' -f1)"
+ TAG="$(echo "$l" | cut -d' ' -f2)"
+ UC="$(echo "$LC" | tr '[:lower:]' '[:upper:]')"
+ cat <<-EOF
+ $LC = toggletags $TAG
+ $UC = search tag:$TAG AND NOT tag:killed
+ EOF
+ done
+
+ cat <<-'EOF'
+ M = search folder:/lists/ AND NOT tag:killed
+ m = compose --tags inbox
+ [[thread]]
+ v = pipeto urlscan 2>/dev/null
+ V = pipeto 'gpg -d | less'
+ r = reply --all
+ R = reply
+ ' ' = fold; untag unread; move next unfolded
+ P = pipeto 'git am'
+
+ [accounts]
+ EOF
+
+ for env in "$CFGDIR"/*.env; do
+ . "$env"
+ cat <<-EOF
+ [[$LABEL_LC]]
+ realname = $NAME
+ address = $ADDR
+ sendmail_command = msmtpq --account=$LABEL_LC -t
+ sent_box = maildir://~/Maildir/$LABEL/Sent
+ draft_box = maildir://~/Maildir/$LABEL/Drafts
+ gpg_key = 5BDAE9B8B2F6C6BCBB0D6CE581F90EC3CD356060
+ EOF
+ done
+}
+
+
+case "$ACTION" in
+ mbsync|msmtp|notmuchcfg|notmuchhook|alot)
+ "$1"
+ ;;
+ *)
+ printf 'Unsupported ACTION: "%s".\n\n' "$ACTION" >&2
+ usage >&2
+ exit 2
+ ;;
+esac
diff --git a/etc/alot/config b/etc/alot/config
deleted file mode 120000
index 745714d..0000000
--- a/etc/alot/config
+++ /dev/null
@@ -1 +0,0 @@
-../../var/lib/private/tilde/alot/config \ No newline at end of file
diff --git a/etc/mailcfg b/etc/mailcfg
new file mode 120000
index 0000000..fe1b0d6
--- /dev/null
+++ b/etc/mailcfg
@@ -0,0 +1 @@
+/home/andreh/.usr/var/lib/private/tilde/mailcfg \ No newline at end of file
diff --git a/etc/mbsync/config b/etc/mbsync/config
deleted file mode 120000
index a447e0e..0000000
--- a/etc/mbsync/config
+++ /dev/null
@@ -1 +0,0 @@
-../../var/lib/private/tilde/mbsync/config \ No newline at end of file
diff --git a/etc/msmtp/config b/etc/msmtp/config
deleted file mode 120000
index e05c85a..0000000
--- a/etc/msmtp/config
+++ /dev/null
@@ -1 +0,0 @@
-../../var/lib/private/tilde/msmtp/config \ No newline at end of file
diff --git a/etc/notmuch/default/config b/etc/notmuch/default/config
deleted file mode 120000
index a315fdc..0000000
--- a/etc/notmuch/default/config
+++ /dev/null
@@ -1 +0,0 @@
-../../../var/lib/private/tilde/notmuch/default/config \ No newline at end of file
diff --git a/etc/notmuch/default/hooks/post-new b/etc/notmuch/default/hooks/post-new
deleted file mode 120000
index 5d96e3e..0000000
--- a/etc/notmuch/default/hooks/post-new
+++ /dev/null
@@ -1 +0,0 @@
-../../../../var/lib/private/tilde/notmuch/default/hooks/post-new \ No newline at end of file