Skip to content

Commit

Permalink
mdeliver: add refiling capability
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen committed Apr 17, 2018
1 parent 5f25033 commit 5d43ad2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
5 changes: 3 additions & 2 deletions GNUmakefile
Expand Up @@ -27,8 +27,8 @@ all: $(ALL) museragent
$(ALL) : % : %.o
maddr magrep mdeliver mexport mflag mflow mgenmid mhdr mpick mscan msed mshow \
msort mthread : blaze822.o mymemmem.o mytimegm.o
maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort \
mthread : seq.o slurp.o
maddr magrep mdeliver mexport mflag mgenmid mhdr mlist mpick mscan msed mseq \
mshow msort mthread : seq.o slurp.o
maddr magrep mflow mhdr mpick mscan mshow : rfc2047.o
magrep mflow mhdr mshow : rfc2045.o
mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o
Expand Down Expand Up @@ -64,6 +64,7 @@ install: FRC all
ln -sf mcom $(DESTDIR)$(BINDIR)/mbnc
ln -sf mcom $(DESTDIR)$(BINDIR)/mfwd
ln -sf mcom $(DESTDIR)$(BINDIR)/mrep
ln -sf mdeliver $(DESTDIR)$(BINDIR)/mrefile
install -m0644 man/*.1 $(DESTDIR)$(MANDIR)/man1
install -m0644 man/*.5 $(DESTDIR)$(MANDIR)/man5
install -m0644 man/*.7 $(DESTDIR)$(MANDIR)/man7
Expand Down
61 changes: 61 additions & 0 deletions mdeliver.c
Expand Up @@ -23,6 +23,7 @@ design rationale:
*/

static int cflag;
static int kflag;
static int Mflag;
static int vflag;
static char *Xflag;
Expand Down Expand Up @@ -182,9 +183,69 @@ deliver(FILE *infile)
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) {
Expand Down

0 comments on commit 5d43ad2

Please sign in to comment.