From 56c0a0cc104c1d9f74299ae5e3513109dccc80c9 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 21 Dec 2019 14:47:03 -0500 Subject: Add git-fetch-email wrapper --- git-fetch-email.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 git-fetch-email.sh (limited to 'git-fetch-email.sh') 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}" -- cgit 1.4.1