From 2ed06d33b75c170d997a55de6543b9e206fbf92b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 5 Jun 2021 15:57:32 -0400 Subject: Add -H flag to fetch only headers Basically to quickly test which messages are getting matched without having to scroll through their bodies. --- imbox.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'imbox.c') 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); -- cgit 1.4.1