make the junk header customizable like so:

action "local" maildir junk "X-Spam-Flag: YES"


Index: mail.maildir.8
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/mail.maildir.8,v
retrieving revision 1.5
diff -u -p -u -r1.5 mail.maildir.8
--- mail.maildir.8    30 May 2018 12:37:57 -0000    1.5
+++ mail.maildir.8    24 Nov 2018 16:58:03 -0000
@@ -22,7 +22,7 @@
 .Nd store mail in a maildir
 .Sh SYNOPSIS
 .Nm mail.maildir
-.Op Fl j
+.Op Fl j header
 .Op Ar pathname
 .Sh DESCRIPTION
 .Nm
@@ -36,7 +36,9 @@ located in the user's home directory.
 The options are as follows:
 .Bl -tag -width Ds
 .It Fl j
-Scan message for X-Spam and move to Junk folder if result is positive.
+Scan message for
+.Ar header
+and move to Junk folder if result is positive.
 .El
 .Sh EXIT STATUS
 .Ex -std mail.maildir
Index: mail.maildir.c
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/mail.maildir.c,v
retrieving revision 1.7
diff -u -p -u -r1.7 mail.maildir.c
--- mail.maildir.c    24 Oct 2018 19:26:23 -0000    1.7
+++ mail.maildir.c    24 Nov 2018 16:58:03 -0000
@@ -37,23 +37,25 @@

 static int    maildir_subdir(const char *, char *, size_t);
 static void    maildir_mkdirs(const char *);
-static void    maildir_engine(const char *, int);
+static void    maildir_engine(const char *, int, const char *);
 static int    mkdirs_component(const char *, mode_t);
 static int    mkdirs(const char *, mode_t);

 int
 main(int argc, char *argv[])
 {
-    int    ch;
-    int    junk = 0;
+    int     ch;
+    int     junk = 0;
+    char    *header = NULL;

     if (! geteuid())
         errx(1, "mail.maildir: may not be executed as root");

-    while ((ch = getopt(argc, argv, "j")) != -1) {
+    while ((ch = getopt(argc, argv, "j:")) != -1) {
         switch (ch) {
         case 'j':
             junk = 1;
+            header = optarg;
             break;
         default:
             break;
@@ -65,7 +67,7 @@ main(int argc, char *argv[])
     if (argc > 1)
         errx(1, "mail.maildir: only one maildir is allowed");

-    maildir_engine(argv[0], junk);
+    maildir_engine(argv[0], junk, header);

     return (0);
 }
@@ -107,7 +109,7 @@ maildir_mkdirs(const char *dirname)
 }

 static void
-maildir_engine(const char *dirname, int junk)
+maildir_engine(const char *dirname, int junk, const char *header)
 {
     char    rootpath[PATH_MAX];
     char    junkpath[PATH_MAX];
@@ -182,7 +184,7 @@ maildir_engine(const char *dirname, int
         line[strcspn(line, "\n")] = '\0';
         if (line[0] == '\0')
             in_hdr = 0;
-        if (junk && in_hdr && strcmp(line, "X-Spam: yes") == 0)
+        if (junk && in_hdr && strcmp(line, header) == 0)
             is_junk = 1;
         fprintf(fp, "%s\n", line);
     }
Index: smtpd.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/smtpd.conf.5,v
retrieving revision 1.206
diff -u -p -u -r1.206 smtpd.conf.5
--- smtpd.conf.5    8 Oct 2018 06:10:17 -0000    1.206
+++ smtpd.conf.5    24 Nov 2018 16:58:03 -0000
@@ -128,7 +128,7 @@ Optionally,
 might be specified to use the
 recipient email address (after expansion) instead of the
 local user in the LMTP session as RCPT TO.
-.It Cm maildir Op Ar pathname Op Cm junk
+.It Cm maildir Op Ar pathname Op Cm junk header
 Deliver the message to the maildir in
 .Ar pathname
 if specified, or by default to
@@ -142,7 +142,8 @@ may contain format specifiers that are e
 If the
 .Cm junk
 argument is provided, the message will be moved to the Junk
-folder if it contains a positive X-Spam header.
+folder if it contains a positive match for the provided
+.Ar header .
 .It Cm mbox
 Deliver the message to the user's mbox with
 .Xr mail.local 8 .
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/parse.y,v
retrieving revision 1.230
diff -u -p -u -r1.230 parse.y
--- parse.y    8 Nov 2018 13:24:22 -0000    1.230
+++ parse.y    24 Nov 2018 16:58:04 -0000
@@ -662,8 +662,8 @@ MBOX {
 | MAILDIR {
     asprintf(&dispatcher->u.local.command, "/usr/libexec/mail.maildir");
 } dispatcher_local_options
-| MAILDIR JUNK {
-    asprintf(&dispatcher->u.local.command, "/usr/libexec/mail.maildir -j");
+| MAILDIR JUNK STRING {
+    asprintf(&dispatcher->u.local.command, "/usr/libexec/mail.maildir -j \"%s\"", $3);
 } dispatcher_local_options
 | MAILDIR STRING {
     if (strncmp($2, "~/", 2) == 0)
@@ -673,13 +673,13 @@ MBOX {
         asprintf(&dispatcher->u.local.command,
             "/usr/libexec/mail.maildir \"%s\"", $2);
 } dispatcher_local_options
-| MAILDIR STRING JUNK {
+| MAILDIR STRING JUNK STRING{
     if (strncmp($2, "~/", 2) == 0)
         asprintf(&dispatcher->u.local.command,
-            "/usr/libexec/mail.maildir -j \"%%{user.directory}/%s\"", $2+2); +            "/usr/libexec/mail.maildir -j \"%s\" \"%%{user.directory}/%s\"", $4, $2+2);
     else
         asprintf(&dispatcher->u.local.command,
-            "/usr/libexec/mail.maildir -j \"%s\"", $2);
+            "/usr/libexec/mail.maildir -j \"%s\" \"%s\"", $4, $2);
 } dispatcher_local_options
 | LMTP STRING {
     asprintf(&dispatcher->u.local.command,


--
You received this mail because you are subscribed to [email protected]
To unsubscribe, send a mail to: [email protected]

Reply via email to