diff options
-rw-r--r-- | usr.sbin/smtpd/mail.maildir.8 | 22 | ||||
-rw-r--r-- | usr.sbin/smtpd/mail.maildir.c | 57 | ||||
-rw-r--r-- | usr.sbin/smtpd/parse.y | 9 |
3 files changed, 34 insertions, 54 deletions
diff --git a/usr.sbin/smtpd/mail.maildir.8 b/usr.sbin/smtpd/mail.maildir.8 index 629fb5ad5e4..10a7ef4304b 100644 --- a/usr.sbin/smtpd/mail.maildir.8 +++ b/usr.sbin/smtpd/mail.maildir.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mail.maildir.8,v 1.2 2018/04/28 10:33:41 gilles Exp $ +.\" $OpenBSD: mail.maildir.8,v 1.3 2018/05/29 19:32:34 gilles Exp $ .\" .\" Copyright (c) 2017 Gilles Chehade <gilles@poolp.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 28 2018 $ +.Dd $Mdocdate: May 29 2018 $ .Dt MAIL.MAILDIR 8 .Os .Sh NAME @@ -22,23 +22,13 @@ .Nd store mail in a maildir .Sh SYNOPSIS .Nm mail.maildir -.Op Fl d Ar delimiter -.Op Fl p Ar pathname -.Op Fl r Ar recipient +.Op Ar pathname .Sh DESCRIPTION .Nm reads the standard input up to an end-of-file and adds it to the -provided mail directory. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl d Ar delimiter -Specify the delimiter to use for sub-addressing. -.It Fl p Ar pathname -Specify the path to user mail directory. -.It Fl r Ar recipient -Specify the recipient email address. -.El +mail directory located in +.Ar pathname +or to the mail directory Maildir located in the user home directory. .Sh EXIT STATUS .Ex -std mail.maildir .Sh SEE ALSO diff --git a/usr.sbin/smtpd/mail.maildir.c b/usr.sbin/smtpd/mail.maildir.c index 96bb8fa3719..966ada41f37 100644 --- a/usr.sbin/smtpd/mail.maildir.c +++ b/usr.sbin/smtpd/mail.maildir.c @@ -28,11 +28,10 @@ #include <string.h> #include <unistd.h> -#define SUBADDRESSING_DELIMITER "+" #define MAILADDR_ESCAPE "!#$%&'*/?^`{|}~" -static int maildir_subdir(const char *, const char *, char *, size_t); -static void maildir_engine(const char *, const char *, const char *); +static int maildir_subdir(const char *, char *, size_t); +static void maildir_engine(const char *); static int mkdirs_component(const char *, mode_t); static int mkdirs(const char *, mode_t); @@ -40,24 +39,12 @@ int main(int argc, char *argv[]) { int ch; - char *pathname = NULL; - char *recipient = NULL; - char *delim = SUBADDRESSING_DELIMITER; if (! geteuid()) errx(1, "mail.maildir: may not be executed as root"); - while ((ch = getopt(argc, argv, "d:p:r:")) != -1) { + while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { - case 'd': - delim = optarg; - break; - case 'p': - pathname = optarg; - break; - case 'r': - recipient = optarg; - break; default: break; } @@ -65,39 +52,33 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (pathname == NULL) - errx(1, "no maildir pathname specified"); + if (argc > 1) + errx(1, "mail.maildir: only one maildir is allowed"); - maildir_engine(pathname, recipient, delim); + maildir_engine(argv[0]); return (0); } static int -maildir_subdir(const char *recipient, const char *delim, char *dest, size_t len) +maildir_subdir(const char *extension, char *dest, size_t len) { - char *tag; char *sanitized; - if ((tag = strchr(recipient, *delim))) { - tag++; - while (*tag == '.') - tag++; - } - if (tag == NULL) - return 1; - - if (strlcpy(dest, tag, len) >= len) + if (strlcpy(dest, extension, len) >= len) return 0; + for (sanitized = dest; *sanitized; sanitized++) if (strchr(MAILADDR_ESCAPE, *sanitized)) *sanitized = ':'; + return 1; } static void -maildir_engine(const char *dirname, const char *recipient, const char *delim) +maildir_engine(const char *dirname) { + char root[PATH_MAX]; char tmp[PATH_MAX]; char new[PATH_MAX]; char subdir[PATH_MAX]; @@ -107,10 +88,20 @@ maildir_engine(const char *dirname, const char *recipient, const char *delim) size_t linesize = 0; ssize_t linelen; struct stat sb; + char *home; + char *extension; + - if (recipient) { + if (dirname == NULL) { + if ((home = getenv("HOME")) == NULL) + err(1, NULL); + (void)snprintf(root, sizeof root, "%s/Maildir", home); + dirname = root; + } + + if ((extension = getenv("EXTENSION")) != NULL) { memset(subdir, 0, sizeof subdir); - if (! maildir_subdir(recipient, delim, subdir, sizeof(subdir))) + if (! maildir_subdir(extension, subdir, sizeof(subdir))) err(1, NULL); if (subdir[0]) { diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index dd46d9b4d3d..5e3670de864 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.202 2018/05/25 14:10:28 gilles Exp $ */ +/* $OpenBSD: parse.y,v 1.203 2018/05/29 19:32:34 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -355,16 +355,15 @@ MBOX { asprintf(&dispatcher->u.local.command, "/usr/libexec/mail.local -f %%{sender} %%{user.username}"); } dispatcher_local_options | MAILDIR { - asprintf(&dispatcher->u.local.command, - "/usr/libexec/mail.maildir -p %%{user.directory}/Maildir -r %%{dest.user}"); + asprintf(&dispatcher->u.local.command, "/usr/libexec/mail.maildir"); } dispatcher_local_options | MAILDIR STRING { if (strncmp($2, "~/", 2) == 0) asprintf(&dispatcher->u.local.command, - "/usr/libexec/mail.maildir -p %%{user.directory}/%s -r %%{dest.user}}", $2+2); + "/usr/libexec/mail.maildir \"%%{user.directory}/%s\"", $2+2); else asprintf(&dispatcher->u.local.command, - "/usr/libexec/mail.maildir -p %s -r %%{dest.user}}", $2); + "/usr/libexec/mail.maildir \"%s\"", $2); } dispatcher_local_options | MDA STRING { asprintf(&dispatcher->u.local.command, |