about summary refs log tree commit diff
path: root/mdeliver.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2018-04-17 15:15:31 +0200
committerLeah Neukirchen <leah@vuxu.org>2018-04-17 15:15:31 +0200
commit5d43ad24048698ba89858648389e7e8479801746 (patch)
tree49395b69809b567e2ba51b3074809a746a4fb661 /mdeliver.c
parent5f250330cb0269191a25ba76b52ac50d5dcf8cc4 (diff)
downloadmblaze-5d43ad24048698ba89858648389e7e8479801746.tar.gz
mblaze-5d43ad24048698ba89858648389e7e8479801746.tar.xz
mblaze-5d43ad24048698ba89858648389e7e8479801746.zip
mdeliver: add refiling capability
Diffstat (limited to 'mdeliver.c')
-rw-r--r--mdeliver.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/mdeliver.c b/mdeliver.c
index 1a32af4..1714760 100644
--- a/mdeliver.c
+++ b/mdeliver.c
@@ -23,6 +23,7 @@ design rationale:
 */
 
 static int cflag;
+static int kflag;
 static int Mflag;
 static int vflag;
 static char *Xflag;
@@ -182,9 +183,69 @@ tryagain:
 	return 0;
 }
 
+void
+refile(char *file)
+{
+	while (*file == ' ' || *file == '\t')
+		file++;
+
+	FILE *f = fopen(file, "r");
+	if (!f) {
+		fprintf(stderr, "mrefile: %s: %s\n", file, strerror(errno)); 
+		return;
+	}
+
+	// keep flags
+	char *flags = strstr(file, ":2,");
+	if (flags)
+		Xflag = flags + 3;
+	else
+		Xflag = "";
+
+	if (deliver(f) < 0) {
+		perror("mrefile");
+		return;
+	}
+
+	fclose(f);
+	if (!kflag)
+		unlink(file);
+}
+
 int
 main(int argc, char *argv[])
 {
+	if (strchr(argv[0], 'f')) {
+		// mrefile(1)
+
+		cflag = 1;  // use cur/
+
+		int c;
+		while ((c = getopt(argc, argv, "kv")) != -1)
+			switch (c) {
+			case 'k': kflag = 1; break;
+			case 'v': vflag = 1; break;
+			default:
+usage:
+				fprintf(stderr,
+				    "Usage: mrefile [-kv] [msgs...] maildir\n");
+			exit(1);
+		}
+
+		if (argc == optind)
+			goto usage;
+
+		targetdir = argv[argc - 1];
+		gethost();
+
+		if (argc == optind + 1 && isatty(0))
+			blaze822_loop1(".", refile);
+		else
+			blaze822_loop(argc - 1 - optind, argv + optind, refile);
+
+		return 0;
+	}
+
 	int c;
 	while ((c = getopt(argc, argv, "cMvX:")) != -1)
 		switch (c) {