summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--imbox.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/imbox.c b/imbox.c
index 5ab23c1..0328c34 100644
--- a/imbox.c
+++ b/imbox.c
@@ -26,8 +26,6 @@
 #include <tls.h>
 #include <unistd.h>
 
-#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
-
 static void compile(regex_t *regex, const char *pattern) {
 	if (regex->re_nsub) return;
 	int error = regcomp(regex, pattern, REG_EXTENDED | REG_NEWLINE);
@@ -132,9 +130,10 @@ enum Atom {
 #define X(id, _) id,
 	ENUM_ATOM
 #undef X
+	AtomsLen,
 };
 
-static const char *Atoms[] = {
+static const char *Atoms[AtomsLen] = {
 #define X(id, str) [id] = str,
 	ENUM_ATOM
 #undef X
@@ -142,7 +141,7 @@ static const char *Atoms[] = {
 
 static enum Atom atom(const char *str) {
 	if (!str) return Unknown;
-	for (size_t i = 0; i < ARRAY_LEN(Atoms); ++i) {
+	for (enum Atom i = 0; i < AtomsLen; ++i) {
 		if (!strcmp(str, Atoms[i])) return i;
 	}
 	return Unknown;
@@ -224,20 +223,21 @@ int main(int argc, char *argv[]) {
 	char *line = NULL;
 	size_t cap = 0;
 	while (0 < getline(&line, &cap, imap)) {
-		if (strchr(line, '\r')) *strchr(line, '\r') = '\0';
+		char *cr = strchr(line, '\r');
+		if (cr) *cr = '\0';
 
 		char *rest = line;
 		enum Atom tag = atom(strsep(&rest, " "));
-		if (rest && isdigit(rest[0])) strsep(&rest, " ");
+		if (rest && isdigit(rest[0])) {
+			strsep(&rest, " ");
+		}
 		enum Atom resp = atom(strsep(&rest, " "));
 
-		if (resp == No || resp == Bad) {
+		if (resp == No || resp == Bad || resp == Bye) {
 			errx(
 				EX_CONFIG, "%s: %s %s",
 				Atoms[tag], Atoms[resp], (rest ? rest : "")
 			);
-		} else if (resp == Bye) {
-			errx(EX_UNAVAILABLE, "unexpected BYE: %s", (rest ? rest : ""));
 		}
 
 		switch (tag) {
@@ -262,15 +262,15 @@ int main(int argc, char *argv[]) {
 				for (char *ch = uids; *ch; ++ch) {
 					if (*ch == ' ') *ch = ',';
 				}
-				// FIXME: Grab Content-Encoding as well?
 				fprintf(
 					imap,
-					"%s UID FETCH %s ("
-					"BODY[HEADER.FIELDS (Date From Subject Message-Id)] "
-					"BODY[TEXT]"
-					")\r\n",
+					"%s UID FETCH %s (BODY[HEADER.FIELDS ("
+					"Date From Subject Message-Id Content-Transfer-Encoding"
+					")] BODY[TEXT])\r\n",
 					Atoms[Fetch], uids
 				);
+				free(uids);
+				uids = NULL;
 			}
 			break; case Fetch: {
 				fprintf(imap, "ayy LOGOUT\r\n");
@@ -282,7 +282,7 @@ int main(int argc, char *argv[]) {
 
 		switch (resp) {
 			break; case Search: {
-				if (!rest) errx(EX_TEMPFAIL, "no messages match");
+				if (!rest) errx(EX_TEMPFAIL, "no matching messages");
 				uids = strdup(rest);
 				if (!uids) err(EX_OSERR, "strdup");
 			}
@@ -290,14 +290,14 @@ int main(int argc, char *argv[]) {
 				char *headers = readLiteral(imap, rest);
 
 				ssize_t len = getline(&line, &cap, imap);
-				if (len <= 0) errx(EX_PROTOCOL, "unexpected eof");
+				if (len <= 0) errx(EX_PROTOCOL, "unexpected eof after headers");
 
 				char *body = readLiteral(imap, line);
 
 				len = getline(&line, &cap, imap);
-				if (len <= 0) errx(EX_PROTOCOL, "unexpected eof");
+				if (len <= 0) errx(EX_PROTOCOL, "unexpected eof after body");
 				if (strcmp(line, ")\r\n")) {
-					errx(EX_PROTOCOL, "trailing fetch data");
+					errx(EX_PROTOCOL, "trailing data after headers and body");
 				}
 
 				mboxrd(headers, body);
@@ -307,4 +307,5 @@ int main(int argc, char *argv[]) {
 			break; default:;
 		}
 	}
+	errx(EX_PROTOCOL, "unexpected eof");
 }
rsion of Git there does indeed match that specified in the CGit makefile. Stop this by stripping the ".dirty" suffix from the GIT_VERSION variable. Note that this brings the "Git version" behaviour in line with the "submodule version" case which does not check if the working tree in git/ is modified. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-04-15tests: set TEST_OUTPUT_DIRECTORY to the CGit test directoryJohn Keeping By default, Git's test suite puts the trash directories and test-results directory into its own directory, not that containing the tests being run. This is less convenient for inspecting test failures, so set the output directory to CGit's tests/ directory instead. Note that there is currently a bug in Git whereby it will create the trash directories in our tests/ directory regardless of the value of TEST_OUTPUT_DIRECTORY, and then fail to remove them once the tests are done. This change does currently affect the location of the test-results/ directory though. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-04-15t0109: test more URLsJohn Keeping In order to ensure that we don't access $HOME at some point after initial startup when rendering a specific view, run the strace test on a range of different pages. This ensures that we don't end up reading a configuration later for some specific view. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-04-10cgitrc.5.txt: Specify when scan-path must be defined before.Jason A. Donenfeld Several options must be specified prior to scan-path. This is consistant source of user confusion. Document these facts. Suggested-by: Lukas Fleischer <cgit@cryptocrack.de> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2013-04-10ui-snapshot.c: Prepend "V" when guessing ref namesLukas Fleischer In cgit_print_snapshot_links() we strip leading "v" and "V", while we currently only prepend a lower case "v" when parsing a snapshot file name. This results in broken snapshot links for tags that start with an upper case "V". Avoid this by prepending a "V" as a fallback. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2013-04-10t0107: Skip ZIP tests if unzip(1) isn't availableLukas Fleischer Note that we cannot use skip_all here since some tests have already been executed when ZIP tests are reached. Use test prerequisites to skip everything using unzip(1) if the binary is not available instead. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2013-04-10tests/: Do not use `sed -i`Lukas Fleischer "-i" isn't part of the POSIX standard and doesn't work on several platforms such as OpenBSD. Use a temporary file instead. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2013-04-10Add branch-sort and repo.branch-sort options.Jason A. Donenfeld When set to "name", branches are sorted by name, which is the current default. When set to "age", branches are sorted by the age of the repository. This feature was requested by Konstantin Ryabitsev for use on kernel.org. Proposed-by: Konstantin Ryabitsev <mricon@kernel.org> 2013-04-10t0109: chain operations with &&John Keeping Without '&&' between operations, we will not detect if strace or cgit exit with an error status, which would cause a false positive test status in this case. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-04-10cgit.c: Do not restore unset environment variablesLukas Fleischer getenv() returns a NULL pointer if the specified variable name cannot be found in the environment. However, some setenv() implementations crash if a NULL pointer is passed as second argument. Only restore variables that are not NULL. See commit d96d2c98ebc4c2d3765f5b35c4142e0e828a421b for a related patch. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2013-04-09t0107: Use `tar -z` for gzip'ed archivesLukas Fleischer