diff options
Diffstat (limited to '')
-rw-r--r-- | archive.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/archive.c b/archive.c index 6a3f612..a3b7f84 100644 --- a/archive.c +++ b/archive.c @@ -56,7 +56,16 @@ static void createDir(const char *path) { if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", path); } +static void createDirs(void) { + createDir("UID"); + createDir("attachment"); + createDir("message"); + createDir("thread"); +} + int main(int argc, char *argv[]) { + int exitStatus = 0; + const char *host = NULL; const char *port = "imaps"; const char *user = NULL; @@ -66,7 +75,7 @@ int main(int argc, char *argv[]) { const char *algo = "REFERENCES"; const char *search = "ALL"; - for (int opt; 0 < (opt = getopt(argc, argv, "C:a:h:m:p:s:t:u:vw:"));) { + for (int opt; 0 < (opt = getopt(argc, argv, "C:a:h:m:p:qs:t:u:vw:"));) { switch (opt) { break; case 'C': { int error = chdir(optarg); @@ -76,6 +85,7 @@ int main(int argc, char *argv[]) { break; case 'h': concatHead = optarg; break; case 'm': baseAddress = optarg; break; case 'p': port = optarg; + break; case 'q': exitStatus = EXIT_FAILURE; break; case 's': search = optarg; break; case 't': baseTitle = optarg; break; case 'u': baseURL = optarg; @@ -107,9 +117,6 @@ int main(int argc, char *argv[]) { if (!pass) errx(EX_CONFIG, ENV_PASSWORD " unset"); } - FILE *imapRead, *imap; - imapOpen(&imapRead, &imap, host, port); - enum { Ready, Login, @@ -130,6 +137,9 @@ int main(int argc, char *argv[]) { uint32_t uidNext = 0; struct List threads = {0}; struct Envelope *envelopes = NULL; + + FILE *imapRead, *imap; + imapOpen(&imapRead, &imap, host, port); for (struct Resp resp; resp = imapResp(imapRead), resp.resp != AtomBye;) { if (resp.resp == AtomNo || resp.resp == AtomBad) { errx(EX_CONFIG, "%s %s", Atoms[resp.resp], resp.text); @@ -170,6 +180,8 @@ int main(int argc, char *argv[]) { if (uidNext == prev) { fprintf(imap, "ayy LOGOUT\r\n"); state = Logout; + } else { + exitStatus = EXIT_SUCCESS; } } } @@ -187,10 +199,7 @@ int main(int argc, char *argv[]) { if (!resp.data.len) { errx(EX_TEMPFAIL, "no messages matching %s", search); } - createDir("UID"); - createDir("attachment"); - createDir("message"); - createDir("thread"); + createDirs(); threads = resp.data; resp.data = (struct List) {0}; @@ -237,4 +246,6 @@ int main(int argc, char *argv[]) { } fclose(imapRead); fclose(imap); + + return exitStatus; } |