#!/bin/sh # Copyright (C) 2019 C. McEnroe # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . 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) args=$(getopt 'C:F:S:T:h:m:p:' $*) [ $? -ne 0 ] && exit 1 set -- $args 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}"