summary refs log tree commit diff
diff options
context:
space:
mode:
-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 .