summary refs log tree commit diff
path: root/git-fetch-email.sh
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-21 14:47:03 -0500
committerJune McEnroe <june@causal.agency>2019-12-21 14:47:03 -0500
commit56c0a0cc104c1d9f74299ae5e3513109dccc80c9 (patch)
tree4b5aee79baea985564804e6924aa715adc2354cd /git-fetch-email.sh
parentDetermine host by SRV lookup (diff)
downloadimbox-56c0a0cc104c1d9f74299ae5e3513109dccc80c9.tar.gz
imbox-56c0a0cc104c1d9f74299ae5e3513109dccc80c9.zip
Add git-fetch-email wrapper
Diffstat (limited to '')
-rw-r--r--git-fetch-email.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/git-fetch-email.sh b/git-fetch-email.sh
new file mode 100644
index 0000000..ed18141
--- /dev/null
+++ b/git-fetch-email.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+set -u
+
+host=$(git config fetchemail.imapServer)
+port=$(git config fetchemail.imapServerPort)
+user=$(git config fetchemail.imapUser)
+pass=$(git config fetchemail.imapPass)
+mailbox=$(git config fetchemail.imapMailbox)
+subject=$(git config fetchemail.subject)
+from=$(git config fetchemail.from)
+to=$(git config fetchemail.to)
+cc=$(git config fetchemail.cc)
+
+set -- $(getopt 'C:F:S:T:h:m:p:' $*)
+for opt; do
+	shift;
+	case "$opt" in
+		(-C) cc=$1; shift;;
+		(-F) from=$1; shift;;
+		(-S) subject=$1; shift;;
+		(-T) to=$1; shift;;
+		(-h) host=$1; shift;;
+		(-m) mailbox=$1; shift;;
+		(-p) port=$1; shift;;
+		(--) break;;
+	esac
+done
+[ $# -ne 0 ] && user=$1
+if [ -z "${user:-}" ]; then
+	echo "$0: username required"
+	exit 1
+fi
+
+description() {
+	cat <<-EOF
+		protocol=imaps
+		host=${user#*@}
+		username=${user%@*}
+		${pass:+password=${pass}}
+	EOF
+}
+
+pass=$(description | git credential fill | grep '^password=')
+pass=${pass#*=}
+
+echo "${pass}" | imbox -w \
+	${host:+-h "${host}"} \
+	${port:+-p "${port}"} \
+	${mailbox:+-m "${mailbox}"} \
+	${subject:+-S "${subject}"} \
+	${from:+-F "${from}"} \
+	${to:+-T "${to}"} \
+	${cc:+-C "${cc}"} \
+	${user}
+status=$?
+
+if [ "${status}" -ne 78 ]; then
+	description | git credential approve
+else
+	description | git credential reject
+fi
+exit "${status}"