--- old/usr/src/Makefile.lint	Fri Sep 26 09:49:18 2014
+++ new/usr/src/Makefile.lint	Fri Sep 26 09:49:18 2014
@@ -195,6 +195,7 @@
 	cmd/luxadm \
 	cmd/lvm \
 	cmd/machid \
+	cmd/mailwrapper \
 	cmd/makekey \
 	cmd/mdb \
 	cmd/mesg \
--- old/usr/src/cmd/Makefile	Fri Sep 26 09:49:19 2014
+++ new/usr/src/cmd/Makefile	Fri Sep 26 09:49:19 2014
@@ -250,6 +250,7 @@
 	mach		\
 	machid		\
 	mail		\
+	mailwrapper	\
 	mailx		\
 	makekey		\
 	man		\
--- old/usr/src/cmd/fm/notify/smtp-notify/common/smtp-notify.xml	Fri Sep 26 09:49:19 2014
+++ new/usr/src/cmd/fm/notify/smtp-notify/common/smtp-notify.xml	Fri Sep 26 09:49:19 2014
@@ -60,7 +60,6 @@
 	    type='service'>
 		<service_fmri value='svc:/milestone/multi-user:default' />
 		<service_fmri value='svc:/system/fmd:default' />
-		<service_fmri value='svc:/network/sendmail-client:default' />
 	</dependency>
 
 	<exec_method
--- /dev/null	Fri Sep 26 09:49:20 2014
+++ new/usr/src/cmd/mailwrapper/Makefile	Fri Sep 26 09:49:20 2014
@@ -0,0 +1,100 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2014 Alexander Pyhalov
+#
+
+
+LIBPROG=	mailwrapper 
+
+PROG= 	       $(LIBPROG)
+
+include ../Makefile.cmd
+
+MWOBJS=		fgetln.o fparseln.o mailwrapper.o
+
+CLOBBERFILES=	$(PROG)
+CLEANFILES=	$(MWOBJS)
+
+SRCS=	 	$(MWOBJS:%.o=%.c)
+
+CPROG=		mailwrapper
+CPROGSRC= 	$(CPROG:%=_%.c)
+
+CFS=		mailer.conf
+
+ROOTETCFILES=$(CFS:%=$(ROOTETC)/%)
+
+$(ROOTETCFILES) :=	FILEMODE = 0644
+
+# installed modules
+ROOTLIBPROG=	$(LIBPROG:%=$(ROOTLIB)/%)
+
+ROOTSYMLINKS=	$(ROOTBIN)/mailq \
+		$(ROOTLIB)/sendmail \
+		$(ROOTUSRSBIN)/newaliases \
+		$(ROOTUSRSBIN)/sendmail
+
+CPPFLAGS =	-I. $(CPPFLAGS.master)
+
+LINTFLAGS	+= -erroff=E_FUNC_RET_ALWAYS_IGNOR2
+
+# conditional assignments
+#
+all:=		TARGET= all
+install:=	TARGET= install
+clean:=		TARGET= clean
+clobber:=	TARGET= clobber
+lint:=		TARGET= lint
+
+# install rules
+$(ROOTINC)/% : %
+	$(INS.file)
+
+.KEEP_STATE:
+
+.PARALLEL: $(MWOBJS) $(OBJS)
+
+all:		$(PROG) 
+
+mailwrapper:	$(MWOBJS)
+	$(LINK.c) -o $@ $(MWOBJS) $(LDLIBS)
+	$(POST_PROCESS)
+
+install: all .WAIT $(ROOTLIBPROG) $(ROOTSYMLINKS) $(ROOTETCFILES)
+
+# ROOTSYMLINKS
+#
+$(ROOTBIN)/mailq: 
+	$(RM) $@; $(SYMLINK) ../lib/mailwrapper $@
+
+$(ROOTLIB)/sendmail:
+	$(RM) $@; $(SYMLINK) mailwrapper $@
+
+$(ROOTUSRSBIN)/newaliases:
+	$(RM) $@; $(SYMLINK) ../lib/mailwrapper $@
+
+$(ROOTUSRSBIN)/sendmail:
+	$(RM) $@; $(SYMLINK) ../lib/mailwrapper $@
+
+$(ROOTETCMAIL)/%:  %
+	$(INS.file)
+
+lint: 
+	$(LINT.c) $(SRCS)
+
+clean:
+	$(RM) $(OBJS) $(MWOBJS) mailwrapper
+
+clobber: clean
+	$(RM) $(ROOTSYMLINKS) $(ROOTLIBPROG) $(ROOTETCFILES)
--- /dev/null	Fri Sep 26 09:49:20 2014
+++ new/usr/src/cmd/mailwrapper/THIRDPARTYLICENSE	Fri Sep 26 09:49:20 2014
@@ -0,0 +1,93 @@
+fgetln.c is provided under the following license
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+fparseln.c is provided under the following license
+/*
+ * Copyright (c) 1997 Christos Zoulas.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+mailwrapper.c is provided under the following license
+/*
+ * Copyright (c) 1998
+ *      Perry E. Metzger.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgment:
+ *      This product includes software developed for the NetBSD Project
+ *      by Perry E. Metzger.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
--- /dev/null	Fri Sep 26 09:49:20 2014
+++ new/usr/src/cmd/mailwrapper/THIRDPARTYLICENSE.descrip	Fri Sep 26 09:49:20 2014
@@ -0,0 +1,1 @@
+mailwrapper and BSD compatibilty functions
--- /dev/null	Fri Sep 26 09:49:20 2014
+++ new/usr/src/cmd/mailwrapper/compat.h	Fri Sep 26 09:49:20 2014
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1996  Peter Wemm <peter@FreeBSD.org>.
+ * All rights reserved.
+ * Copyright (c) 2002 Networks Associates Technology, Inc.
+ * All rights reserved.
+ *
+ * Portions of this software were developed for the FreeBSD Project by
+ * ThinkSec AS and NAI Labs, the Security Research Division of Network
+ * Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
+ * ("CBOSS"), as part of the DARPA CHATS research program.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, is permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* This file contains extracts from FreeBSD libc and libutil headers */
+#include <stdio.h>
+
+#define FPARSELN_UNESCESC       0x01
+#define FPARSELN_UNESCCONT      0x02
+#define FPARSELN_UNESCCOMM      0x04
+#define FPARSELN_UNESCREST      0x08
+#define FPARSELN_UNESCALL       0x0f
+
+char* fparseln(FILE *, size_t *, size_t *, const char[3], int);
+char* fgetln(FILE *, size_t *);
--- /dev/null	Fri Sep 26 09:49:21 2014
+++ new/usr/src/cmd/mailwrapper/fgetln.c	Fri Sep 26 09:49:21 2014
@@ -0,0 +1,84 @@
+/* $Id$ */
+/*	$NetBSD: fgetln.c,v 1.3 2007/08/07 02:06:58 lukem Exp $	*/
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+fgetln(FILE *fp, size_t *len)
+{
+	static char *buf = NULL;
+	static size_t bufsiz = 0;
+	char *ptr;
+
+
+	if (buf == NULL) {
+		bufsiz = BUFSIZ;
+		if ((buf = malloc(bufsiz)) == NULL)
+			return NULL;
+	}
+
+	if (fgets(buf, bufsiz, fp) == NULL)
+		return NULL;
+
+	*len = 0;
+	while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
+		size_t nbufsiz = bufsiz + BUFSIZ;
+		char *nbuf = realloc(buf, nbufsiz);
+
+		if (nbuf == NULL) {
+			int oerrno = errno;
+			free(buf);
+			errno = oerrno;
+			buf = NULL;
+			return NULL;
+		} else
+			buf = nbuf;
+
+		*len = bufsiz;
+		if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL)
+			return buf;
+
+		bufsiz = nbufsiz;
+	}
+
+	*len = (ptr - buf) + 1;
+	return buf;
+}
+
--- /dev/null	Fri Sep 26 09:49:21 2014
+++ new/usr/src/cmd/mailwrapper/fparseln.c	Fri Sep 26 09:49:21 2014
@@ -0,0 +1,207 @@
+/*	$NetBSD: fparseln.c,v 1.9 1999/09/20 04:48:06 lukem Exp $	*/
+
+/*
+ * Copyright (c) 1997 Christos Zoulas.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <compat.h>
+
+static int isescaped(const char *, const char *, int);
+
+/* isescaped():
+ *	Return true if the character in *p that belongs to a string
+ *	that starts in *sp, is escaped by the escape character esc.
+ */
+static int
+isescaped(const char *sp, const char *p, int esc)
+{
+	const char     *cp;
+	size_t		ne;
+
+	/* No escape character */
+	if (esc == '\0')
+		return 1;
+
+	/* Count the number of escape characters that precede ours */
+	for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
+		continue;
+
+	/* Return true if odd number of escape characters */
+	return (ne & 1) != 0;
+}
+
+
+/* fparseln():
+ *	Read a line from a file parsing continuations ending in \
+ *	and eliminating trailing newlines, or comments starting with
+ *	the comment char.
+ */
+char *
+fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
+{
+	static const char dstr[3] = { '\\', '\\', '#' };
+
+	size_t	s, len;
+	char   *buf;
+	char   *ptr, *cp;
+	int	cnt;
+	char	esc, con, nl, com;
+
+	len = 0;
+	buf = NULL;
+	cnt = 1;
+
+	if (str == NULL)
+		str = dstr;
+
+	esc = str[0];
+	con = str[1];
+	com = str[2];
+	/*
+	 * XXX: it would be cool to be able to specify the newline character,
+	 * but unfortunately, fgetln does not let us
+	 */
+	nl  = '\n';
+
+	while (cnt) {
+		cnt = 0;
+
+		if (lineno)
+			(*lineno)++;
+
+		if ((ptr = fgetln(fp, &s)) == NULL)
+			break;
+
+		if (s && com) {		/* Check and eliminate comments */
+			for (cp = ptr; cp < ptr + s; cp++)
+				if (*cp == com && !isescaped(ptr, cp, esc)) {
+					s = cp - ptr;
+					cnt = s == 0 && buf == NULL;
+					break;
+				}
+		}
+
+		if (s && nl) { 		/* Check and eliminate newlines */
+			cp = &ptr[s - 1];
+
+			if (*cp == nl)
+				s--;	/* forget newline */
+		}
+
+		if (s && con) {		/* Check and eliminate continuations */
+			cp = &ptr[s - 1];
+
+			if (*cp == con && !isescaped(ptr, cp, esc)) {
+				s--;	/* forget escape */
+				cnt = 1;
+			}
+		}
+
+		if (s == 0 && buf != NULL)
+			continue;
+
+		if ((cp = realloc(buf, len + s + 1)) == NULL) {
+			free(buf);
+			return NULL;
+		}
+		buf = cp;
+
+		(void) memcpy(buf + len, ptr, s);
+		len += s;
+		buf[len] = '\0';
+	}
+
+	if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
+	    strchr(buf, esc) != NULL) {
+		ptr = cp = buf;
+		while (cp[0] != '\0') {
+			int skipesc;
+
+			while (cp[0] != '\0' && cp[0] != esc)
+				*ptr++ = *cp++;
+			if (cp[0] == '\0' || cp[1] == '\0')
+				break;
+
+			skipesc = 0;
+			if (cp[1] == com)
+				skipesc += (flags & FPARSELN_UNESCCOMM);
+			if (cp[1] == con)
+				skipesc += (flags & FPARSELN_UNESCCONT);
+			if (cp[1] == esc)
+				skipesc += (flags & FPARSELN_UNESCESC);
+			if (cp[1] != com && cp[1] != con && cp[1] != esc)
+				skipesc = (flags & FPARSELN_UNESCREST);
+
+			if (skipesc)
+				cp++;
+			else
+				*ptr++ = *cp++;
+			*ptr++ = *cp++;
+		}
+		*ptr = '\0';
+		len = strlen(buf);
+	}
+
+	if (size)
+		*size = len;
+	return buf;
+}
+
+#ifdef TEST
+
+int
+main(int argc, char *argv[])
+{
+	char   *ptr;
+	size_t	size, line;
+
+	line = 0;
+	while ((ptr = fparseln(stdin, &size, &line, NULL,
+	    FPARSELN_UNESCALL)) != NULL)
+		printf("line %d (%d) |%s|\n", line, size, ptr);
+	return 0;
+}
+
+/*
+
+# This is a test
+line 1
+line 2 \
+line 3 # Comment
+line 4 \# Not comment \\\\
+
+# And a comment \
+line 5 \\\
+line 6
+
+*/
+
+#endif /* TEST */
--- /dev/null	Fri Sep 26 09:49:21 2014
+++ new/usr/src/cmd/mailwrapper/mailer.conf	Fri Sep 26 09:49:21 2014
@@ -0,0 +1,9 @@
+#
+# This file configures mailwrapper(1M). 
+# For details see mailer.conf(4).
+# The following configuration is correct for sendmail(1M).
+#
+
+sendmail	/usr/lib/smtp/sendmail/sendmail
+newaliases	/usr/lib/smtp/sendmail/sendmail
+mailq		/usr/lib/smtp/sendmail/mailq
--- /dev/null	Fri Sep 26 09:49:21 2014
+++ new/usr/src/cmd/mailwrapper/mailwrapper.c	Fri Sep 26 09:49:21 2014
@@ -0,0 +1,167 @@
+/*	$OpenBSD: mailwrapper.c,v 1.18 2007/11/06 14:39:19 otto Exp $	*/
+/*	$NetBSD: mailwrapper.c,v 1.9 2003/03/09 08:10:43 mjl Exp $	*/
+
+/*
+ * Copyright (c) 1998
+ * 	Perry E. Metzger.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgment:
+ *	This product includes software developed for the NetBSD Project
+ *	by Perry E. Metzger.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <compat.h>
+#include <err.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <syslog.h>
+#include <limits.h>
+
+#include "pathnames.h"
+
+struct arglist {
+	size_t argc, maxc;
+	char **argv;
+};
+
+int main(int, char *[], char *[]);
+
+static void initarg(struct arglist *);
+static void addarg(struct arglist *, const char *);
+
+static void
+initarg(struct arglist *al)
+{
+	al->argc = 0;
+	al->maxc = 10;
+	if ((al->argv = calloc(al->maxc, sizeof(char *))) == NULL)
+		err(EX_TEMPFAIL, "calloc");
+}
+
+static void
+addarg(struct arglist *al, const char *arg)
+{
+
+	if (al->argc == al->maxc) {
+		al->maxc <<= 1;
+		al->argv = realloc(al->argv, al->maxc * sizeof(char *));
+		if (al->argv == NULL)
+			err(EX_TEMPFAIL, "realloc");
+	}
+	if (arg == NULL)
+		al->argv[al->argc++] = NULL;
+	else if ((al->argv[al->argc++] = strdup(arg)) == NULL)
+		err(EX_TEMPFAIL, "strdup");
+}
+
+int
+main(int argc, char *argv[], char *envp[])
+{
+	FILE *config;
+	char *line, *cp, *from, *to, *ap;
+	char progname[PATH_MAX+1];
+	const char *name;
+	size_t len, lineno = 0;
+	int i;
+	struct arglist al;
+
+	/* change __progname to mailwrapper so we get sensible error messages */
+	name = getprogname();
+	if(name) {
+		strncpy(progname,name,sizeof(progname));
+	} else {
+		err(EX_OSERR, "cannot get program name");
+	}
+	setprogname("mailwrapper");
+
+	initarg(&al);
+	addarg(&al, argv[0]);
+
+	if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
+		addarg(&al, NULL);
+		openlog(getprogname(), LOG_PID, LOG_MAIL);
+		syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
+		    _PATH_MAILERCONF, _PATH_DEFAULTMTA);
+		closelog();
+		execve(_PATH_DEFAULTMTA, al.argv, envp);
+		err(EX_OSERR, "cannot exec %s", _PATH_DEFAULTMTA);
+		/*NOTREACHED*/
+	}
+
+	for (;;) {
+		if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
+			if (feof(config))
+				errx(EX_CONFIG, "no mapping for %s in %s", progname, _PATH_MAILERCONF);
+			err(EX_CONFIG, "cannot parse line %lu", (u_long)lineno);
+		}
+
+#define	WS	" \t\n"
+		cp = line;
+
+		cp += strspn(cp, WS);
+		if (cp[0] == '\0') {
+			/* empty line */
+			free(line);
+			continue;
+		}
+
+		if ((from = strsep(&cp, WS)) == NULL || cp == NULL)
+			goto parse_error;
+
+		cp += strspn(cp, WS);
+
+		if ((to = strsep(&cp, WS)) == NULL)
+			goto parse_error;
+
+		if (strcmp(from, progname) == 0) {
+			for (ap = strsep(&cp, WS); ap != NULL;
+			     ap = strsep(&cp, WS)) {
+				if (*ap)
+				    addarg(&al, ap);
+			}
+			break;
+		}
+
+		free(line);
+	}
+
+	(void)fclose(config);
+
+	for (i = 1; i < argc; i++)
+		addarg(&al, argv[i]);
+
+	addarg(&al, NULL);
+	execve(to, al.argv, envp);
+	err(EX_OSERR, "cannot exec %s", to);
+	/*NOTREACHED*/
+parse_error:
+	errx(EX_CONFIG, "parse error in %s at line %lu",
+	    _PATH_MAILERCONF, (u_long)lineno);
+	/*NOTREACHED*/
+	return 0;
+}
--- /dev/null	Fri Sep 26 09:49:22 2014
+++ new/usr/src/cmd/mailwrapper/pathnames.h	Fri Sep 26 09:49:22 2014
@@ -0,0 +1,35 @@
+/* $FreeBSD$ */
+
+/*
+ * Copyright (c) 1998
+ * 	Perry E. Metzger.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgment:
+ *	This product includes software developed for the NetBSD Project
+ *	by Perry E. Metzger.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define _PATH_MAILERCONF	"/etc/mailer.conf"
+#define _PATH_DEFAULTMTA	"/usr/lib/smtp/sendmail/sendmail"
--- old/usr/src/cmd/mailx/names.c	Fri Sep 26 09:49:22 2014
+++ new/usr/src/cmd/mailx/names.c	Fri Sep 26 09:49:22 2014
@@ -38,8 +38,6 @@
  * contributors.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * mailx -- a modified version of a University of California at Berkeley
  *	mail program
@@ -607,7 +605,6 @@
 
 	if (rflag != NOSTR)
 		extra += 2;
-#ifdef SENDMAIL
 	extra++;
 	metoo = value("metoo") != NOSTR;
 	if (metoo)
@@ -617,15 +614,13 @@
 		extra++;
 	if (hflag)
 		extra += 2;
-#endif /* SENDMAIL */
 	top = (char **) salloc((t + extra) * sizeof (char *));
 	ap = top;
-	*ap++ = "mail";
+	*ap++ = "sendmail";
 	if (rflag != NOSTR) {
 		*ap++ = "-r";
 		*ap++ = rflag;
 	}
-#ifdef SENDMAIL
 	*ap++ = "-i";
 	if (metoo)
 		*ap++ = "-m";
@@ -636,7 +631,6 @@
 		snprintf(hbuf, sizeof (hbuf), "%d", hflag);
 		*ap++ = savestr(hbuf);
 	}
-#endif /* SENDMAIL */
 	while (n != NIL) {
 		if (n->n_type & GDEL) {
 			n = n->n_flink;
--- old/usr/src/cmd/sendmail/Makefile.cmd	Fri Sep 26 09:49:22 2014
+++ new/usr/src/cmd/sendmail/Makefile.cmd	Fri Sep 26 09:49:22 2014
@@ -33,3 +33,11 @@
 CERRWARN +=	-_gcc=-Wno-empty-body
 CERRWARN +=	-_gcc=-Wno-unused-variable
 DBMDEF=		-DNDBM -DNEWDB -DNIS -DUSERDB -DMAP_REGEX -DLDAPMAP
+
+ROOTLIBSMTPSM = $(ROOTLIB)/smtp/sendmail
+
+$(ROOTLIBSMTPSM):
+	$(INS.dir)
+
+$(ROOTLIBSMTPSM)/%: $(ROOTLIBSMTPSM) %
+	$(INS.file)
--- old/usr/src/cmd/sendmail/aux/Makefile	Fri Sep 26 09:49:23 2014
+++ new/usr/src/cmd/sendmail/aux/Makefile	Fri Sep 26 09:49:23 2014
@@ -27,12 +27,14 @@
 include		../../Makefile.cmd
 include		../Makefile.cmd
 
-PROG= 		mailstats mconnect vacation mailcompat praliases mailq
+PROG= 		mailstats mconnect vacation mailcompat praliases
 
 LIBPROG=	mail.local smrsh
 
 USRSBINPROG=	etrn makemap editmap
 
+LIBSMTPSMPROG= mailq
+
 # $(PROG) by default
 CLOBBERFILES=	$(LIBPROG) $(USRSBINPROG)
 
@@ -51,7 +53,7 @@
 praliases :=	LDLIBS += -lldap
 smrsh :=	LDLIBS += -lldap
 vacation :=	LDLIBS += -lldap
-$(ROOTBIN)/mailq :=	FILEMODE = 4555
+$(ROOTLIBSMTPSM)/mailq :=	FILEMODE = 4555
 
 INCPATH=	-I../src -I../db -I../include
 
@@ -67,7 +69,7 @@
 
 .KEEP_STATE:
 
-all:		$(PROG) $(LIBPROG) $(USRSBINPROG)
+all:		$(PROG) $(LIBSMTPSMPROG) $(LIBPROG) $(USRSBINPROG)
 
 convtime.o:	../src/convtime.c
 	$(COMPILE.c) ../src/convtime.c
@@ -111,7 +113,8 @@
 	$(POST_PROCESS)
 
 install: all $(ROOTPROG) $(ROOTLIB)/mail.local $(ROOTLIB)/smrsh \
-	$(ROOTUSRSBIN)/makemap $(ROOTUSRSBIN)/etrn $(ROOTUSRSBIN)/editmap
+	$(ROOTLIBSMTPSM)/mailq $(ROOTUSRSBIN)/makemap \
+	$(ROOTUSRSBIN)/etrn $(ROOTUSRSBIN)/editmap
 
 clean:
 	$(RM) $(OBJS) *.o
--- old/usr/src/cmd/sendmail/aux/mailq.c	Fri Sep 26 09:49:23 2014
+++ new/usr/src/cmd/sendmail/aux/mailq.c	Fri Sep 26 09:49:23 2014
@@ -34,7 +34,7 @@
 #include <errno.h>
 #include <auth_list.h>
 
-#define	_PATH_SENDMAIL_BIN	"/usr/lib/sendmail"
+#define	_PATH_SENDMAIL_BIN	"/usr/lib/smtp/sendmail/sendmail"
 
 int
 main(int argc, char *argv[], char *envp[])
--- old/usr/src/cmd/sendmail/src/Makefile	Fri Sep 26 09:49:24 2014
+++ new/usr/src/cmd/sendmail/src/Makefile	Fri Sep 26 09:49:24 2014
@@ -59,7 +59,7 @@
 
 FILEMODE= 	2555
 
-ROOTSYMLINKS=	$(ROOTUSRSBIN)/newaliases $(ROOTUSRSBIN)/sendmail
+ROOTSYMLINKS=	$(ROOTLIBSMTPSM)/newaliases
 
 # build rule
 #
@@ -74,10 +74,10 @@
 	$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
 	$(POST_PROCESS)
 
-install:	$(ROOTLIBPROG) $(ROOTSYMLINKS)
+install:	$(ROOTLIBSMTPSM)/sendmail $(ROOTSYMLINKS)
 
 $(ROOTSYMLINKS):
-	$(RM) $@; $(SYMLINK) ../lib/sendmail $@
+	$(RM) $@; $(SYMLINK) sendmail $@
 
 clean:
 	$(RM) $(PROG) $(OBJS)
--- old/usr/src/cmd/svc/shell/sendmail_include.sh	Fri Sep 26 09:49:24 2014
+++ new/usr/src/cmd/svc/shell/sendmail_include.sh	Fri Sep 26 09:49:24 2014
@@ -23,7 +23,7 @@
 # Use is subject to license terms.
 
 DEFAULT_FILE="/etc/default/sendmail"
-SENDMAIL="/usr/lib/sendmail"
+SENDMAIL="/usr/lib/smtp/sendmail/sendmail"
 PATH="/usr/bin:/usr/sbin:/usr/ccs/bin"
 export PATH
 
--- old/usr/src/man/man1m/Makefile	Fri Sep 26 09:49:25 2014
+++ new/usr/src/man/man1m/Makefile	Fri Sep 26 09:49:25 2014
@@ -296,6 +296,7 @@
 		lpusers.1m		\
 		luxadm.1m		\
 		mail.local.1m		\
+		mailwrapper.1m		\
 		makedbm.1m		\
 		makemap.1m		\
 		mdmonitord.1m		\
--- /dev/null	Fri Sep 26 09:49:25 2014
+++ new/usr/src/man/man1m/mailwrapper.1m	Fri Sep 26 09:49:25 2014
@@ -0,0 +1,130 @@
+.\"	$OpenBSD: mailwrapper.8,v 1.10 2009/02/07 16:58:23 martynas Exp $
+.\"	$NetBSD: mailwrapper.8,v 1.11 2002/02/08 01:38:50 ross Exp $
+.\" $FreeBSD: releng/9.1/usr.sbin/mailwrapper/mailwrapper.8 205938 2010-03-30 21:54:25Z delphij $
+.\"
+.\" Copyright (c) 1998
+.\" 	Perry E. Metzger.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgment:
+.\"	This product includes software developed for the NetBSD Project
+.\"	by Perry E. Metzger.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd August 7, 2006
+.Dt MAILWRAPPER 1M
+.Os
+.Sh NAME
+.Nm \fB/usr/lib/mailwrapper\fR
+.Nd invoke appropriate MTA software based on configuration file
+.Sh SYNOPSIS
+Special.
+See below.
+.Sh DESCRIPTION
+At one time, the only Mail Transfer Agent (MTA) software easily available
+was
+.Xr sendmail 1M .
+As a result of this, most Mail User Agents (MUAs) such as
+.Xr mail 1
+had the path and calling conventions expected by
+.Xr sendmail 1M
+compiled in.
+.Pp
+Times have changed, however.
+On a modern
+.Ux
+system, the administrator may wish to use one of several
+available MTAs.
+.Pp
+It would be difficult to modify all MUA software typically available
+on a system, so most of the authors of alternative MTAs have written
+their front end message submission programs so that they use the same
+calling conventions as
+.Xr sendmail 1M
+and may be put into place instead of
+.Xr sendmail 1M
+in
+.Pa /usr/lib/sendmail .
+.Pp
+.Xr sendmail 1M
+also typically has aliases named
+.Xr mailq 1
+and
+.Xr newaliases 1M
+linked to it.
+The program knows to behave differently when its
+.Va argv[0]
+is
+.Dq mailq
+or
+.Dq newaliases
+and behaves appropriately.
+Typically, replacement MTAs provide similar
+functionality, either through a program that also switches behavior
+based on calling name, or through a set of programs that provide
+similar functionality.
+.Pp
+Although having drop-in replacements for
+.Xr sendmail 1M
+helps in installing alternative MTAs, it essentially makes the
+configuration of the system depend on hand installing new programs in
+.Pa /usr .
+This leads to configuration problems for many administrators, since
+they may wish to install a new MTA without altering the system
+provided
+.Pa /usr .
+(This may be, for example, to avoid having upgrade problems when a new
+version of the system is installed over the old.)
+They may also have a shared
+.Pa /usr
+among several
+machines, and may wish to avoid placing implicit configuration
+information in a read-only
+.Pa /usr .
+.Pp
+The
+.Nm
+utility is designed to replace
+.Pa /usr/lib/sendmail
+and to invoke an appropriate MTA instead of
+.Xr sendmail 1M
+based on configuration information placed in
+.Pa /etc/mailer.conf .
+This permits the administrator to configure which MTA is to be invoked on
+the system at run time.
+.Pp
+Other configuration files may need to be altered when replacing
+.Xr sendmail 1M .
+.Sh EXIT STATUS
+.Ex -std
+.Sh DIAGNOSTICS
+The
+.Nm
+will print a diagnostic if its configuration file is missing or malformed,
+or does not contain a mapping for the name under which it was invoked.
+.Sh SEE ALSO
+.Xr mail 1 ,
+.Xr mailq 1 ,
+.Xr newaliases 1M ,
+.Xr mailer.conf 4 ,
+.Xr sendmail 1M
--- old/usr/src/man/man4/Makefile	Fri Sep 26 09:49:26 2014
+++ new/usr/src/man/man4/Makefile	Fri Sep 26 09:49:26 2014
@@ -103,6 +103,7 @@
 		logindevperm.4			\
 		loginlog.4			\
 		magic.4				\
+		mailer.conf.4			\
 		md.tab.4			\
 		mddb.cf.4			\
 		mech.4				\
--- /dev/null	Fri Sep 26 09:49:26 2014
+++ new/usr/src/man/man4/mailer.conf.4	Fri Sep 26 09:49:26 2014
@@ -0,0 +1,107 @@
+.\"	$NetBSD: mailer.conf.5,v 1.2 1999/05/29 18:18:30 christos Exp $
+.\"
+.\" Copyright (c) 1998
+.\" 	Perry E. Metzger.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgment:
+.\"	This product includes software developed for the NetBSD Project
+.\"	by Perry E. Metzger.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD: releng/9.1/share/man/man5/mailer.conf.5 213609 2010-10-08 20:13:12Z markm $
+.\"
+.Dd October 8, 2010
+.Dt MAILER.CONF 4
+.Os
+.Sh NAME
+.Nm mailer.conf
+.Nd configuration file for
+.Xr mailwrapper 1M
+.Sh DESCRIPTION
+The file
+.Pa /etc/mailer.conf
+contains a series of lines of the form
+.Pp
+.Ar name
+.Ar program
+.Op Ar arguments ...
+.Pp
+The first word of each line is the
+.Ar name
+of a program invoking
+.Xr mailwrapper 1M .
+(For example, on a typical system
+.Pa /usr/lib/sendmail
+would be a symbolic link to
+.Xr mailwrapper 1M ,
+as would
+.Xr newaliases 1M
+and
+.Xr mailq 1 .
+Thus,
+.Ar name
+might be
+.Dq Li sendmail
+or
+.Dq Li newaliases
+etc.)
+.Pp
+The second word of each line is the name of the
+.Ar program
+to actually execute when the first name is invoked.
+.Pp
+The further
+.Ar arguments ,
+if any, are passed to the
+.Ar program ,
+followed by the arguments
+.Xr mailwrapper 1M
+was called with.
+.Pp
+The file may also contain comment lines, denoted by a
+.Ql #
+mark in the first column of any line.
+.Sh FILES
+/etc/mail/mailer.conf
+.Sh EXAMPLES
+This example shows how to set up
+.Nm
+to invoke the traditional
+.Xr sendmail 1M
+program:
+.Bd -literal -offset indent
+# Execute the "real" sendmail program located in
+# /usr/lib/smtp/sendmail/sendmail
+sendmail	/usr/lib/smtp/sendmail/sendmail
+mailq		/usr/lib/smtp/sendmail/sendmail
+newaliases	/usr/lib/smtp/sendmail/sendmail
+.Ed
+.Sh SEE ALSO
+.Xr mail 1 ,
+.Xr mailq 1 ,
+.Xr newaliases 1M ,
+.Xr mailwrapper 1M ,
+.Xr sendmail 1M
+.Sh AUTHORS
+.An Perry E. Metzger Aq perry@piermont.com
--- old/usr/src/pkg/manifests/SUNWcs.mf	Fri Sep 26 09:49:26 2014
+++ new/usr/src/pkg/manifests/SUNWcs.mf	Fri Sep 26 09:49:26 2014
@@ -1900,3 +1900,7 @@
 # Depend on zoneinfo data.
 #
 depend fmri=system/data/zoneinfo type=require
+#
+# The mailx binary calls /usr/lib/sendmail provided by mailwrapper
+#
+depend fmri=system/network/mailwrapper type=require
--- old/usr/src/pkg/manifests/developer-build-onbld.mf	Fri Sep 26 09:49:27 2014
+++ new/usr/src/pkg/manifests/developer-build-onbld.mf	Fri Sep 26 09:49:27 2014
@@ -228,7 +228,5 @@
 link path=opt/onbld/man/man1/git-nits.1 target=git-pbchk.1
 # webrev(1) requires ps2pdf
 depend fmri=print/filter/ghostscript type=require
-# hgsetup(1) uses check-hostname(1) and nightly sendmail(1M)
-depend fmri=service/network/smtp/sendmail type=require
 # nightly(1) uses wget
 depend fmri=web/wget type=require
--- old/usr/src/pkg/manifests/service-network-smtp-sendmail.mf	Fri Sep 26 09:49:27 2014
+++ new/usr/src/pkg/manifests/service-network-smtp-sendmail.mf	Fri Sep 26 09:49:27 2014
@@ -56,6 +56,8 @@
 dir path=usr/lib/help/auths
 dir path=usr/lib/help/auths/locale
 dir path=usr/lib/help/auths/locale/C
+dir path=usr/lib/smtp
+dir path=usr/lib/smtp/sendmail
 dir path=usr/sbin
 dir path=usr/share/man
 dir path=usr/share/man/man1
@@ -167,7 +169,6 @@
 file path=lib/svc/method/smtp-sendmail mode=0555
 file path=lib/svc/share/sendmail_include.sh mode=0444
 file path=usr/bin/mailcompat mode=0555
-file path=usr/bin/mailq mode=4555
 file path=usr/bin/mailstats mode=0555
 file path=usr/bin/mconnect mode=0555
 file path=usr/bin/praliases mode=0555
@@ -181,8 +182,9 @@
 file path=usr/lib/llib-lmilter
 file path=usr/lib/llib-lmilter.ln
 file path=usr/lib/mail.local mode=0555
-file path=usr/lib/sendmail group=smmsp mode=2555
 file path=usr/lib/smrsh mode=0555
+file path=usr/lib/smtp/sendmail/mailq mode=4555
+file path=usr/lib/smtp/sendmail/sendmail group=smmsp mode=2555
 file path=usr/sbin/check-hostname group=mail mode=0555
 file path=usr/sbin/check-permissions group=mail mode=0555
 file path=usr/sbin/editmap mode=0555
@@ -212,7 +214,8 @@
 license lic_CDDL license=lic_CDDL
 license usr/src/cmd/sendmail/THIRDPARTYLICENSE \
     license=usr/src/cmd/sendmail/THIRDPARTYLICENSE
-link path=etc/aliases target=./mail/aliases
+link path=etc/aliases mediator=mta mediator-implementation=sendmail \
+    target=./mail/aliases
 link path=etc/mail/cf/cf/main.cf target=sendmail.cf
 link path=etc/mail/cf/cf/main.mc target=sendmail.mc
 link path=etc/mail/cf/cf/subsidiary.cf target=sendmail.cf
@@ -224,10 +227,17 @@
 link path=etc/mail/main.cf target=sendmail.cf
 link path=etc/mail/sendmail.hf target=helpfile
 link path=etc/mail/subsidiary.cf target=sendmail.cf
+link path=usr/bin/mailq mediator=mta mediator-implementation=sendmail \
+    target=../lib/smtp/sendmail/mailq
 link path=usr/lib/libmilter.so target=libmilter.so.1
 link path=usr/lib/mail target=../../etc/mail/cf
-link path=usr/sbin/newaliases target=../lib/sendmail
-link path=usr/sbin/sendmail target=../lib/sendmail
+link path=usr/lib/sendmail mediator=mta mediator-implementation=sendmail \
+    target=../lib/smtp/sendmail/sendmail
+link path=usr/lib/smtp/sendmail/newaliases target=sendmail
+link path=usr/sbin/newaliases mediator=mta mediator-implementation=sendmail \
+    target=../lib/smtp/sendmail/newaliases
+link path=usr/sbin/sendmail mediator=mta mediator-implementation=sendmail \
+    target=../lib/smtp/sendmail/sendmail
 link path=usr/share/man/man4/addresses.4 target=aliases.4
 link path=usr/share/man/man4/forward.4 target=aliases.4
 link path=usr/share/man/man4/sendmail.cf.4 target=sendmail.4
--- /dev/null	Fri Sep 26 09:49:28 2014
+++ new/usr/src/pkg/manifests/system-network-mailwrapper.mf	Fri Sep 26 09:49:28 2014
@@ -0,0 +1,45 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet
+# at http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2014, Alexander Pyhalov
+#
+
+set name=pkg.fmri value=pkg:/system/network/mailwrapper@$(PKGVERS)
+set name=pkg.description \
+    value="utility to invoke appropriate MTA software based on configuration file"
+set name=pkg.summary value=mailwrapper
+set name=info.classification \
+    value="org.opensolaris.category.2008:System/Administration and Configuration"
+set name=variant.arch value=$(ARCH)
+dir path=etc group=sys
+dir path=etc/mail group=mail
+dir path=usr/bin
+dir path=usr/lib
+dir path=usr/sbin
+dir path=usr/share/man
+dir path=usr/share/man/man1m
+dir path=usr/share/man/man4
+file path=etc/mailer.conf group=sys preserve=true
+file path=usr/lib/mailwrapper mode=0555
+file path=usr/share/man/man1m/mailwrapper.1m
+file path=usr/share/man/man4/mailer.conf.4
+license usr/src/cmd/mailwrapper/THIRDPARTYLICENSE \
+    license=usr/src/cmd/mailwrapper/THIRDPARTYLICENSE
+link path=usr/bin/mailq mediator=mta mediator-implementation=mailwrapper \
+    target=../lib/mailwrapper
+link path=usr/lib/sendmail mediator=mta mediator-implementation=mailwrapper \
+    target=mailwrapper
+link path=usr/sbin/newaliases mediator=mta mediator-implementation=mailwrapper \
+    target=../lib/mailwrapper
+link path=usr/sbin/sendmail mediator=mta mediator-implementation=mailwrapper \
+    target=../lib/mailwrapper
+depend fmri=service/network/smtp/sendmail type=require
--- old/usr/src/tools/scripts/hgsetup.sh	Fri Sep 26 09:49:28 2014
+++ new/usr/src/tools/scripts/hgsetup.sh	Fri Sep 26 09:49:28 2014
@@ -122,8 +122,9 @@
 
 if [[ -z $email ]]; then
 	my_id=$(id -un)
-	my_checkhostname=$(check-hostname)
-	my_fqhn=${my_checkhostname##* }
+	my_hostname=$(hostname)
+	possible_fqhns=$(getent hosts $my_hostname | cut -f 2-) 
+	my_fqhn=`for i in $possible_fqhns; do case $i in *.*) echo $i; break;; esac; done` 
 	email="$my_id@$my_fqhn"
 	echo "No e-mail address provided, defaulting to $email"
 fi
