diff options
author | June McEnroe <june@causal.agency> | 2021-02-16 19:45:51 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-02-16 19:45:51 -0500 |
commit | 1805a77fbb239a5cbe9016ce7c974e6f229153cb (patch) | |
tree | e2685df226144fbc0a9176538b5957c313fddd66 | |
parent | Add imapIdle (diff) | |
download | imbox-1805a77fbb239a5cbe9016ce7c974e6f229153cb.tar.gz imbox-1805a77fbb239a5cbe9016ce7c974e6f229153cb.zip |
Add -i to wait for matching messages
Not adding a corresponding flag to git-fetch-email since that doesn't make much sense.
Diffstat (limited to '')
-rw-r--r-- | imbox.1 | 8 | ||||
-rw-r--r-- | imbox.c | 12 |
2 files changed, 16 insertions, 4 deletions
diff --git a/imbox.1 b/imbox.1 index 4a0c34f..a8d1dcd 100644 --- a/imbox.1 +++ b/imbox.1 @@ -1,4 +1,4 @@ -.Dd December 4, 2020 +.Dd February 16, 2021 .Dt IMBOX 1 .Os . @@ -8,7 +8,7 @@ . .Sh SYNOPSIS .Nm -.Op Fl vw +.Op Fl ivw .Op Fl C Ar cc .Op Fl F Ar from .Op Fl S Ar subject @@ -71,6 +71,10 @@ on the domain name of or simply the domain name if no SRV record exists. . +.It Fl i +If no messages initially match the criteria, +wait for new messages using IMAP IDLE. +. .It Fl m Ar mailbox Export messages from .Ar mailbox . diff --git a/imbox.c b/imbox.c index f1ed24a..1852815 100644 --- a/imbox.c +++ b/imbox.c @@ -27,6 +27,7 @@ #include <err.h> #include <inttypes.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -74,16 +75,18 @@ int main(int argc, char *argv[]) { const char *from = NULL; const char *to = NULL; const char *cc = NULL; + bool idle = false; int rppFlags = 0; int opt; - while (0 < (opt = getopt(argc, argv, "C:F:S:T:h:m:p:vw"))) { + while (0 < (opt = getopt(argc, argv, "C:F:S:T:h:im:p:vw"))) { switch (opt) { break; case 'C': cc = optarg; break; case 'F': from = optarg; break; case 'S': subject = optarg; break; case 'T': to = optarg; break; case 'h': host = optarg; + break; case 'i': idle = true; break; case 'm': mailbox = optarg; break; case 'p': port = optarg; break; case 'v': imapVerbose = true; @@ -122,6 +125,7 @@ int main(int argc, char *argv[]) { for (; resp = respOk(imapResp(&imap)), resp.tag != examine; respFree(resp)); respFree(resp); +search:; struct List nums = {0}; enum Atom search = atom("search"); fprintf(imap.w, "%s SEARCH CHARSET UTF-8", Atoms[search]); @@ -132,11 +136,15 @@ int main(int argc, char *argv[]) { fprintf(imap.w, "\r\n"); for (; resp = respOk(imapResp(&imap)), resp.tag != search; respFree(resp)) { if (resp.resp != AtomSearch) continue; - if (!resp.data.len) errx(EX_TEMPFAIL, "no matching messages"); nums = resp.data; resp.data = (struct List) {0}; } respFree(resp); + if (!nums.len) { + if (!idle) errx(EX_TEMPFAIL, "no matching messages"); + respFree(respOk(imapIdle(&imap, atom("idle")))); + goto search; + } enum Atom fetch = atom("fetch"); fprintf(imap.w, "%s FETCH ", Atoms[fetch]); |