summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-02-16 20:38:04 -0500
committerJune McEnroe <june@causal.agency>2021-02-16 20:38:04 -0500
commit4ea8f158a7965f866e91e5f11c1ba189079bd935 (patch)
tree25cea835df81a25a6fac7780e7a2108d61bc6f88
parentDon't use Fl Fl for long options (diff)
downloadimbox-4ea8f158a7965f866e91e5f11c1ba189079bd935.tar.gz
imbox-4ea8f158a7965f866e91e5f11c1ba189079bd935.zip
Add -M to move messages after export
-rw-r--r--git-fetch-email.114
-rw-r--r--git-fetch-email.sh15
-rw-r--r--imbox.148
-rw-r--r--imbox.c23
4 files changed, 78 insertions, 22 deletions
diff --git a/git-fetch-email.1 b/git-fetch-email.1
index 956df5d..de61874 100644
--- a/git-fetch-email.1
+++ b/git-fetch-email.1
@@ -1,4 +1,4 @@
-.Dd May  2, 2020
+.Dd February 16, 2021
 .Dt GIT-FETCH-EMAIL 1
 .Os
 .
@@ -12,6 +12,7 @@
 .Op Fl av
 .Op Fl C Ar cc
 .Op Fl F Ar from
+.Op Fl M Ar mailbox
 .Op Fl S Ar subject
 .Op Fl T Ar to
 .Op Fl h Ar host
@@ -52,6 +53,17 @@ headers.
 The default is the value of
 .Cm fetchemail.from .
 .
+.It Fl M Ar mailbox , Fl \-move\-to Ns = Ns Ar mailbox , Fl \-no\-move\-to
+Move matching patches to
+.Ar mailbox .
+With
+.Fl \-apply ,
+only move patches if
+.Xr git-am 1
+is successful.
+The default is the value of
+.Cm fetchemail.moveTo .
+.
 .It Fl S Ar subject, Fl \-subject Ns = Ns Ar subject , Fl \-no\-subject
 Fetch patches with matching
 .Cm Subject
diff --git a/git-fetch-email.sh b/git-fetch-email.sh
index 52aa74f..6109091 100644
--- a/git-fetch-email.sh
+++ b/git-fetch-email.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2019, 2020  C. McEnroe <june@causal.agency>
+# Copyright (C) 2019-2021  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
@@ -27,12 +27,14 @@ subject=$(git config fetchemail.subject)
 from=$(git config fetchemail.from)
 to=$(git config fetchemail.to)
 cc=$(git config fetchemail.cc)
+move=$(git config fetchemail.moveTo)
 
 OPTS_SPEC="\
 git fetch-email [<options>]
 --
 C,cc= fetch patches with matching Cc headers
 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
 a,apply apply patches with git-am
@@ -50,6 +52,7 @@ while [ $# -gt 0 ]; do
 	case "${opt}" in
 		(-C) cc=$1; shift;;
 		(-F) from=$1; shift;;
+		(-M) move=$1; shift;;
 		(-S) subject=$1; shift;;
 		(-T) to=$1; shift;;
 		(-a) apply=yes;;
@@ -61,6 +64,7 @@ while [ $# -gt 0 ]; do
 		(--no-apply) apply=;;
 		(--no-cc) cc=;;
 		(--no-from) from=;;
+		(--no-move-to) move=;;
 		(--no-subject) subject=;;
 		(--no-to) to=;;
 		(--no-verbose) verbose=;;
@@ -96,6 +100,7 @@ fetch() {
 		${from:+-F "${from}"} \
 		${to:+-T "${to}"} \
 		${cc:+-C "${cc}"} \
+		${move:+-M "${move}"} \
 		${user}
 	status=$?
 	if [ $status -ne 78 ]; then
@@ -107,7 +112,15 @@ fetch() {
 }
 
 if [ -n "${apply}" ]; then
+	applyMove=$move
+	move=
 	fetch | git am --patch-format=mboxrd "$@"
+	status=$?
+	if [ $status -eq 0 ] && [ -n "${applyMove}" ]; then
+		move=$applyMove
+		fetch
+	fi
+	exit $status
 else
 	fetch
 fi
diff --git a/imbox.1 b/imbox.1
index a8d1dcd..22e2df3 100644
--- a/imbox.1
+++ b/imbox.1
@@ -11,6 +11,7 @@
 .Op Fl ivw
 .Op Fl C Ar cc
 .Op Fl F Ar from
+.Op Fl M Ar mailbox
 .Op Fl S Ar subject
 .Op Fl T Ar to
 .Op Fl h Ar host
@@ -52,6 +53,11 @@ Export messages with matching
 .Cm From
 headers.
 .
+.It Fl M Ar mailbox
+Move matching messages to
+.Ar mailbox
+after exporting them.
+.
 .It Fl S Ar subject
 Export messages with matching
 .Cm Subject
@@ -113,21 +119,40 @@ imbox -T list+imbox@causal.agency june@causal.agency
 .It
 .Rs
 .%A M. Crispin
-.%Q University of Washington
 .%T INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1
 .%I IETF
-.%N RFC 3501
-.%D March 2003
+.%R RFC 3501
 .%U https://tools.ietf.org/html/rfc3501
+.%D March 2003
+.Re
+.It
+.Rs
+.%A L. Esibov
+.%A A. Gulbrandsen
+.%A P. Vixie
+.%T A DNS RR for specifying the location of services (DNS SRV)
+.%I IETF
+.%R RFC 2782
+.%U https://tools.ietf.org/html/rfc2782
+.%D February 2000
+.Re
+.It
+.Rs
+.%A A. Gulbrandsen
+.%T Internet Message Access Protocol (IMAP) - MOVE Extension
+.%I IETF
+.%R RFC 6851
+.%U https://tools.ietf.org/html/rfc6851
+.%D January 2013
 .Re
 .It
 .Rs
 .%A E. Hall
 .%T The application/mbox Media Type
 .%I IETF
-.%N RFC 4155
-.%D September 2005
+.%R RFC 4155
 .%U https://tools.ietf.org/html/rfc4155
+.%D September 2005
 .Re
 .It
 .Rs
@@ -135,19 +160,8 @@ imbox -T list+imbox@causal.agency june@causal.agency
 .%T DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION
 .%I IETF
 .%R RFC 1035
-.%D November 1987
 .%U https://tools.ietf.org/html/rfc1035
-.Re
-.It
-.Rs
-.%A A. Gulbrandsen
-.%A P. Vixie
-.%A L. Esibov
-.%T A DNS RR for specifying the location of services (DNS SRV)
-.%I IETF
-.%R RFC 2782
-.%D February 2000
-.%U https://tools.ietf.org/html/rfc2782
+.%D November 1987
 .Re
 .El
 .
diff --git a/imbox.c b/imbox.c
index 1852815..b385366 100644
--- a/imbox.c
+++ b/imbox.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2019, 2020  C. McEnroe <june@causal.agency>
+/* Copyright (C) 2019-2021  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
@@ -75,14 +75,16 @@ int main(int argc, char *argv[]) {
 	const char *from = NULL;
 	const char *to = NULL;
 	const char *cc = NULL;
+	const char *move = NULL;
 	bool idle = false;
 	int rppFlags = 0;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "C:F:S:T:h:im:p:vw"))) {
+	while (0 < (opt = getopt(argc, argv, "C:F:M:S:T:h:im:p:vw"))) {
 		switch (opt) {
 			break; case 'C': cc = optarg;
 			break; case 'F': from = optarg;
+			break; case 'M': move = optarg;
 			break; case 'S': subject = optarg;
 			break; case 'T': to = optarg;
 			break; case 'h': host = optarg;
@@ -121,7 +123,10 @@ int main(int argc, char *argv[]) {
 	respFree(resp);
 
 	enum Atom examine = atom("examine");
-	fprintf(imap.w, "%s EXAMINE \"%s\"\r\n", Atoms[examine], mailbox);
+	fprintf(
+		imap.w, "%s %s \"%s\"\r\n",
+		Atoms[examine], (move ? "SELECT" : "EXAMINE"), mailbox
+	);
 	for (; resp = respOk(imapResp(&imap)), resp.tag != examine; respFree(resp));
 	respFree(resp);
 
@@ -180,6 +185,18 @@ search:;
 	}
 	respFree(resp);
 
+	if (move) {
+		enum Atom mov = atom("move");
+		fprintf(imap.w, "%s MOVE ", Atoms[mov]);
+		for (size_t i = 0; i < nums.len; ++i) {
+			uint32_t num = dataCheck(nums.ptr[i], Number).number;
+			fprintf(imap.w, "%s%" PRIu32, (i ? "," : ""), num);
+		}
+		fprintf(imap.w, " \"%s\"\r\n", move);
+		for (; resp = respOk(imapResp(&imap)), resp.tag != mov; respFree(resp));
+		respFree(resp);
+	}
+
 	fprintf(imap.w, "ayy LOGOUT\r\n");
 	fclose(imap.r);
 	fclose(imap.w);