about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-01-27 15:23:34 -0500
committerJune McEnroe <june@causal.agency>2020-01-27 15:24:22 -0500
commit61ff06502622e11e5b9a7b6b3c1f1332fe3c95b7 (patch)
tree35aa94a78dac46a50ba88deb97fcceab6369a8ad
parentCheck envelope date rather than internal date (diff)
downloadnotemap-61ff06502622e11e5b9a7b6b3c1f1332fe3c95b7.tar.gz
notemap-61ff06502622e11e5b9a7b6b3c1f1332fe3c95b7.zip
Skip if dates match
-rw-r--r--notemap.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/notemap.c b/notemap.c
index 0ba364b..1a5cef2 100644
--- a/notemap.c
+++ b/notemap.c
@@ -198,6 +198,8 @@ static enum Atom atom(const char *str) {
 	return Unknown;
 }
 
+#define DATE_FORMAT "%a, %e %b %Y %H:%M:%S %z"
+
 static void append(
 	FILE *imap, const char *mailbox,
 	const char *from, const char *uuid, const char *path
@@ -211,7 +213,7 @@ static void append(
 
 	char date[sizeof("Mon, 00 Jan 0000 00:00:00 -0000")];
 	strftime(
-		date, sizeof(date), "%a, %e %b %Y %H:%M:%S %z",
+		date, sizeof(date), DATE_FORMAT,
 		localtime(&status.st_mtime)
 	);
 
@@ -392,9 +394,8 @@ int main(int argc, char *argv[]) {
 				fprintf(imap, "%s SELECT \"%s\"\r\n", Atoms[Next], mailbox);
 			}
 
-			break; case Next: {
+			break; case Next: Next: {
 				ssize_t len;
-next:
 				len = getline(&entry, &entryCap, map);
 				if (ferror(map)) err(EX_IOERR, "%s", path);
 				if (len < 1) {
@@ -419,18 +420,16 @@ next:
 			}
 
 			break; case Search: {
-				if (!seq) goto append;
+				if (!seq) goto Fetch;
 				fprintf(imap, "%s FETCH %d ENVELOPE\r\n", Atoms[Fetch], seq);
 			}
 
-			break; case Fetch: {
-append:
+			break; case Fetch: Fetch: {
 				append(imap, mailbox, user, uuid, note);
 			}
 
 			break; case Append: {
-				if (!seq) goto next;
-				// FIXME: Apparently we still get new flags back...
+				if (!seq) goto Next;
 				fprintf(
 					imap, "%s STORE %d +FLAGS.SILENT (\\Deleted)\r\n",
 					Atoms[Next], seq
@@ -452,23 +451,23 @@ append:
 		}
 
 		if (resp == Fetch) {
-			if (!strncmp(rest, "(FLAGS", 6)) continue;
+			if (strncmp(rest, "(ENVELOPE", 9)) continue;
 
-			// TODO: Factor out format string.
 			struct tm date = {0};
 			rest = strptime(
-				rest, "(ENVELOPE (\"%a, %e %b %Y %H:%M:%S %z\"", &date
+				rest, "(ENVELOPE (\"" DATE_FORMAT "\"", &date
 			);
-			if (!rest) errx(EX_PROTOCOL, "invalid INTERNALDATE");
+			if (!rest) errx(EX_PROTOCOL, "invalid envelope date");
 
 			struct stat status;
 			int error = stat(note, &status);
 			if (error) err(EX_NOINPUT, "%s", note);
 
 			if (!force && status.st_mtime < mktime(&date)) {
-				errx(EX_TEMPFAIL, "%s: note has been modified in mailbox", note);
+				errx(EX_TEMPFAIL, "%s: note modified in mailbox", note);
+			} else if (status.st_mtime == mktime(&date)) {
+				goto Next;
 			}
-			// TODO: Skip if times are the same.
 		}
 	}
 }