about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-06-05 15:57:32 -0400
committerJune McEnroe <june@causal.agency>2021-06-05 15:57:32 -0400
commit2ed06d33b75c170d997a55de6543b9e206fbf92b (patch)
tree7fb2dbe648aaefd70cdda838aa899def31eb59c7
parentReplace freenode with tilde.chat (diff)
downloadimbox-2ed06d33b75c170d997a55de6543b9e206fbf92b.tar.gz
imbox-2ed06d33b75c170d997a55de6543b9e206fbf92b.zip
Add -H flag to fetch only headers
Basically to quickly test which messages are getting matched without
having to scroll through their bodies.
-rw-r--r--git-fetch-email.17
-rw-r--r--git-fetch-email.sh6
-rw-r--r--imbox.17
-rw-r--r--imbox.c10
4 files changed, 22 insertions, 8 deletions
diff --git a/git-fetch-email.1 b/git-fetch-email.1
index 7b3be53..fcf2ed5 100644
--- a/git-fetch-email.1
+++ b/git-fetch-email.1
@@ -1,4 +1,4 @@
-.Dd February 24, 2021
+.Dd June  5, 2021
 .Dt GIT-FETCH-EMAIL 1
 .Os
 .
@@ -9,7 +9,7 @@
 .Sh SYNOPSIS
 .Nm git
 .Cm fetch-email
-.Op Fl Uaisv
+.Op Fl HUaisv
 .Op Fl C Ar cc
 .Op Fl F Ar from
 .Op Fl M Ar mailbox
@@ -53,6 +53,9 @@ headers.
 The default is the value of
 .Cm fetchemail.from .
 .
+.It Fl H , Fl \-headers
+Fetch only patch headers.
+.
 .It Fl M Ar mailbox , Fl \-move\-to Ns = Ns Ar mailbox , Fl \-no\-move\-to
 Move matching patches to
 .Ar mailbox .
diff --git a/git-fetch-email.sh b/git-fetch-email.sh
index e3fc953..574d04f 100644
--- a/git-fetch-email.sh
+++ b/git-fetch-email.sh
@@ -18,6 +18,7 @@ set -u
 
 idle=
 apply=
+headers=
 verbose=
 host=$(git config fetchemail.imapServer)
 port=$(git config fetchemail.imapServerPort)
@@ -40,6 +41,7 @@ git fetch-email [<options>]
 --
 C,cc= fetch patches with matching Cc headers
 F,from= fetch patches with matching From headers
+H,headers fetch only patch headers
 M,move-to= move patches to mailbox
 S,subject= fetch patches with matching Subject headers
 T,to= fetch patches with matching To headers
@@ -61,6 +63,7 @@ while [ $# -gt 0 ]; do
 	case "${opt}" in
 		(-C) cc=$1; shift;;
 		(-F) from=$1; shift;;
+		(-H) headers=yes;;
 		(-M) move=$1; shift;;
 		(-S) subject=$1; shift;;
 		(-T) to=$1; shift;;
@@ -76,6 +79,7 @@ while [ $# -gt 0 ]; do
 		(--no-apply) apply=;;
 		(--no-cc) cc=;;
 		(--no-from) from=;;
+		(--no-headers) headers=;;
 		(--no-idle) idle=;;
 		(--no-mark-seen) seen=;;
 		(--no-move-to) move=;;
@@ -107,7 +111,7 @@ fi
 
 fetch() {
 	printf '%s' "${pass}" | imbox -w \
-		${verbose:+-v} ${idle:+-i} ${unseen:+-U} ${seen:+-s} \
+		${verbose:+-v} ${idle:+-i} ${headers:+-H} ${unseen:+-U} ${seen:+-s} \
 		${host:+-h "${host}"} \
 		${port:+-p "${port}"} \
 		${mailbox:+-m "${mailbox}"} \
diff --git a/imbox.1 b/imbox.1
index f362e91..abf0875 100644
--- a/imbox.1
+++ b/imbox.1
@@ -1,4 +1,4 @@
-.Dd March  3, 2021
+.Dd June  5, 2021
 .Dt IMBOX 1
 .Os
 .
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl Uisvw
+.Op Fl HUisvw
 .Op Fl C Ar cc
 .Op Fl F Ar from
 .Op Fl M Ar mailbox
@@ -51,6 +51,9 @@ Export messages with matching
 .Cm From
 headers.
 .
+.It Fl H
+Export only the message headers.
+.
 .It Fl M Ar mailbox
 Move matching messages to
 .Ar mailbox
diff --git a/imbox.c b/imbox.c
index 1f65517..a4d34d7 100644
--- a/imbox.c
+++ b/imbox.c
@@ -54,6 +54,7 @@ static void mboxrd(char *header, char *body) {
 		*crlf = '\0';
 		printf("%s\n", header);
 	}
+	if (!body) return;
 	for (char *crlf; (crlf = strstr(body, "\r\n")); body = &crlf[2]) {
 		*crlf = '\0';
 		char *from = body;
@@ -86,15 +87,17 @@ int main(int argc, char *argv[]) {
 	const char *cc = NULL;
 	bool unseen = false;
 	bool idle = false;
+	bool body = true;
 
 	const char *move = NULL;
 	bool seen = false;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "C:F:M:S:T:Uh:im:p:svw"))) {
+	while (0 < (opt = getopt(argc, argv, "C:F:HM:S:T:Uh:im:p:svw"))) {
 		switch (opt) {
 			break; case 'C': cc = optarg;
 			break; case 'F': from = optarg;
+			break; case 'H': body = false;
 			break; case 'M': move = optarg;
 			break; case 'S': subject = optarg;
 			break; case 'T': to = optarg;
@@ -169,7 +172,8 @@ search:;
 	fprintf(imap.w, "%s FETCH ", Atoms[fetch]);
 	printNums(imap.w, nums);
 	fprintf(
-		imap.w, " (BODY[HEADER.FIELDS (" FETCH_HEADERS ")] BODY[TEXT])\r\n"
+		imap.w, " (BODY[HEADER.FIELDS (" FETCH_HEADERS ")]%s)\r\n",
+		(body ? " BODY[TEXT]" : "")
 	);
 	for (; resp = respOk(imapResp(&imap)), resp.tag != fetch; respFree(resp)) {
 		if (resp.resp != AtomFetch) continue;
@@ -191,7 +195,7 @@ search:;
 		}
 		mboxrd(
 			dataCheck(header, String).string,
-			dataCheck(body, String).string
+			(body.type == String ? body.string : NULL)
 		);
 	}
 	respFree(resp);