diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | git-fetch-email.1 | 124 | ||||
-rw-r--r-- | git-fetch-email.sh | 62 |
4 files changed, 196 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore index af43d4e..0084246 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.mk +git-fetch-email imbox diff --git a/Makefile b/Makefile index 312c579..2a9d1d9 100644 --- a/Makefile +++ b/Makefile @@ -7,17 +7,20 @@ CFLAGS += ${LIBRESSL_PREFIX:%=-I%/include} LDFLAGS += ${LIBRESSL_PREFIX:%=-L%/lib} LDLIBS = -ltls +BINS = imbox git-fetch-email +MANS = ${BINS:=.1} + -include config.mk -imbox: +all: ${BINS} clean: - rm -f imbox + rm -f ${BINS} -install: imbox imbox.1 +install: ${BINS} ${MANS} install -d ${PREFIX}/bin ${MANDIR}/man1 - install imbox ${PREFIX}/bin - gzip -c imbox.1 > ${MANDIR}/man1/imbox.1.gz + install ${BINS} ${PREFIX}/bin + for man in ${MANS}; do gzip -c $$man > ${MANDIR}/man1/$$man.gz; done uninstall: - rm -f ${PREFIX}/bin/imbox ${MANDIR}/man1/imbox.1.gz + rm -f ${BINS:%=${PREFIX}/bin/%} ${MANS:%=${MANDIR}/man1/%.gz} diff --git a/git-fetch-email.1 b/git-fetch-email.1 new file mode 100644 index 0000000..2ee3a6f --- /dev/null +++ b/git-fetch-email.1 @@ -0,0 +1,124 @@ +.Dd December 21, 2019 +.Dt GIT-FETCH-EMAIL 1 +.Os +. +.Sh NAME +.Nm git-fetch-email +.Nd fetch patches over IMAP +. +.Sh SYNOPSIS +.Nm git +.Cm fetch-email +.Op Fl C Ar cc +.Op Fl F Ar from +.Op Fl S Ar subject +.Op Fl T Ar to +.Op Fl h Ar host +.Op Fl m Ar mailbox +.Op Fl p Ar port +.Op Ar user +. +.Sh DESCRIPTION +The +.Nm +command is a wrapper around +.Xr imbox 1 +using +.Xr git-config 1 +and +.Xr git-credential 1 . +It fetches patches to be piped into +.Xr git-am 1 . +. +.Pp +The arguments are as follows: +.Bl -tag -width Ds +.It Fl C Ar cc +Fetch patches with matching +.Cm Cc +headers. +The default is the value of +.Cm fetchemail.cc . +. +.It Fl F Ar from +Fetch patches with matching +.Cm From +headers. +The default is the value of +.Cm fetchemail.from . +. +.It Fl S Ar subject +Fetch patches with matching +.Cm Subject +headers. +The default is the value of +.Cm fetchemail.subject , +or +.Ql [PATCH . +. +.It Fl T Ar to +Fetch patches with matching +.Cm To +headers. +The default is the value of +.Cm fetchemail.to . +. +.It Fl h Ar host +Connect to IMAP on +.Ar host . +The default is the value of +.Cm fetchemail.imapServer , +or as inferred by +.Xr imbox 1 . +. +.It Fl m Ar mailbox +Fetch patches from +.Ar mailbox . +The default is the value of +.Cm fetchemail.imapMailbox , +or INBOX. +. +.It Fl p Ar port +Connect to IMAP on +.Ar port . +The default is the value of +.Cm fetchemail.imapServerPort , +or as inferred by +.Xr imbox 1 . +.El +. +.Pp +If +.Ar user +is not provided, +the value of +.Cm fetchemail.imapUser +is used. +If +.Cm fetchemail.imapPass +is set, +it is used as the IMAP login password, +otherwise the password is obtained using +.Xr git-credential 1 . +. +.Sh EXAMPLES +.Bd -literal +git config fetchemail.to list@example.org +git fetch-email june@causal.agency | git am +.Ed +. +.Sh SEE ALSO +.Xr git-am 1 , +.Xr imbox 1 , +.Xr gitcredentials 7 +. +.Sh AUTHORS +.An June Bug Aq Mt june@causal.agency +. +.Sh BUGS +Send mail to +.Aq Mt june@causal.agency +or join +.Li #ascii.town +on +.Li chat.freenode.net . 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}" |