From 5d43ad24048698ba89858648389e7e8479801746 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Tue, 17 Apr 2018 15:15:31 +0200 Subject: mdeliver: add refiling capability --- mdeliver.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'mdeliver.c') 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) { -- cgit 1.4.1