about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--git-fetch-email.119
-rw-r--r--git-fetch-email.sh17
2 files changed, 32 insertions, 4 deletions
diff --git a/git-fetch-email.1 b/git-fetch-email.1
index 7ffca89..59d66d9 100644
--- a/git-fetch-email.1
+++ b/git-fetch-email.1
@@ -1,4 +1,4 @@
-.Dd February 16, 2021
+.Dd February 24, 2021
 .Dt GIT-FETCH-EMAIL 1
 .Os
 .
@@ -9,7 +9,7 @@
 .Sh SYNOPSIS
 .Nm git
 .Cm fetch-email
-.Op Fl aiv
+.Op Fl Uaisv
 .Op Fl C Ar cc
 .Op Fl F Ar from
 .Op Fl M Ar mailbox
@@ -80,6 +80,11 @@ headers.
 The default is the value of
 .Cm fetchemail.to .
 .
+.It Fl U , Fl \-unseen , Fl \-no-unseen
+Fetch only patches which are unseen.
+The default is the value of
+.Cm fetchemail.unseen .
+.
 .It Fl a , Fl \-apply
 Apply patches with
 .Xr git-am 1 .
@@ -119,6 +124,16 @@ The default is the value of
 or as inferred by
 .Xr imbox 1 .
 .
+.It Fl s , Fl \-mark\-seen , Fl \-no\-mark\-seen
+Mark matching patches as seen.
+With
+.Fl \-apply ,
+only mark patches if
+.Xr git-am 1
+is successful.
+The default is the value of
+.Cm fetchemail.markSeen .
+.
 .It Fl u Ar user , Fl \-user Ns = Ns Ar user
 Log in to IMAP as
 .Ar user .
diff --git a/git-fetch-email.sh b/git-fetch-email.sh
index cb3969c..571fc4f 100644
--- a/git-fetch-email.sh
+++ b/git-fetch-email.sh
@@ -28,7 +28,11 @@ subject=$(git config fetchemail.subject)
 from=$(git config fetchemail.from)
 to=$(git config fetchemail.to)
 cc=$(git config fetchemail.cc)
+unseen=$(git config --type bool fetchemail.unseen)
+seen=$(git config --type bool fetchemail.markSeen)
 move=$(git config fetchemail.moveTo)
+[ "${unseen}" = 'false' ] && unseen=
+[ "${seen}" = 'false' ] && seen=
 
 OPTS_SPEC="\
 git fetch-email [<options>]
@@ -38,11 +42,13 @@ F,from= fetch patches with matching From headers
 M,move-to= move patches to mailbox
 S,subject= fetch patches with matching Subject headers
 T,to= fetch patches with matching To headers
+U,unseen fetch unseen patches
 a,apply apply patches with git-am
 h,host=! connect to IMAP on host
 i,idle wait for matching patches
 m,mailbox=! fetch patches from mailbox
 p,port=! connect to IMAP on port
+s,mark-seen mark matching patches as seen
 u,user=! log in to IMAP as user
 v,verbose log IMAP protocol to standard error
 "
@@ -57,20 +63,24 @@ while [ $# -gt 0 ]; do
 		(-M) move=$1; shift;;
 		(-S) subject=$1; shift;;
 		(-T) to=$1; shift;;
+		(-U) unseen=true;;
 		(-a) apply=yes;;
 		(-h) host=$1; shift;;
 		(-i) idle=yes;;
 		(-m) mailbox=$1; shift;;
 		(-p) port=$1; shift;;
+		(-s) seen=true; shift;;
 		(-u) user=$1; shift;;
 		(-v) verbose=yes;;
 		(--no-apply) apply=;;
 		(--no-cc) cc=;;
 		(--no-from) from=;;
 		(--no-idle) idle=;;
+		(--no-mark-seen) seen=;;
 		(--no-move-to) move=;;
 		(--no-subject) subject=;;
 		(--no-to) to=;;
+		(--no-unseen) unseen=;;
 		(--no-verbose) verbose=;;
 		(--) break;;
 	esac
@@ -96,7 +106,7 @@ fi
 
 fetch() {
 	echo "${pass}" | imbox -w \
-		${verbose:+-v} ${idle:+-i} \
+		${verbose:+-v} ${idle:+-i} ${unseen:+-U} ${seen:+-s} \
 		${host:+-h "${host}"} \
 		${port:+-p "${port}"} \
 		${mailbox:+-m "${mailbox}"} \
@@ -116,11 +126,14 @@ fetch() {
 }
 
 if [ -n "${apply}" ]; then
+	applySeen=$seen
 	applyMove=$move
+	seen=
 	move=
 	fetch | git am --patch-format=mboxrd "$@"
 	status=$?
-	if [ $status -eq 0 ] && [ -n "${applyMove}" ]; then
+	if [ $status -eq 0 ] && [ -n "${applySeen}${applyMove}" ]; then
+		seen=$applySeen
 		move=$applyMove
 		fetch >/dev/null
 	fi