summary refs log tree commit diff
path: root/archive.c
diff options
context:
space:
mode:
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/archive.c b/archive.c
index 1ef4f33..91c6118 100644
--- a/archive.c
+++ b/archive.c
@@ -82,6 +82,7 @@ static void createDirs(void) {
 
 int main(int argc, char *argv[]) {
 	int exitStatus = 0;
+	bool truncate = false;
 
 	const char *host = NULL;
 	const char *port = "imaps";
@@ -95,7 +96,7 @@ int main(int argc, char *argv[]) {
 
 	for (
 		int opt;
-		0 < (opt = getopt(argc, argv, "C:H:S:a:h:im:p:qs:t:u:vw:y:"));
+		0 < (opt = getopt(argc, argv, "C:H:S:T:a:h:im:p:qs:tu:vw:y:"));
 	) {
 		switch (opt) {
 			break; case 'C': {
@@ -104,6 +105,7 @@ int main(int argc, char *argv[]) {
 			}
 			break; case 'H': concatHead = optarg;
 			break; case 'S': search = optarg;
+			break; case 'T': baseTitle = optarg;
 			break; case 'a': algo = optarg;
 			break; case 'h': host = optarg;
 			break; case 'i': idle = true;
@@ -111,7 +113,7 @@ int main(int argc, char *argv[]) {
 			break; case 'p': port = optarg;
 			break; case 'q': quiet = true; exitStatus = EXIT_FAILURE;
 			break; case 's': baseSubscribe = optarg;
-			break; case 't': baseTitle = optarg;
+			break; case 't': truncate = true;
 			break; case 'u': baseURL = optarg;
 			break; case 'v': imapVerbose = true;
 			break; case 'w': passPath = optarg;
@@ -177,7 +179,13 @@ int main(int argc, char *argv[]) {
 	for (; resp = respOk(imapResp(&imap)), resp.tag != login; respFree(resp));
 	respFree(resp);
 
-examine:;
+examine:
+	if (truncate) {
+		int error = ftruncate(STDOUT_FILENO, 0);
+		if (error) warn("ftruncate");
+		rewind(stdout);
+	}
+
 	uint32_t uidNext = 0;
 	uint32_t uidValidity = 0;
 	enum Atom examine = atom("examine");
@@ -259,6 +267,7 @@ concat:;
 
 	concatThreads(threads, envelopes);
 	concatIndex(threads, envelopes);
+	fflush(stdout);
 	uidWrite("UIDNEXT", uidNext);
 
 	for (size_t i = 0; i < threads.len; ++i) {