about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-26 21:02:54 -0400
committerJune McEnroe <june@causal.agency>2020-04-26 21:02:54 -0400
commit96068224350f214ff6bdea8c401eeb13750cc369 (patch)
tree568d0483fece04e278714a6fa524aaa5453bba72
parentRearrange some of archive.h (diff)
downloadbubger-96068224350f214ff6bdea8c401eeb13750cc369.tar.gz
bubger-96068224350f214ff6bdea8c401eeb13750cc369.zip
Add -q to exit non-zero on early exit
Diffstat (limited to '')
-rw-r--r--archive.c27
-rw-r--r--bubger.15
2 files changed, 23 insertions, 9 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;
 }
diff --git a/bubger.1 b/bubger.1
index 07ae858..b626f6c 100644
--- a/bubger.1
+++ b/bubger.1
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl v
+.Op Fl qv
 .Op Fl C Ar path
 .Op Fl a Ar algo
 .Op Fl h Ar head
@@ -65,6 +65,9 @@ The default port is
 .Pq 993 .
 TLS without STARTTLS is assumed.
 .
+.It Fl q
+Exit non-zero if no changes are made.
+.
 .It Fl s Ar search
 Limit threads to messages matching
 .Ar search .