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