summary refs log tree commit diff
path: root/git-fetch-email.sh
blob: 3272a2b1177601ac61822561027c81a3824c2201 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
# Copyright (C) 2019, 2020  C. McEnroe <june@causal.agency>
#
# 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 <https://www.gnu.org/licenses/>.

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)

OPTS_SPEC="\
git fetch-email [<options>]
--
C,cc= fetch patches with matching Cc headers
F,from= fetch patches with matching From headers
S,subject= fetch patches with matching Subject headers
T,to= fetch patches with matching To headers
a,apply apply patches with git-am
h,host=! connect to IMAP on host
m,mailbox=! fetch patches from mailbox
p,port=! connect to IMAP on port
u,user=! log in to IMAP as user
v,verbose log IMAP protocol to standard error
"
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"

while [ $# -gt 0 ]; do
	opt=$1
	shift
	case "${opt}" in
		(-C) cc=$1; shift;;
		(-F) from=$1; shift;;
		(-S) subject=$1; shift;;
		(-T) to=$1; shift;;
		(-a) apply=1;;
		(-h) host=$1; shift;;
		(-m) mailbox=$1; shift;;
		(-p) port=$1; shift;;
		(-u) user=$1; shift;;
		(-v) verbose=1;;
		(--no-apply) apply=;;
		(--no-cc) cc=;;
		(--no-from) from=;;
		(--no-subject) subject=;;
		(--no-to) to=;;
		(--no-verbose) verbose=;;
		(--) break;;
	esac
done
if [ -z "${user:-}" ]; then
	echo "${0}: username required" >&2
	exit 1
fi

description() {
	cat <<-EOF
		protocol=imaps
		host=${host:-${user#*@}}
		username=${user%@*}
		${pass:+password=${pass}}
	EOF
}

if [ -z "${pass:-}" ]; then
	pass=$(description | git credential fill | grep '^password=')
	pass=${pass#*=}
fi

fetch() {
	echo "${pass}" | imbox -w \
		${verbose:+-v} \
		${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
	return $status
}

if [ -n "${apply:-}" ]; then
	fetch | git am --patch-format=mboxrd "$@"
else
	fetch
fi
hover-highlight'> 2022-02-20Remove unused mbs.len field from struct EditJune McEnroe 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe In other words, warn when a function is missing static. I don't see why this isn't in -Wextra. 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe I know, it feels wrong. 2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe