From 6a5616b3d4d543998037f7063bd49fa7d5d41433 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 24 Feb 2021 14:42:17 -0500 Subject: Add -U and -s flags to match unseen and mark as seen --- imbox.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'imbox.c') diff --git a/imbox.c b/imbox.c index b385366..70b1270 100644 --- a/imbox.c +++ b/imbox.c @@ -68,29 +68,35 @@ static void mboxrd(char *header, char *body) { } int main(int argc, char *argv[]) { + int rppFlags = 0; const char *host = NULL; const char *port = "imaps"; const char *mailbox = "INBOX"; + const char *subject = "[PATCH"; const char *from = NULL; const char *to = NULL; const char *cc = NULL; - const char *move = NULL; + bool unseen = false; bool idle = false; - int rppFlags = 0; + + const char *move = NULL; + bool seen = false; int opt; - while (0 < (opt = getopt(argc, argv, "C:F:M:S:T:h:im:p:vw"))) { + while (0 < (opt = getopt(argc, argv, "C:F:M:S:T:Uh:im:p:svw"))) { 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 'U': unseen = true; break; case 'h': host = optarg; break; case 'i': idle = true; break; case 'm': mailbox = optarg; break; case 'p': port = optarg; + break; case 's': seen = true; break; case 'v': imapVerbose = true; break; case 'w': rppFlags |= RPP_STDIN; break; default: return EX_USAGE; @@ -125,7 +131,7 @@ int main(int argc, char *argv[]) { enum Atom examine = atom("examine"); fprintf( imap.w, "%s %s \"%s\"\r\n", - Atoms[examine], (move ? "SELECT" : "EXAMINE"), mailbox + Atoms[examine], (move || seen ? "SELECT" : "EXAMINE"), mailbox ); for (; resp = respOk(imapResp(&imap)), resp.tag != examine; respFree(resp)); respFree(resp); @@ -138,6 +144,7 @@ search:; if (from) fprintf(imap.w, " FROM \"%s\"", from); if (to) fprintf(imap.w, " TO \"%s\"", to); if (cc) fprintf(imap.w, " CC \"%s\"", cc); + if (unseen) fprintf(imap.w, " UNSEEN"); fprintf(imap.w, "\r\n"); for (; resp = respOk(imapResp(&imap)), resp.tag != search; respFree(resp)) { if (resp.resp != AtomSearch) continue; @@ -185,6 +192,18 @@ search:; } respFree(resp); + if (seen) { + enum Atom sto = atom("store"); + fprintf(imap.w, "%s STORE ", Atoms[sto]); + 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, " +FLAGS.SILENT (\\Seen)\r\n"); + for (; resp = respOk(imapResp(&imap)), resp.tag != sto; respFree(resp)); + respFree(resp); + } + if (move) { enum Atom mov = atom("move"); fprintf(imap.w, "%s MOVE ", Atoms[mov]); -- cgit 1.4.1