diff --git a/config/config.c b/config/config.c index 3971d52..594270b 100644 --- a/config/config.c +++ b/config/config.c @@ -298,6 +298,12 @@ char *showmimeproc = nmhbindir (/mhshow); char *showproc = nmhlibdir (/mhl); +/* + * Default command to filter mails + */ + +char *slocalproc = nmhlibdir (/slocal); + /* * This program is called by vmh as the back-end to the window management * protocol diff --git a/h/mh.h b/h/mh.h index 1ecb488..ea7046b 100644 --- a/h/mh.h +++ b/h/mh.h @@ -458,6 +458,7 @@ extern char *rmmproc; extern char *sendproc; extern char *showmimeproc; extern char *showproc; +extern char *slocalproc; extern char *usequence; extern char *version_num; extern char *version_str; diff --git a/man/inc.man b/man/inc.man index 8d0a462..493c389 100644 --- a/man/inc.man +++ b/man/inc.man @@ -34,6 +34,7 @@ inc \- incorporate new mail .RB [ \-nopack ] .RB [ \-proxy .IR command ] +.RB [ \-slocal ] .RB [ \-sasl " | " \-nosasl ] .RB [ \-saslmech .IR mechanism ] @@ -228,6 +229,19 @@ server. The string .IR %h in the command will be substituted by the hostname to connect to. .PP +If passed the +.B \-slocal +switch, +.B inc +will save message to temp file and call +slocal(1) +command on it to automatically put it to proper folder, according to your rules. +This switch is not supported with +.B \-audit +or +.B \-pack +directives. +.PP If .B inc uses POP, then the diff --git a/uip/inc.c b/uip/inc.c index b76f1cd..7c824f1 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -68,6 +68,7 @@ X("nosasl", SASLminc(-6), NOSASLSW) \ X("saslmech", SASLminc(-8), SASLMECHSW) \ X("proxy command", 0, PROXYSW) \ + X("slocal", 0, SLOCSW) \ #define X(sw, minchars, id) id, DEFINE_SWITCH_ENUM(INC); @@ -174,6 +175,7 @@ main (int argc, char **argv) int noisy = 1, width = 0; int hghnum = 0, msgnum = 0; int sasl = 0; + int slocal = 0; int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */ char *cp, *maildir = NULL, *folder = NULL; char *format = NULL, *form = NULL; @@ -345,6 +347,10 @@ main (int argc, char **argv) if (!(proxy = *argp++) || *proxy == '-') adios (NULL, "missing argument to %s", argp[-2]); continue; + + case SLOCSW: + slocal = 1; + continue; } } if (*cp == '+' || *cp == '@') { @@ -377,6 +383,16 @@ main (int argc, char **argv) inc_type = INC_FILE; /* + * Do not allow to start with functionality we won't be able to support + */ + if (slocal && audfile) + adios (NULL, "you can't use -slocal and audit at the same time"); + if (slocal && packfile) + adios (NULL, "you can't use -slocal and -packfile at the same time"); + if (slocal && inc_type != INC_POP) + adios (NULL, "you can use -slocal only with POP servers"); + + /* * Are we getting the mail from * a POP server? */ @@ -556,7 +572,10 @@ go_to_it: nfs = new_fs (form, format, FORMAT); if (noisy) { - printf ("Incorporating new mail into %s...\n\n", folder); + if (slocal) + printf ("Incorporating new mail with slocal(1) filtering...\n"); + else + printf ("Incorporating new mail into %s...\n\n", folder); fflush (stdout); } @@ -604,7 +623,12 @@ go_to_it: adios (packfile, "write error on"); fseek (pf, start, SEEK_SET); } else { - cp = getcpy (m_name (msgnum)); + if (slocal) { + if ((cp = m_mktemps(invo_name, "filt", NULL, NULL)) == NULL) + adios (NULL, "unable to create temp file"); + } else + cp = getcpy (m_name (msgnum)); + if ((pf = fopen (cp, "w+")) == NULL) adios (cp, "unable to write"); chmod (cp, m_gmprot ()); @@ -617,6 +641,28 @@ go_to_it: adios (cp, "write error on"); fseek (pf, 0L, SEEK_SET); } + if (slocal) { + int pid; + int argnum; + char *sloc, **arglist; + + switch (pid = fork()) { + case NOTOK: + adios ("fork", "unable to"); + case OK: + arglist = argsplit (slocalproc, &sloc, &argnum); + arglist[argnum++] = "-file"; + arglist[argnum++] = cp; + arglist[argnum++] = "-verbose"; + arglist[argnum++] = NULL; + execvp(sloc, arglist); + exit(1); + default: + fclose(pf); + free(cp); + continue; + } + } switch (incerr = scan (pf, msgnum, 0, nfs, width, packfile ? 0 : msgnum == mp->hghmsg + 1 && chgflag, 1, NULL, stop - start, noisy)) { @@ -674,6 +720,8 @@ go_to_it: mbx_close (packfile, pd); pd = NOTOK; } + if (slocal) + done (0); } /*