diff options
Diffstat (limited to '')
-rw-r--r-- | git-fetch-email.sh | 62 |
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}" |