about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/mail
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/servers/mail')
-rw-r--r--nixpkgs/pkgs/servers/mail/archiveopteryx/default.nix42
-rw-r--r--nixpkgs/pkgs/servers/mail/clamsmtp/default.nix22
-rw-r--r--nixpkgs/pkgs/servers/mail/clamsmtp/header-order.patch25
-rw-r--r--nixpkgs/pkgs/servers/mail/dkimproxy/default.nix36
-rw-r--r--nixpkgs/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch122
-rw-r--r--nixpkgs/pkgs/servers/mail/dovecot/default.nix75
-rw-r--r--nixpkgs/pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix38
-rw-r--r--nixpkgs/pkgs/servers/mail/dspam/default.nix108
-rw-r--r--nixpkgs/pkgs/servers/mail/exim/default.nix96
-rw-r--r--nixpkgs/pkgs/servers/mail/freepops/default.nix29
-rw-r--r--nixpkgs/pkgs/servers/mail/mailhog/default.nix25
-rw-r--r--nixpkgs/pkgs/servers/mail/mailhog/deps.nix191
-rw-r--r--nixpkgs/pkgs/servers/mail/mailman/default.nix33
-rw-r--r--nixpkgs/pkgs/servers/mail/mailman/fix-var-prefix.patch33
-rw-r--r--nixpkgs/pkgs/servers/mail/mlmmj/default.nix27
-rw-r--r--nixpkgs/pkgs/servers/mail/nullmailer/default.nix51
-rw-r--r--nixpkgs/pkgs/servers/mail/opensmtpd/default.nix68
-rw-r--r--nixpkgs/pkgs/servers/mail/opensmtpd/extras.nix92
-rw-r--r--nixpkgs/pkgs/servers/mail/opensmtpd/fix-build.diff12
-rw-r--r--nixpkgs/pkgs/servers/mail/opensmtpd/proc_path.diff59
-rw-r--r--nixpkgs/pkgs/servers/mail/petidomo/default.nix27
-rw-r--r--nixpkgs/pkgs/servers/mail/popa3d/default.nix28
-rw-r--r--nixpkgs/pkgs/servers/mail/popa3d/enable-standalone-mode.patch12
-rw-r--r--nixpkgs/pkgs/servers/mail/popa3d/fix-mail-spool-path.patch12
-rw-r--r--nixpkgs/pkgs/servers/mail/popa3d/use-glibc-crypt.patch12
-rw-r--r--nixpkgs/pkgs/servers/mail/popa3d/use-openssl.patch21
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/0001-Fix-build-with-unbound-1.6.1.patch54
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/default.nix98
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/pfixtools.nix55
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/pflogsumm.nix34
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/post-install-script.patch28
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/postfix-3.0-no-warnings.patch86
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/postfix-script-shell.patch21
-rw-r--r--nixpkgs/pkgs/servers/mail/postfix/relative-symlinks.patch13
-rw-r--r--nixpkgs/pkgs/servers/mail/postgrey/default.nix34
-rw-r--r--nixpkgs/pkgs/servers/mail/postsrsd/default.nix29
-rw-r--r--nixpkgs/pkgs/servers/mail/pypolicyd-spf/default.nix26
-rw-r--r--nixpkgs/pkgs/servers/mail/rmilter/default.nix33
-rw-r--r--nixpkgs/pkgs/servers/mail/rmilter/fd-passing-libmilter.patch80
-rw-r--r--nixpkgs/pkgs/servers/mail/rspamd/default.nix51
-rw-r--r--nixpkgs/pkgs/servers/mail/spamassassin/default.nix43
-rw-r--r--nixpkgs/pkgs/servers/mail/spamassassin/sa-update_add--siteconfigpath.patch59
-rw-r--r--nixpkgs/pkgs/servers/mail/system-sendmail/default.nix36
43 files changed, 2076 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/servers/mail/archiveopteryx/default.nix b/nixpkgs/pkgs/servers/mail/archiveopteryx/default.nix
new file mode 100644
index 000000000000..080cbc897756
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/archiveopteryx/default.nix
@@ -0,0 +1,42 @@
+{ stdenv, fetchurl, openssl, perl, zlib, jam }:
+stdenv.mkDerivation rec {
+  version = "3.2.0";
+  name = "archiveopteryx-${version}";
+
+  src = fetchurl {
+    url = "http://archiveopteryx.org/download/${name}.tar.bz2";
+    sha256 = "0i0zg8di8nbh96qnyyr156ikwcsq1w9b2291bazm5whb351flmqx";
+  };
+
+  nativeBuildInputs = [ jam ];
+  buildInputs = [ openssl perl zlib ];
+
+  preConfigure = ''
+    export INSTALLROOT=installroot
+    sed -i 's:BINDIR = $(PREFIX)/bin:BINDIR = '$out'/bin:' ./Jamsettings
+    sed -i 's:SBINDIR = $(PREFIX)/sbin:SBINDIR = '$out'/bin:' ./Jamsettings
+    sed -i 's:LIBDIR = $(PREFIX)/lib:LIBDIR = '$out'/lib:' ./Jamsettings
+    sed -i 's:MANDIR = $(PREFIX)/man:MANDIR = '$out'/share/man:' ./Jamsettings
+    sed -i 's:READMEDIR = $(PREFIX):READMEDIR = '$out'/share/doc/archiveopteryx:' ./Jamsettings
+  '';
+
+  # fix build on gcc7
+  NIX_CFLAGS_COMPILE = [
+    "-Wno-error=builtin-declaration-mismatch"
+    "-Wno-error=implicit-fallthrough"
+  ];
+
+  buildPhase = ''jam "-j$NIX_BUILD_CORES" '';
+  installPhase = ''
+    jam install
+    mv installroot/$out $out
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://archiveopteryx.org/;
+    description = "An advanced PostgreSQL-based IMAP/POP server";
+    license = licenses.postgresql;
+    maintainers = [ maintainers.phunehehe ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/clamsmtp/default.nix b/nixpkgs/pkgs/servers/mail/clamsmtp/default.nix
new file mode 100644
index 000000000000..7214c08d2427
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/clamsmtp/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "clamsmtp-" + version;
+  version = "1.10";
+
+  src = fetchurl {
+    url = "http://thewalter.net/stef/software/clamsmtp/${name}.tar.gz";
+    sha256 = "0apr1pxifw6f1rbbsdrrwzs1dnhybg4hda3qqhqcw7p14r5xnbx5";
+  };
+
+  patches = [ ./header-order.patch ];
+
+  meta = with stdenv.lib; {
+    description = "SMTP filter that allows to check for viruses using the ClamAV
+                   anti-virus software";
+    homepage = http://thewalter.net/stef/software/clamsmtp/;
+    license = licenses.bsd3;
+    maintainers = [ maintainers.ekleog ];
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/clamsmtp/header-order.patch b/nixpkgs/pkgs/servers/mail/clamsmtp/header-order.patch
new file mode 100644
index 000000000000..102ae0a471dd
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/clamsmtp/header-order.patch
@@ -0,0 +1,25 @@
+diff --git a/common/smtppass.c b/common/smtppass.c
+index d9be1ba..4a366f4 100644
+--- a/common/smtppass.c
++++ b/common/smtppass.c
+@@ -60,15 +60,15 @@
+ 
+ #include "usuals.h"
+ 
+-#ifdef LINUX_TRANSPARENT_PROXY
+-#include <linux/netfilter_ipv4.h>
+-#endif
+-
+ #include "compat.h"
+ #include "sock_any.h"
+ #include "stringx.h"
+ #include "sppriv.h"
+ 
++#ifdef LINUX_TRANSPARENT_PROXY
++#include <linux/netfilter_ipv4.h>
++#endif
++
+ /* -----------------------------------------------------------------------
+  *  STRUCTURES
+  */
+
diff --git a/nixpkgs/pkgs/servers/mail/dkimproxy/default.nix b/nixpkgs/pkgs/servers/mail/dkimproxy/default.nix
new file mode 100644
index 000000000000..2912ce4cfcaa
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/dkimproxy/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, perl, fetchurl, Error, MailDKIM, MIMETools, NetServer }:
+
+let
+  pkg = "dkimproxy";
+  version = "1.4.1";
+in
+stdenv.mkDerivation rec {
+  name = "${pkg}-${version}";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/dkimproxy/${name}.tar.gz";
+    sha256 = "1gc5c7lg2qrlck7b0lvjfqr824ch6jkrzkpsn0gjvlzg7hfmld75";
+  };
+
+  # Idea taken from pkgs/development/perl-modules/generic/builder.sh
+  preFixup = ''
+    perlFlags=
+    for i in $(IFS=:; echo $PERL5LIB); do
+      perlFlags="$perlFlags -I$i"
+    done
+    for f in $(ls $out/bin); do
+      sed -i $out/bin/$f -e "s|#\!\(.*/perl.*\)$|#\! \1 $perlFlags|"
+    done
+  '';
+
+  buildInputs = [ perl ];
+  propagatedBuildInputs = [ Error MailDKIM MIMETools NetServer ];
+
+  meta = with stdenv.lib; {
+    description = "SMTP-proxy that signs and/or verifies emails";
+    homepage = http://dkimproxy.sourceforge.net/;
+    license = licenses.gpl2Plus;
+    maintainers = [ maintainers.ekleog ];
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch b/nixpkgs/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch
new file mode 100644
index 000000000000..1914933c558c
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/dovecot/2.2.x-module_dir.patch
@@ -0,0 +1,122 @@
+diff --git a/src/auth/main.c b/src/auth/main.c
+index 5a87c57..74bff52 100644
+--- a/src/auth/main.c
++++ b/src/auth/main.c
+@@ -194,7 +194,7 @@ static void main_preinit(void)
+ 	mod_set.debug = global_auth_settings->debug;
+ 	mod_set.filter_callback = auth_module_filter;
+ 
+-	modules = module_dir_load(AUTH_MODULE_DIR, NULL, &mod_set);
++	modules = module_dir_load("/etc/dovecot/modules/auth", NULL, &mod_set);
+ 	module_dir_init(modules);
+ 
+ 	if (!worker)
+@@ -225,7 +225,7 @@ void auth_module_load(const char *names)
+ 	mod_set.debug = global_auth_settings->debug;
+ 	mod_set.ignore_missing = TRUE;
+ 
+-	modules = module_dir_load_missing(modules, AUTH_MODULE_DIR, names,
++	modules = module_dir_load_missing(modules, "/etc/dovecot/modules/auth", names,
+ 					  &mod_set);
+ 	module_dir_init(modules);
+ }
+diff --git a/src/config/all-settings.c b/src/config/all-settings.c
+index de223a5..2df2d21 100644
+--- a/src/config/all-settings.c
++++ b/src/config/all-settings.c
+@@ -836,7 +836,7 @@ static const struct mail_user_settings mail_user_default_settings = {
+ 	.last_valid_gid = 0,
+ 
+ 	.mail_plugins = "",
+-	.mail_plugin_dir = MODULEDIR,
++	.mail_plugin_dir = "/etc/dovecot/modules",
+ 
+ 	.mail_log_prefix = "%s(%u): ",
+ 
+@@ -3545,7 +3545,7 @@ const struct doveadm_settings doveadm_default_settings = {
+ 	.base_dir = PKG_RUNDIR,
+ 	.libexec_dir = PKG_LIBEXECDIR,
+ 	.mail_plugins = "",
+-	.mail_plugin_dir = MODULEDIR,
++	.mail_plugin_dir = "/etc/dovecot/modules",
+ 	.auth_debug = FALSE,
+ 	.auth_socket_path = "auth-userdb",
+ 	.doveadm_socket_path = "doveadm-server",
+diff --git a/src/config/config-parser.c b/src/config/config-parser.c
+index 2a5009a..134f92b 100644
+--- a/src/config/config-parser.c
++++ b/src/config/config-parser.c
+@@ -1047,7 +1047,7 @@ void config_parse_load_modules(void)
+ 
+ 	memset(&mod_set, 0, sizeof(mod_set));
+ 	mod_set.abi_version = DOVECOT_ABI_VERSION;
+-	modules = module_dir_load(CONFIG_MODULE_DIR, NULL, &mod_set);
++	modules = module_dir_load("/etc/dovecot/modules/settings", NULL, &mod_set);
+ 	module_dir_init(modules);
+ 
+ 	i_array_init(&new_roots, 64);
+diff --git a/src/dict/main.c b/src/dict/main.c
+index e6c945e..06ad6c5 100644
+--- a/src/dict/main.c
++++ b/src/dict/main.c
+@@ -62,7 +62,7 @@ static void main_init(void)
+ 	mod_set.abi_version = DOVECOT_ABI_VERSION;
+ 	mod_set.require_init_funcs = TRUE;
+ 
+-	modules = module_dir_load(DICT_MODULE_DIR, NULL, &mod_set);
++	modules = module_dir_load("/etc/dovecot/modules/dict", NULL, &mod_set);
+ 	module_dir_init(modules);
+ 
+ 	/* Register only after loading modules. They may contain SQL drivers,
+diff --git a/src/doveadm/doveadm-settings.c b/src/doveadm/doveadm-settings.c
+index df12284..19c18da 100644
+--- a/src/doveadm/doveadm-settings.c
++++ b/src/doveadm/doveadm-settings.c
+@@ -81,7 +81,7 @@ const struct doveadm_settings doveadm_default_settings = {
+ 	.base_dir = PKG_RUNDIR,
+ 	.libexec_dir = PKG_LIBEXECDIR,
+ 	.mail_plugins = "",
+-	.mail_plugin_dir = MODULEDIR,
++	.mail_plugin_dir = "/etc/dovecot/modules",
+ 	.auth_debug = FALSE,
+ 	.auth_socket_path = "auth-userdb",
+ 	.doveadm_socket_path = "doveadm-server",
+diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c
+index b50fbe0..ace3aff 100644
+--- a/src/lib-fs/fs-api.c
++++ b/src/lib-fs/fs-api.c
+@@ -114,7 +114,7 @@ static void fs_class_try_load_plugin(const char *driver)
+ 	mod_set.abi_version = DOVECOT_ABI_VERSION;
+ 	mod_set.ignore_missing = TRUE;
+ 
+-	fs_modules = module_dir_load_missing(fs_modules, MODULE_DIR,
++	fs_modules = module_dir_load_missing(fs_modules, "/etc/dovecot/modules",
+ 					     module_name, &mod_set);
+ 	module_dir_init(fs_modules);
+ 
+diff --git a/src/lib-ssl-iostream/iostream-ssl.c b/src/lib-ssl-iostream/iostream-ssl.c
+index a0659ab..dba3729 100644
+--- a/src/lib-ssl-iostream/iostream-ssl.c
++++ b/src/lib-ssl-iostream/iostream-ssl.c
+@@ -34,7 +34,7 @@ static int ssl_module_load(const char **error_r)
+ 	mod_set.abi_version = DOVECOT_ABI_VERSION;
+ 	mod_set.setting_name = "<built-in lib-ssl-iostream lookup>";
+ 	mod_set.require_init_funcs = TRUE;
+-	ssl_module = module_dir_load(MODULE_DIR, plugin_name, &mod_set);
++	ssl_module = module_dir_load("/etc/dovecot/modules", plugin_name, &mod_set);
+ 	if (module_dir_try_load_missing(&ssl_module, MODULE_DIR, plugin_name,
+ 					&mod_set, error_r) < 0)
+ 		return -1;
+diff --git a/src/lib-storage/mail-storage-settings.c b/src/lib-storage/mail-storage-settings.c
+index e2233bf..bbf981e 100644
+--- a/src/lib-storage/mail-storage-settings.c
++++ b/src/lib-storage/mail-storage-settings.c
+@@ -274,7 +274,7 @@ static const struct mail_user_settings mail_user_default_settings = {
+ 	.last_valid_gid = 0,
+ 
+ 	.mail_plugins = "",
+-	.mail_plugin_dir = MODULEDIR,
++	.mail_plugin_dir = "/etc/dovecot/modules",
+ 
+ 	.mail_log_prefix = "%s(%u): ",
+ 
diff --git a/nixpkgs/pkgs/servers/mail/dovecot/default.nix b/nixpkgs/pkgs/servers/mail/dovecot/default.nix
new file mode 100644
index 000000000000..6c6ddf651e62
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/dovecot/default.nix
@@ -0,0 +1,75 @@
+{ stdenv, lib, fetchurl, perl, pkgconfig, systemd, openssl
+, bzip2, zlib, lz4, inotify-tools, pam, libcap
+, clucene_core_2, icu, openldap, libsodium, libstemmer, cyrus_sasl
+, nixosTests
+# Auth modules
+, withMySQL ? false, mysql
+, withPgSQL ? false, postgresql
+, withSQLite ? true, sqlite
+}:
+
+stdenv.mkDerivation rec {
+  name = "dovecot-2.3.4";
+
+  nativeBuildInputs = [ perl pkgconfig ];
+  buildInputs =
+    [ openssl bzip2 zlib lz4 clucene_core_2 icu openldap libsodium libstemmer cyrus_sasl.dev ]
+    ++ lib.optionals (stdenv.isLinux) [ systemd pam libcap inotify-tools ]
+    ++ lib.optional withMySQL mysql.connector-c
+    ++ lib.optional withPgSQL postgresql
+    ++ lib.optional withSQLite sqlite;
+
+  src = fetchurl {
+    url = "https://dovecot.org/releases/2.3/${name}.tar.gz";
+    sha256 = "01ggzf7b3jpl89mjiqr7xbpbs181g2gjf6wzg70qaqfzz3ppc6yr";
+  };
+
+  preConfigure = ''
+    patchShebangs src/config/settings-get.pl
+  '';
+
+  # We need this for sysconfdir, see remark below.
+  installFlags = [ "DESTDIR=$(out)" ];
+
+  postInstall = ''
+    cp -r $out/$out/* $out
+    rm -rf $out/$(echo "$out" | cut -d "/" -f2)
+  '';
+
+  patches = [
+    # Make dovecot look for plugins in /etc/dovecot/modules
+    # so we can symlink plugins from several packages there.
+    # The symlinking needs to be done in NixOS.
+    ./2.2.x-module_dir.patch
+  ];
+
+  configureFlags = [
+    # It will hardcode this for /var/lib/dovecot.
+    # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=626211
+    "--localstatedir=/var"
+    # We need this so utilities default to reading /etc/dovecot/dovecot.conf file.
+    "--sysconfdir=/etc"
+    "--with-ldap"
+    "--with-ssl=openssl"
+    "--with-zlib"
+    "--with-bzlib"
+    "--with-lz4"
+    "--with-ldap"
+    "--with-lucene"
+    "--with-icu"
+  ] ++ lib.optional (stdenv.isLinux) "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+    ++ lib.optional (stdenv.isDarwin) "--enable-static"
+    ++ lib.optional withMySQL "--with-mysql"
+    ++ lib.optional withPgSQL "--with-pgsql"
+    ++ lib.optional withSQLite "--with-sqlite";
+
+  meta = {
+    homepage = https://dovecot.org/;
+    description = "Open source IMAP and POP3 email server written with security primarily in mind";
+    maintainers = with stdenv.lib.maintainers; [ peti rickynils fpletz ];
+    platforms = stdenv.lib.platforms.unix;
+  };
+  passthru.tests = {
+    opensmtpd-interaction = nixosTests.opensmtpd;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix b/nixpkgs/pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix
new file mode 100644
index 000000000000..73d6b5d593c9
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/dovecot/plugins/pigeonhole/default.nix
@@ -0,0 +1,38 @@
+{ stdenv, fetchurl, dovecot, openssl }:
+
+stdenv.mkDerivation rec {
+  name = "dovecot-pigeonhole-${version}";
+  version = "0.5.4";
+
+  src = fetchurl {
+    url = "https://pigeonhole.dovecot.org/releases/2.3/dovecot-2.3-pigeonhole-${version}.tar.gz";
+    sha256 = "05l5y0gc8ycswdbl58j7kbx5gq1z7mjkazjccmgbq6h0gbk9jyal";
+  };
+
+  buildInputs = [ dovecot openssl ];
+
+  preConfigure = ''
+    substituteInPlace src/managesieve/managesieve-settings.c --replace \
+      ".executable = \"managesieve\"" \
+      ".executable = \"$out/libexec/dovecot/managesieve\""
+    substituteInPlace src/managesieve-login/managesieve-login-settings.c --replace \
+      ".executable = \"managesieve-login\"" \
+      ".executable = \"$out/libexec/dovecot/managesieve-login\""
+  '';
+
+  configureFlags = [
+    "--with-dovecot=${dovecot}/lib/dovecot"
+    "--without-dovecot-install-dirs"
+    "--with-moduledir=$(out)/lib/dovecot"
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    homepage = http://pigeonhole.dovecot.org/;
+    description = "A sieve plugin for the Dovecot IMAP server";
+    license = licenses.lgpl21;
+    maintainers = [ maintainers.rickynils ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/dspam/default.nix b/nixpkgs/pkgs/servers/mail/dspam/default.nix
new file mode 100644
index 000000000000..8fa7719a722b
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/dspam/default.nix
@@ -0,0 +1,108 @@
+{ stdenv, lib, fetchurl, makeWrapper
+, gawk, gnused, gnugrep, coreutils, which
+, perl, libnet
+, withMySQL ? false, zlib, mysql57
+, withPgSQL ? false, postgresql
+, withSQLite ? false, sqlite
+, withDB ? false, db
+}:
+
+let
+  drivers = lib.concatStringsSep ","
+            ([ "hash_drv" ]
+             ++ lib.optional withMySQL "mysql_drv"
+             ++ lib.optional withPgSQL "pgsql_drv"
+             ++ lib.optional withSQLite "sqlite3_drv"
+             ++ lib.optional withDB "libdb4_drv"
+            );
+  maintenancePath = lib.makeBinPath [ gawk gnused gnugrep coreutils which ];
+
+in stdenv.mkDerivation rec {
+  name = "dspam-3.10.2";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/dspam/dspam/${name}/${name}.tar.gz";
+    sha256 = "1acklnxn1wvc7abn31l3qdj8q6k13s51k5gv86vka7q20jb5cxmf";
+  };
+
+  buildInputs = [ perl ]
+                ++ lib.optionals withMySQL [ zlib mysql57.connector-c ]
+                ++ lib.optional withPgSQL postgresql
+                ++ lib.optional withSQLite sqlite
+                ++ lib.optional withDB db;
+  nativeBuildInputs = [ makeWrapper ];
+
+  configureFlags = [
+    "--with-storage-driver=${drivers}"
+    "--sysconfdir=/etc/dspam"
+    "--localstatedir=/var"
+    "--with-dspam-home=/var/lib/dspam"
+    "--with-logdir=/var/log/dspam"
+    "--with-logfile=/var/log/dspam/dspam.log"
+
+    "--enable-daemon"
+    "--enable-clamav"
+    "--enable-syslog"
+    "--enable-large-scale"
+    "--enable-virtual-users"
+    "--enable-split-configuration"
+    "--enable-preferences-extension"
+    "--enable-long-usernames"
+    "--enable-external-lookup"
+  ] ++ lib.optional withMySQL "--with-mysql-includes=${mysql57.connector-c}/include/mysql"
+    ++ lib.optional withPgSQL "--with-pgsql-libraries=${postgresql.lib}/lib";
+
+  # Lots of things are hardwired to paths like sysconfdir. That's why we install with both "prefix" and "DESTDIR"
+  # and fix directory structure manually after that.
+  installFlags = [ "DESTDIR=$(out)" ];
+
+  postInstall = ''
+    cp -r $out/$out/* $out
+    rm -rf $out/$(echo "$out" | cut -d "/" -f2)
+    rm -rf $out/var
+
+    wrapProgram $out/bin/dspam_notify \
+      --set PERL5LIB "${lib.makePerlPath [ libnet ]}"
+
+    # Install SQL scripts
+    mkdir -p $out/share/dspam/sql
+    # MySQL
+    cp src/tools.mysql_drv/mysql_*.sql $out/share/dspam/sql
+    for i in src/tools.mysql_drv/{purge*.sql,virtual*.sql}; do
+      cp "$i" $out/share/dspam/sql/mysql_$(basename "$i")
+    done
+    # PostgreSQL
+    cp src/tools.pgsql_drv/pgsql_*.sql $out/share/dspam/sql
+    for i in src/tools.pgsql_drv/{purge*.sql,virtual*.sql}; do
+      cp "$i" $out/share/dspam/sql/pgsql_$(basename "$i")
+    done
+    # SQLite
+    for i in src/tools.sqlite_drv/purge*.sql; do
+      cp "$i" $out/share/dspam/sql/sqlite_$(basename "$i")
+    done
+
+    # Install maintenance script
+    install -Dm755 contrib/dspam_maintenance/dspam_maintenance.sh $out/bin/dspam_maintenance
+    sed -i \
+      -e "2iexport PATH=$out/bin:${maintenancePath}:\$PATH" \
+      -e 's,/usr/[a-z0-9/]*,,g' \
+      -e 's,^DSPAM_CONFIGDIR=.*,DSPAM_CONFIGDIR=/etc/dspam,' \
+      -e "s,^DSPAM_HOMEDIR=.*,DSPAM_HOMEDIR=/var/lib/dspam," \
+      -e "s,^DSPAM_PURGE_SCRIPT_DIR=.*,DSPAM_PURGE_SCRIPT_DIR=$out/share/dspam/sql," \
+      -e "s,^DSPAM_BIN_DIR=.*,DSPAM_BIN_DIR=$out/bin," \
+      -e "s,^MYSQL_BIN_DIR=.*,MYSQL_BIN_DIR=/run/current-system/sw/bin," \
+      -e "s,^PGSQL_BIN_DIR=.*,PGSQL_BIN_DIR=/run/current-system/sw/bin," \
+      -e "s,^SQLITE_BIN_DIR=.*,SQLITE_BIN_DIR=/run/current-system/sw/bin," \
+      -e "s,^SQLITE3_BIN_DIR=.*,SQLITE3_BIN_DIR=/run/current-system/sw/bin," \
+      -e 's,^DSPAM_CRON_LOCKFILE=.*,DSPAM_CRON_LOCKFILE=/run/dspam/dspam_maintenance.pid,' \
+      $out/bin/dspam_maintenance
+  '';
+
+  meta = with lib; {
+    homepage = http://nuclearelephant.com/;
+    description = "Community Driven Antispam Filter";
+    license = licenses.agpl3;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/exim/default.nix b/nixpkgs/pkgs/servers/mail/exim/default.nix
new file mode 100644
index 000000000000..07623a80f243
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/exim/default.nix
@@ -0,0 +1,96 @@
+{ coreutils, db, fetchurl, openssl, pcre, perl, pkgconfig, stdenv
+, enableLDAP ? false, openldap
+, enableMySQL ? false, mysql, zlib
+, enableAuthDovecot ? false, dovecot
+, enablePAM ? false, pam
+}:
+
+stdenv.mkDerivation rec {
+  name = "exim-4.91";
+
+  src = fetchurl {
+    url = "https://ftp.exim.org/pub/exim/exim4/${name}.tar.xz";
+    sha256 = "066ip7a5lqfn9rcr14j4nm0kqysw6mzvbbb0ip50lmfm0fqsqmzc";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ coreutils db openssl perl pcre ]
+    ++ stdenv.lib.optional enableLDAP openldap
+    ++ stdenv.lib.optionals enableMySQL [ mysql zlib ]
+    ++ stdenv.lib.optional enableAuthDovecot dovecot
+    ++ stdenv.lib.optional enablePAM pam;
+
+  preBuild = ''
+    ${stdenv.lib.optionalString enableMySQL "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${mysql}/share/mysql/pkgconfig/"}
+    sed '
+      s:^\(BIN_DIRECTORY\)=.*:\1='"$out"'/bin:
+      s:^\(CONFIGURE_FILE\)=.*:\1=/etc/exim.conf:
+      s:^\(EXIM_USER\)=.*:\1=ref\:nobody:
+      s:^\(SPOOL_DIRECTORY\)=.*:\1=/exim-homeless-shelter:
+      s:^# \(TRANSPORT_LMTP\)=.*:\1=yes:
+      s:^# \(SUPPORT_MAILDIR\)=.*:\1=yes:
+      s:^EXIM_MONITOR=.*$:# &:
+      s:^\(FIXED_NEVER_USERS\)=root$:\1=0:
+      s:^# \(WITH_CONTENT_SCAN\)=.*:\1=yes:
+      s:^# \(AUTH_PLAINTEXT\)=.*:\1=yes:
+      s:^# \(SUPPORT_TLS\)=.*:\1=yes:
+      s:^# \(USE_OPENSSL_PC=openssl\)$:\1:
+      s:^# \(LOG_FILE_PATH=syslog\)$:\1:
+      s:^# \(HAVE_IPV6=yes\)$:\1:
+      s:^# \(CHOWN_COMMAND\)=.*:\1=${coreutils}/bin/chown:
+      s:^# \(CHGRP_COMMAND\)=.*:\1=${coreutils}/bin/chgrp:
+      s:^# \(CHMOD_COMMAND\)=.*:\1=${coreutils}/bin/chmod:
+      s:^# \(MV_COMMAND\)=.*:\1=${coreutils}/bin/mv:
+      s:^# \(RM_COMMAND\)=.*:\1=${coreutils}/bin/rm:
+      s:^# \(TOUCH_COMMAND\)=.*:\1=${coreutils}/bin/touch:
+      s:^# \(PERL_COMMAND\)=.*:\1=${perl}/bin/perl:
+      ${stdenv.lib.optionalString enableLDAP ''
+        s:^# \(LDAP_LIB_TYPE=OPENLDAP2\)$:\1:
+        s:^# \(LOOKUP_LDAP=yes\)$:\1:
+        s:^\(LOOKUP_LIBS\)=\(.*\):\1=\2 -lldap:
+        s:^# \(LOOKUP_LIBS\)=.*:\1=-lldap:
+      ''}
+      ${stdenv.lib.optionalString enableMySQL ''
+        s:^# \(LOOKUP_MYSQL=yes\)$:\1:
+        s:^# \(LOOKUP_MYSQL_PC=mariadb\)$:\1:
+        s:^\(LOOKUP_LIBS\)=\(.*\):\1=\2 -lmysqlclient:
+        s:^# \(LOOKUP_LIBS\)=.*:\1=-lmysqlclient:
+        s:^# \(LOOKUP_INCLUDE\)=.*:\1=-I${mysql}/include/mysql/:
+      ''}
+      ${stdenv.lib.optionalString enableAuthDovecot ''
+        s:^# \(AUTH_DOVECOT\)=.*:\1=yes:
+      ''}
+      ${stdenv.lib.optionalString enablePAM ''
+        s:^# \(SUPPORT_PAM\)=.*:\1=yes:
+        s:^\(EXTRALIBS_EXIM\)=\(.*\):\1=\2 -lpam:
+        s:^# \(EXTRALIBS_EXIM\)=.*:\1=-lpam:
+      ''}
+      #/^\s*#.*/d
+      #/^\s*$/d
+    ' < src/EDITME > Local/Makefile
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin $out/share/man/man8
+    cp doc/exim.8 $out/share/man/man8
+
+    ( cd build-Linux-*
+      cp exicyclog exim_checkaccess exim_dumpdb exim_lock exim_tidydb \
+        exipick exiqsumm exigrep exim_dbmbuild exim exim_fixdb eximstats \
+        exinext exiqgrep exiwhat \
+        $out/bin )
+
+    ( cd $out/bin
+      for i in mailq newaliases rmail rsmtp runq sendmail; do
+        ln -s exim $i
+      done )
+  '';
+
+  meta = {
+    homepage = http://exim.org/;
+    description = "A mail transfer agent (MTA)";
+    license = stdenv.lib.licenses.gpl3;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.tv ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/freepops/default.nix b/nixpkgs/pkgs/servers/mail/freepops/default.nix
new file mode 100644
index 000000000000..b4f671862f88
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/freepops/default.nix
@@ -0,0 +1,29 @@
+{stdenv, fetchurl, pkgconfig, openssl, lua5, curl, readline, bison, expat}:
+
+stdenv.mkDerivation {
+  name = "freepops-0.2.9";
+  src = fetchurl {
+    url = mirror://sourceforge/freepops/0.2.9/freepops-0.2.9.tar.gz;
+    sha256 = "3a065e30cafed03d9b6fdb28251ae5bf0d8aeb62181746154beecd25dc0c9cae";
+  };
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ openssl lua5 curl readline bison expat];
+  configurePhase =
+  ''
+    export WHERE=$prefix/
+    export LOCALEDIR=$prefix/share/locale/
+    ./configure.sh linux
+  '';
+
+  meta = {
+    description = "An extensible pop3 server";
+    longDescription = ''
+      FreePOPs is an extensible pop3 server. Its main purpose is to provide
+      a pop3 interface to a webmail.
+    '';
+    homepage = http://www.freepops.org/;
+    platforms = with stdenv.lib.platforms; linux;
+    maintainers = with stdenv.lib.maintainers; [ pierron ];
+    broken = true;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/mailhog/default.nix b/nixpkgs/pkgs/servers/mail/mailhog/default.nix
new file mode 100644
index 000000000000..019c84d2898b
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/mailhog/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, buildGoPackage, fetchFromGitHub }:
+
+buildGoPackage rec {
+  name = "MailHog-${version}";
+  version = "1.0.0";
+  rev = "v${version}";
+
+  goPackagePath = "github.com/mailhog/MailHog";
+
+  src = fetchFromGitHub {
+    inherit rev;
+    owner = "mailhog";
+    repo = "MailHog";
+    sha256 = "0r6zidkffb8q12zyxd063jy0ig2x93llna4zb5i2qjh9gb971i83";
+  };
+
+  goDeps = ./deps.nix;
+
+  meta = with stdenv.lib; {
+    description = "Web and API based SMTP testing";
+    homepage = https://github.com/mailhog/MailHog;
+    maintainers = with maintainers; [ disassembler ];
+    license = licenses.mit;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/mailhog/deps.nix b/nixpkgs/pkgs/servers/mail/mailhog/deps.nix
new file mode 100644
index 000000000000..9967c3a549a5
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/mailhog/deps.nix
@@ -0,0 +1,191 @@
+[
+  {
+    goPackagePath = "github.com/gorilla/pat";
+    fetch = {
+      type = "git";
+      url = "https://github.com/gorilla/pat";
+      rev = "cf955c3d1f2c27ee96f93e9738085c762ff5f49d";
+      sha256 = "1jnhdhba3cwgsgv6qf7shvmk2nbbp8z30n9cimz9w6vd940ipisf";
+    };
+  }
+  {
+    goPackagePath = "github.com/gorilla/context";
+    fetch = {
+      type = "git";
+      url = "https://github.com/gorilla/context";
+      rev = "1ea25387ff6f684839d82767c1733ff4d4d15d0a";
+      sha256 = "1nh1nzxcsgd215x4xn59wc4cbqfa8zvhvnnx5p8fkrn4bj1cgak4";
+    };
+  }
+  {
+    goPackagePath = "github.com/gorilla/mux";
+    fetch = {
+      type = "git";
+      url = "https://github.com/gorilla/mux";
+      rev = "bcd8bc72b08df0f70df986b97f95590779502d31";
+      sha256 = "0majd18zn8v1b1agn015vnk3xk2v8j5nyckczlf72gm3kaq3icga";
+    };
+  }
+  {
+    goPackagePath = "github.com/gorilla/websocket";
+    fetch = {
+      type = "git";
+      url = "https://github.com/gorilla/websocket";
+      rev = "3ab3a8b8831546bd18fd182c20687ca853b2bb13";
+      sha256 = "17y94ngp1yrswq5pxxy97naiw6jgxz2yvm8zydi83gfixdgs99fc";
+    };
+  }
+  {
+    goPackagePath = "github.com/ian-kent/go-log";
+    fetch = {
+      type = "git";
+      url = "https://github.com/ian-kent/go-log";
+      rev = "5731446c36ab9f716106ce0731f484c50fdf1ad1";
+      sha256 = "1qr0myg68r9zq43fnx0rbnxcny2jpyg3gc269pc2riskqk0a731d";
+    };
+  }
+  {
+    goPackagePath = "github.com/ian-kent/envconf";
+    fetch = {
+      type = "git";
+      url = "https://github.com/ian-kent/envconf";
+      rev = "c19809918c02ab33dc8635d68c77649313185275";
+      sha256 = "1085863rnx4h0q9xvg4zlsc7xf7jngfmjrq83cpcv1ayi664mzdx";
+    };
+  }
+  {
+    goPackagePath = "github.com/ian-kent/goose";
+    fetch = {
+      type = "git";
+      url = "https://github.com/ian-kent/goose";
+      rev = "c3541ea826ad9e0f8a4a8c15ca831e8b0adde58c";
+      sha256 = "0v98d2554vlrm8mzk2zx8wj3daq076273w0zs8ww1aa57a1l74qv";
+    };
+  }
+  {
+    goPackagePath = "github.com/ian-kent/linkio";
+    fetch = {
+      type = "git";
+      url = "https://github.com/ian-kent/linkio";
+      rev = "77fb4b01842cb4b019137c0227df9a8f9779d0bd";
+      sha256 = "0fixidplxzmw7aakw19d64nvrykwm5xk55fj1q74n70s8j5d8hiq";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/MailHog-Server";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/MailHog-Server";
+      rev = "50f74a1aa2991b96313144d1ac718ce4d6739dfd";
+      sha256 = "1h0qs66bvgygpq0sz3w6y445vm3pvlrljr5x7xr13y0087mrpjla";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/MailHog-UI";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/MailHog-UI";
+      rev = "24b31a47cc5b65d23576bb9884c941d2b88381f7";
+      sha256 = "0309jmryhx3n0yksssk2j4xkh1xb01468i5f2sy3a83xkz9p3d54";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/http";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/http";
+      rev = "2e653938bf190d0e2fbe4825ce74e5bc149a62f2";
+      sha256 = "18j03lvyis7z0mv3fym3j9a7pi2qvnhggmhpxnjbwvwb86dhxjm8";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/mhsendmail";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/mhsendmail";
+      rev = "002527025ef50364446d7560600aedc5daaa1997";
+      sha256 = "11l2y0xb7hwk0zs7pwif3xkclhz32sc0jff3jkaxi3jdf3q3kz91";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/data";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/data";
+      rev = "024d554958b5bea5db220bfd84922a584d878ded";
+      sha256 = "0dgh0pcsn0xrxsn1qlxgdssaimch57kxj5vyvhqjnsdnh814g9vf";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/smtp";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/smtp";
+      rev = "0c4e9b7e0625fec61d0c30d7b2f6c62852be6c54";
+      sha256 = "1w46w3asdxsgzyall16hi2s4jvkka1k3a1l52ryfhrzg187krir6";
+    };
+  }
+  {
+    goPackagePath = "github.com/mailhog/storage";
+    fetch = {
+      type = "git";
+      url = "https://github.com/mailhog/storage";
+      rev = "6d871fb23ecd873cb10cdfc3a8dec5f50d2af8fa";
+      sha256 = "1ya0xigm2xysin59zlp2sbqncnmw9h77r9dn9k7vxhf0z8vvbibk";
+    };
+  }
+  {
+    goPackagePath = "github.com/ogier/pflag";
+    fetch = {
+      type = "git";
+      url = "https://github.com/ogier/pflag";
+      rev = "32a05c62658bd1d7c7e75cbc8195de5d585fde0f";
+      sha256 = "1lyrr9wx0j087mnpsxcbspjcgh9a5c6bqwrasd8s237jlyc50qmj";
+    };
+  }
+  {
+    goPackagePath = "github.com/tinylib/msgp";
+    fetch = {
+      type = "git";
+      url = "https://github.com/tinylib/msgp";
+      rev = "02d047e07459c5a7b02b1244161d0f2f6d8f660d";
+      sha256 = "12y7qz1x266m0a0w3zwd49achxbh036yhkmx93xfs2283xh70q1r";
+    };
+  }
+  {
+    goPackagePath = "github.com/philhofer/fwd";
+    fetch = {
+      type = "git";
+      url = "https://github.com/philhofer/fwd";
+      rev = "1612a298117663d7bc9a760ae20d383413859798";
+      sha256 = "155l0nvvblpx0fy683q6bzins7csh8fw7yf64hbia8hc7wh0gjdl";
+    };
+  }
+  {
+    goPackagePath = "github.com/t-k/fluent-logger-golang";
+    fetch = {
+      type = "git";
+      url = "https://github.com/t-k/fluent-logger-golang";
+      rev = "0f8ec08f2057a61574b6943e75045fffbeae894e";
+      sha256 = "0ic5bj87wpq1kncixd5mklwqn1jjwqfqfvkyl0mrnwp3p5p24v5c";
+    };
+  }
+  {
+    goPackagePath = "golang.org/x/crypto";
+    fetch = {
+      type = "git";
+      url = "https://go.googlesource.com/crypto";
+      rev = "c197bcf24cde29d3f73c7b4ac6fd41f4384e8af6";
+      sha256 = "1y2bbghi594m8p4pcm9pwrzql06179xj6zvhaghwcc6y0l48rbgp";
+    };
+  }
+  {
+    goPackagePath = "gopkg.in/mgo.v2";
+    fetch = {
+      type = "git";
+      url = "https://gopkg.in/mgo.v2";
+      rev = "d90005c5262a3463800497ea5a89aed5fe22c886";
+      sha256 = "1z81k6mnfk07hkrkw31l16qycyiwa6wzyhysmywgkh58sm5dc9m7";
+    };
+  }
+]
diff --git a/nixpkgs/pkgs/servers/mail/mailman/default.nix b/nixpkgs/pkgs/servers/mail/mailman/default.nix
new file mode 100644
index 000000000000..91445afa97df
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/mailman/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, python2 }:
+
+stdenv.mkDerivation rec {
+  name = "mailman-${version}";
+  version = "2.1.29";
+
+  src = fetchurl {
+    url = "mirror://gnu/mailman/${name}.tgz";
+    sha256 = "0b0dpwf6ap260791c7lg2vpw30llf19hymbf2hja3s016rqp5243";
+  };
+
+  buildInputs = [ python2 python2.pkgs.dnspython ];
+
+  patches = [ ./fix-var-prefix.patch ];
+
+  configureFlags = [
+    "--without-permcheck"
+    "--with-cgi-ext=.cgi"
+    "--with-var-prefix=/var/lib/mailman"
+  ];
+
+  installTargets = "doinstall"; # Leave out the 'update' target that's implied by 'install'.
+
+  makeFlags = [ "DIRSETGID=:" ];
+
+  meta = {
+    homepage = https://www.gnu.org/software/mailman/;
+    description = "Free software for managing electronic mail discussion and e-newsletter lists";
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.peti ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/mailman/fix-var-prefix.patch b/nixpkgs/pkgs/servers/mail/mailman/fix-var-prefix.patch
new file mode 100644
index 000000000000..9bb735ecbed7
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/mailman/fix-var-prefix.patch
@@ -0,0 +1,33 @@
+diff -ubr mailman-2.1.16-orig/contrib/redhat_fhs.patch mailman-2.1.16/contrib/redhat_fhs.patch
+--- mailman-2.1.16-orig/contrib/redhat_fhs.patch	2013-10-21 14:55:48.797631434 +0200
++++ mailman-2.1.16/contrib/redhat_fhs.patch	2013-10-21 14:56:42.534310378 +0200
+@@ -197,7 +197,7 @@
+ +	    else true; \
+ +	    fi; \
+ +	done
+- 	chmod o-r $(DESTDIR)$(var_prefix)/archives/private
++ 	chmod o-r $(prefix)$(var_prefix)/archives/private
+  	@for d in $(ARCH_INDEP_DIRS); \
+  	do \
+ Only in mailman-2.1.5.FHS: Makefile.in~
+diff -ubr mailman-2.1.16-orig/Makefile.in mailman-2.1.16/Makefile.in
+--- mailman-2.1.16-orig/Makefile.in	2013-10-21 14:55:48.798631519 +0200
++++ mailman-2.1.16/Makefile.in	2013-10-21 14:56:42.562313220 +0200
+@@ -87,7 +87,7 @@
+ 	@echo "Creating architecture independent directories..."
+ 	@for d in $(VAR_DIRS); \
+ 	do \
+-	    dir=$(DESTDIR)$(var_prefix)/$$d; \
++	    dir=$(prefix)$(var_prefix)/$$d; \
+ 	    if test ! -d $$dir; then \
+ 		echo "Creating directory hierarchy $$dir"; \
+ 		$(srcdir)/mkinstalldirs $$dir; \
+@@ -96,7 +96,7 @@
+ 	    else true; \
+ 	    fi; \
+ 	done
+-	chmod o-r $(DESTDIR)$(var_prefix)/archives/private
++	chmod o-r $(prefix)$(var_prefix)/archives/private
+ 	@for d in $(ARCH_INDEP_DIRS); \
+ 	do \
+ 	    dir=$(DESTDIR)$(prefix)/$$d; \
diff --git a/nixpkgs/pkgs/servers/mail/mlmmj/default.nix b/nixpkgs/pkgs/servers/mail/mlmmj/default.nix
new file mode 100644
index 000000000000..98b270ad7d41
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/mlmmj/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+
+  name = "mlmmj-${version}";
+  version = "1.3.0";
+
+  src = fetchurl {
+    url = "http://mlmmj.org/releases/${name}.tar.gz";
+    sha256 = "1sghqvwizvm1a9w56r34qy5njaq1c26bagj85r60h32gh3fx02bn";
+  };
+
+  postInstall = ''
+    # grab all documentation files
+    docfiles=$(find -maxdepth 1 -name "[[:upper:]][[:upper:]]*")
+    install -vDm 644 -t $out/share/doc/mlmmj/ $docfiles
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://mlmmj.org;
+    description = "Mailing List Management Made Joyful";
+    maintainers = [ maintainers.edwtjo ];
+    platforms = platforms.linux;
+    license = licenses.mit;
+  };
+
+}
diff --git a/nixpkgs/pkgs/servers/mail/nullmailer/default.nix b/nixpkgs/pkgs/servers/mail/nullmailer/default.nix
new file mode 100644
index 000000000000..4b753bdf0cdb
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/nullmailer/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, fetchurl, lib, tls ? true, gnutls ? null }:
+
+assert tls -> gnutls != null;
+
+stdenv.mkDerivation rec {
+
+  version = "2.2";
+  name = "nullmailer-${version}";
+
+  src = fetchurl {
+    url = "https://untroubled.org/nullmailer/nullmailer-${version}.tar.gz";
+    sha256 = "0md8cf90fl2yf3zh9njjy42a673v4j4ygyq95xg7fzkygdigm1lq";
+  };
+
+  buildInputs = stdenv.lib.optional tls gnutls;
+
+  configureFlags = [
+    "--sysconfdir=/etc"
+    "--localstatedir=/var"
+  ] ++ stdenv.lib.optional tls "--enable-tls";
+
+  installFlags = [ "DESTDIR=$(out)" ];
+
+  # We have to remove the ''var'' directory, since nix can't handle named pipes
+  # and we can't use it in the store anyway. Same for ''etc''.
+  # The second line is need, because the installer of nullmailer will copy its
+  # own prepared version of ''etc'' and ''var'' and also uses the prefix path (configure phase)
+  # for hardcoded absolute references to its own binary farm, e.g. sendmail binary is
+  # calling nullmailer-inject binary. Since we can't configure inside the store of
+  # the derivation we need both directories in the root, but don't want to put them there
+  # during install, hence we have to fix mumbling inside the install directory.
+  # This is kind of a hack, but the only way I know of, yet.
+  postInstall = ''
+    rm -rf $out/var/ $out/etc/
+    mv $out/$out/* $out/
+    rmdir $out/$out
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = http://untroubled.org/nullmailer/;
+    description = ''
+      A sendmail/qmail/etc replacement MTA for hosts which relay to a fixed set of smart relays.
+      It is designed to be simple to configure, secure, and easily extendable.
+    '';
+    license = lib.licenses.gpl2;
+    platforms = lib.platforms.all;
+    maintainers = with lib.maintainers ; [ sargon ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/opensmtpd/default.nix b/nixpkgs/pkgs/servers/mail/opensmtpd/default.nix
new file mode 100644
index 000000000000..695450f18222
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/opensmtpd/default.nix
@@ -0,0 +1,68 @@
+{ stdenv, lib, fetchurl, fetchpatch, autoconf, automake, libtool, bison
+, libasr, libevent, zlib, libressl, db, pam, nixosTests
+}:
+
+stdenv.mkDerivation rec {
+  name = "opensmtpd-${version}";
+  version = "6.4.0p2";
+
+  nativeBuildInputs = [ autoconf automake libtool bison ];
+  buildInputs = [ libasr libevent zlib libressl db pam ];
+
+  src = fetchurl {
+    url = "https://www.opensmtpd.org/archives/${name}.tar.gz";
+    sha256 = "1y7snhsrcdi56vaa23iwjpybhyrnnh2f6dxrfnacn7xgy5xwzbvn";
+  };
+
+  patches = [
+    ./proc_path.diff
+    ./fix-build.diff # See https://github.com/OpenSMTPD/OpenSMTPD/pull/884
+  ];
+
+  # See https://github.com/OpenSMTPD/OpenSMTPD/issues/885 for the `sh bootstrap`
+  # requirement
+  postPatch = ''
+    substituteInPlace smtpd/parse.y \
+      --replace "/usr/libexec/" "$out/libexec/opensmtpd/"
+    substituteInPlace mk/smtpctl/Makefile.am --replace "chgrp" "true"
+    substituteInPlace mk/smtpctl/Makefile.am --replace "chmod 2555" "chmod 0555"
+    sh bootstrap
+  '';
+
+  configureFlags = [
+    "--sysconfdir=/etc"
+    "--localstatedir=/var"
+    "--with-mantype=doc"
+    "--with-auth-pam"
+    "--without-auth-bsdauth"
+    "--with-path-socket=/run"
+    "--with-user-smtpd=smtpd"
+    "--with-user-queue=smtpq"
+    "--with-group-queue=smtpq"
+    "--with-path-CAfile=/etc/ssl/certs/ca-certificates.crt"
+    "--with-libevent=${libevent.dev}"
+    "--with-table-db"
+  ];
+
+  # See https://github.com/OpenSMTPD/OpenSMTPD/pull/884
+  makeFlags = [ "CFLAGS=-ffunction-sections" "LDFLAGS=-Wl,--gc-sections" ];
+
+  installFlags = [
+    "sysconfdir=\${out}/etc"
+    "localstatedir=\${TMPDIR}"
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = https://www.opensmtpd.org/;
+    description = ''
+      A free implementation of the server-side SMTP protocol as defined by
+      RFC 5321, with some additional standard extensions
+    '';
+    license = licenses.isc;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ rickynils obadz ekleog ];
+  };
+  passthru.tests = {
+    basic-functionality-and-dovecot-interaction = nixosTests.opensmtpd;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/opensmtpd/extras.nix b/nixpkgs/pkgs/servers/mail/opensmtpd/extras.nix
new file mode 100644
index 000000000000..1d4ad63c37d2
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/opensmtpd/extras.nix
@@ -0,0 +1,92 @@
+{ stdenv, fetchurl, openssl, libevent, libasr,
+  python2, pkgconfig, lua5, perl, mysql, postgresql, sqlite, hiredis,
+  enablePython ? true,
+  enableLua ? true,
+  enablePerl ? true,
+  enableMysql ? true,
+  enablePostgres ? true,
+  enableSqlite ? true,
+  enableRedis ? true,
+}:
+
+stdenv.mkDerivation rec {
+  name = "opensmtpd-extras-${version}";
+  version = "6.4.0";
+
+  src = fetchurl {
+    url = "https://www.opensmtpd.org/archives/${name}.tar.gz";
+    sha256 = "09k25l7zy5ch3fk6qphni2h0rxdp8wacmfag1whi608dgimrhrnb";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ openssl libevent
+    libasr python2 lua5 perl mysql.connector-c postgresql sqlite hiredis ];
+
+  configureFlags = [
+    "--sysconfdir=/etc"
+    "--localstatedir=/var"
+    "--with-privsep-user=smtpd"
+    "--with-libevent-dir=${libevent.dev}"
+
+    "--with-filter-clamav"
+    "--with-filter-dkim-signer"
+    "--with-filter-dnsbl"
+    "--with-filter-monkey"
+    "--with-filter-pause"
+    "--with-filter-regex"
+    "--with-filter-spamassassin"
+    "--with-filter-stub"
+    "--with-filter-trace"
+    "--with-filter-void"
+    "--with-queue-null"
+    "--with-queue-ram"
+    "--with-queue-stub"
+    "--with-table-ldap"
+    "--with-table-socketmap"
+    "--with-table-passwd"
+    "--with-table-stub"
+    "--with-scheduler-ram"
+    "--with-scheduler-stub"
+
+  ] ++ stdenv.lib.optional enablePython [
+    "--with-python=${python2}"
+    "--with-filter-python"
+    "--with-queue-python"
+    "--with-table-python"
+    "--with-scheduler-python"
+
+  ] ++ stdenv.lib.optional enableLua [
+    "--with-lua=${pkgconfig}"
+    "--with-filter-lua"
+
+  ] ++ stdenv.lib.optional enablePerl [
+    "--with-perl=${perl}"
+    "--with-filter-perl"
+
+  ] ++ stdenv.lib.optional enableMysql [
+    "--with-table-mysql"
+
+  ] ++ stdenv.lib.optional enablePostgres [
+    "--with-table-postgres"
+
+  ] ++ stdenv.lib.optional enableSqlite [
+    "--with-table-sqlite"
+
+  ] ++ stdenv.lib.optional enableRedis [
+    "--with-table-redis"
+  ];
+
+  NIX_CFLAGS_COMPILE =
+    stdenv.lib.optional enableRedis
+      "-I${hiredis}/include/hiredis -lhiredis"
+    ++ stdenv.lib.optional enableMysql
+      "-L${mysql.connector-c}/lib/mysql";
+
+  meta = with stdenv.lib; {
+    homepage = https://www.opensmtpd.org/;
+    description = "Extra plugins for the OpenSMTPD mail server";
+    license = licenses.isc;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ gebner ekleog ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/opensmtpd/fix-build.diff b/nixpkgs/pkgs/servers/mail/opensmtpd/fix-build.diff
new file mode 100644
index 000000000000..1f995fd4f623
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/opensmtpd/fix-build.diff
@@ -0,0 +1,12 @@
+diff --git a/mk/smtpctl/Makefile.am b/mk/smtpctl/Makefile.am
+index 5af0b713..f0fce735 100644
+--- a/mk/smtpctl/Makefile.am
++++ b/mk/smtpctl/Makefile.am
+@@ -4,6 +4,7 @@ sbin_PROGRAMS=          smtpctl
+ 
+ smtpctl_SOURCES=	$(smtpd_srcdir)/enqueue.c
+ smtpctl_SOURCES+=	$(smtpd_srcdir)/parser.c
++smtpctl_SOURCES+=	$(smtpd_srcdir)/config.c
+ smtpctl_SOURCES+=	$(smtpd_srcdir)/log.c
+ smtpctl_SOURCES+=	$(smtpd_srcdir)/envelope.c
+ smtpctl_SOURCES+=	$(smtpd_srcdir)/queue_backend.c
diff --git a/nixpkgs/pkgs/servers/mail/opensmtpd/proc_path.diff b/nixpkgs/pkgs/servers/mail/opensmtpd/proc_path.diff
new file mode 100644
index 000000000000..5e1cfd004299
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/opensmtpd/proc_path.diff
@@ -0,0 +1,59 @@
+diff --git a/smtpd/smtpd.c b/smtpd/smtpd.c
+index e049f07c..a1bd03a0 100644
+--- a/smtpd/smtpd.c
++++ b/smtpd/smtpd.c
+@@ -1157,6 +1157,7 @@ fork_proc_backend(const char *key, const char *conf, const char *procname)
+ 	char		path[PATH_MAX];
+ 	char		name[PATH_MAX];
+ 	char		*arg;
++	char		*proc_path;
+ 
+ 	if (strlcpy(name, conf, sizeof(name)) >= sizeof(name)) {
+ 		log_warnx("warn: %s-proc: conf too long", key);
+@@ -1167,7 +1168,12 @@ fork_proc_backend(const char *key, const char *conf, const char *procname)
+ 	if (arg)
+ 		*arg++ = '\0';
+ 
+-	if (snprintf(path, sizeof(path), PATH_LIBEXEC "/%s-%s", key, name) >=
++	proc_path = getenv("OPENSMTPD_PROC_PATH");
++	if (proc_path == NULL) {
++		proc_path = PATH_LIBEXEC;
++	}
++
++	if (snprintf(path, sizeof(path), "%s/%s-%s", proc_path, key, name) >=
+ 	    (ssize_t)sizeof(path)) {
+ 		log_warn("warn: %s-proc: exec path too long", key);
+ 		return (-1);
+diff --git a/smtpd/table.c b/smtpd/table.c
+index 9cfdfb99..24dfcca4 100644
+--- a/smtpd/table.c
++++ b/smtpd/table.c
+@@ -201,6 +201,7 @@ table_create(const char *backend, const char *name, const char *tag,
+ 	struct table_backend	*tb;
+ 	char			 buf[LINE_MAX];
+ 	char			 path[LINE_MAX];
++	const char		*proc_path;
+ 	size_t			 n;
+ 	struct stat		 sb;
+ 
+@@ -215,11 +216,16 @@ table_create(const char *backend, const char *name, const char *tag,
+ 	if (name && table_find(name, NULL))
+ 		fatalx("table_create: table \"%s\" already defined", name);
+ 
++	proc_path = getenv("OPENSMTPD_PROC_PATH");
++	if (proc_path == NULL) {
++		proc_path = PATH_LIBEXEC;
++	}
++
+ 	if ((tb = table_backend_lookup(backend)) == NULL) {
+-		if ((size_t)snprintf(path, sizeof(path), PATH_LIBEXEC"/table-%s",
+-			backend) >= sizeof(path)) {
+-			fatalx("table_create: path too long \""
+-			    PATH_LIBEXEC"/table-%s\"", backend);
++		if ((size_t)snprintf(path, sizeof(path), "%s/table-%s",
++			proc_path, backend) >= sizeof(path)) {
++			fatalx("table_create: path too long \"%s/table-%s\"",
++				proc_path, backend);
+ 		}
+ 		if (stat(path, &sb) == 0) {
+ 			tb = table_backend_lookup("proc");
diff --git a/nixpkgs/pkgs/servers/mail/petidomo/default.nix b/nixpkgs/pkgs/servers/mail/petidomo/default.nix
new file mode 100644
index 000000000000..c97d8e4ccf38
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/petidomo/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl, flex, bison, sendmailPath ? "/run/wrappers/bin/sendmail" }:
+
+stdenv.mkDerivation rec {
+  name = "petidomo-4.3";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/petidomo/${name}.tar.gz";
+    sha256 = "0x4dbxc4fcfg1rw5ywpcypvylnzn3y4rh0m6fz4h4cdnzb8p1lvm";
+  };
+
+  buildInputs = [ flex bison ];
+
+  configureFlags = [ "--with-mta=${sendmailPath}" ];
+
+  enableParallelBuilding = true;
+
+  doCheck = true;
+
+  meta = {
+    homepage = http://petidomo.sourceforge.net/;
+    description = "A simple and easy to administer mailing list server";
+    license = stdenv.lib.licenses.gpl3Plus;
+
+    platforms = stdenv.lib.platforms.unix;
+    maintainers = [ stdenv.lib.maintainers.peti ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/popa3d/default.nix b/nixpkgs/pkgs/servers/mail/popa3d/default.nix
new file mode 100644
index 000000000000..e14b62a85971
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/popa3d/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchurl,  openssl }:
+
+stdenv.mkDerivation rec {
+
+  name = "popa3d-1.0.3";
+
+  src = fetchurl {
+    url = "http://www.openwall.com/popa3d/${name}.tar.gz";
+    sha256 = "1g48cd74sqhl496wmljhq44iyfpghaz363a1ip8nyhpjz7d57f03";
+  };
+
+  buildInputs = [ openssl ];
+
+  patches = [
+    ./fix-mail-spool-path.patch
+    ./use-openssl.patch
+    ./use-glibc-crypt.patch
+    ./enable-standalone-mode.patch
+  ];
+
+  configurePhase = ''makeFlags="PREFIX=$out MANDIR=$out/share/man"'';
+
+  meta = {
+    homepage = http://www.openwall.com/popa3d/;
+    description = "Tiny POP3 daemon with security as the primary goal";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/popa3d/enable-standalone-mode.patch b/nixpkgs/pkgs/servers/mail/popa3d/enable-standalone-mode.patch
new file mode 100644
index 000000000000..763ede102f25
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/popa3d/enable-standalone-mode.patch
@@ -0,0 +1,12 @@
+diff -ubr popa3d-1.0.2-orig/params.h popa3d-1.0.2/params.h
+--- popa3d-1.0.2-orig/params.h	2012-09-19 01:19:56.698098130 +0200
++++ popa3d-1.0.2/params.h	2012-09-19 01:37:06.749130665 +0200
+@@ -13,7 +13,7 @@
+ /*
+  * Are we going to be a standalone server or start via an inetd clone?
+  */
+-#define POP_STANDALONE			0
++#define POP_STANDALONE			1
+ 
+ #if POP_STANDALONE
+ 
diff --git a/nixpkgs/pkgs/servers/mail/popa3d/fix-mail-spool-path.patch b/nixpkgs/pkgs/servers/mail/popa3d/fix-mail-spool-path.patch
new file mode 100644
index 000000000000..4f440ae59663
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/popa3d/fix-mail-spool-path.patch
@@ -0,0 +1,12 @@
+diff -ubr popa3d-1.0.2-orig/params.h popa3d-1.0.2/params.h
+--- popa3d-1.0.2-orig/params.h	2012-09-19 01:19:56.698098130 +0200
++++ popa3d-1.0.2/params.h	2012-09-19 01:21:13.748065132 +0200
+@@ -191,7 +191,7 @@
+  *
+  * #undef this for qmail-style $HOME/Mailbox mailboxes.
+  */
+-#define MAIL_SPOOL_PATH			"/var/mail"
++#define MAIL_SPOOL_PATH			"/var/spool/mail"
+ 
+ #ifndef MAIL_SPOOL_PATH
+ /*
diff --git a/nixpkgs/pkgs/servers/mail/popa3d/use-glibc-crypt.patch b/nixpkgs/pkgs/servers/mail/popa3d/use-glibc-crypt.patch
new file mode 100644
index 000000000000..35843a38bb31
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/popa3d/use-glibc-crypt.patch
@@ -0,0 +1,12 @@
+diff -ubr popa3d-1.0.2-orig/Makefile popa3d-1.0.2/Makefile
+--- popa3d-1.0.2-orig/Makefile	2012-09-19 01:19:56.698098130 +0200
++++ popa3d-1.0.2/Makefile	2012-09-19 01:24:33.871750473 +0200
+@@ -9,7 +9,7 @@
+ LDFLAGS = -s
+ LIBS =
+ # Linux with glibc, FreeBSD, NetBSD
+-#LIBS += -lcrypt
++LIBS += -lcrypt
+ # HP-UX trusted system
+ #LIBS += -lsec
+ # Solaris (POP_STANDALONE, POP_VIRTUAL)
diff --git a/nixpkgs/pkgs/servers/mail/popa3d/use-openssl.patch b/nixpkgs/pkgs/servers/mail/popa3d/use-openssl.patch
new file mode 100644
index 000000000000..54301dd873b9
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/popa3d/use-openssl.patch
@@ -0,0 +1,21 @@
+diff -ubr popa3d-1.0.2-orig/Makefile popa3d-1.0.2/Makefile
+--- popa3d-1.0.2-orig/Makefile	2012-09-19 01:19:56.698098130 +0200
++++ popa3d-1.0.2/Makefile	2012-09-19 01:23:00.309636423 +0200
+@@ -5,7 +5,7 @@
+ INSTALL = install -c
+ CFLAGS = -Wall -O2 -fomit-frame-pointer
+ # You may use OpenSSL's MD5 routines instead of the ones supplied here
+-#CFLAGS += -DHAVE_OPENSSL
++CFLAGS += -DHAVE_OPENSSL
+ LDFLAGS = -s
+ LIBS =
+ # Linux with glibc, FreeBSD, NetBSD
+@@ -21,7 +21,7 @@
+ # libwrap may also want this
+ #LIBS += -lnsl
+ # OpenSSL (-DHAVE_OPENSSL)
+-#LIBS += -lcrypto
++LIBS += -lcrypto
+ 
+ DESTDIR =
+ PREFIX = /usr/local
diff --git a/nixpkgs/pkgs/servers/mail/postfix/0001-Fix-build-with-unbound-1.6.1.patch b/nixpkgs/pkgs/servers/mail/postfix/0001-Fix-build-with-unbound-1.6.1.patch
new file mode 100644
index 000000000000..5de22573ea33
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/0001-Fix-build-with-unbound-1.6.1.patch
@@ -0,0 +1,54 @@
+From bf269dda3c81bb9eaa244b3015d426de38c85ccf Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carles=20Pag=C3=A8s?= <page@ruiec.cat>
+Date: Fri, 3 Mar 2017 09:59:09 +0100
+Subject: [PATCH] Fix build with unbound 1.6.1
+
+From their changelog: Fix to rename ub_callback_t to ub_callback_type, because POSIX reserves _t typedefs
+---
+ postlicyd/dns.c       | 2 +-
+ postlicyd/dns.h       | 2 +-
+ postlicyd/spf-proto.c | 2 +-
+ 3 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/postlicyd/dns.c b/postlicyd/dns.c
+index d8409c2..97f1c4d 100644
+--- a/postlicyd/dns.c
++++ b/postlicyd/dns.c
+@@ -123,7 +123,7 @@ static int dns_handler(client_t *event, void *config)
+ }
+ 
+ bool dns_resolve(const char *hostname, dns_rrtype_t type,
+-                 ub_callback_t callback, void *data)
++                 ub_callback_type callback, void *data)
+ {
+     if (_G.ctx == NULL) {
+         _G.ctx = ub_ctx_create();
+diff --git a/postlicyd/dns.h b/postlicyd/dns.h
+index d84de3b..905b924 100644
+--- a/postlicyd/dns.h
++++ b/postlicyd/dns.h
+@@ -89,7 +89,7 @@ typedef void (*dns_result_callback_f)(dns_result_t *result, void *data);
+  */
+ __attribute__((nonnull(1,3,4)))
+ bool dns_resolve(const char *hostname, dns_rrtype_t type,
+-                 ub_callback_t callback, void *data);
++                 ub_callback_type callback, void *data);
+ 
+ /** Fetch the DNS record of the given type.
+  */
+diff --git a/postlicyd/spf-proto.c b/postlicyd/spf-proto.c
+index 31cb0a5..79a2d83 100644
+--- a/postlicyd/spf-proto.c
++++ b/postlicyd/spf-proto.c
+@@ -279,7 +279,7 @@ static bool spf_validate_domain(const char* restrict domain)
+ }
+ 
+ static bool spf_query(spf_t *spf, const char* query, dns_rrtype_t rtype,
+-                      ub_callback_t cb)
++                      ub_callback_type cb)
+ {
+     buffer_reset(&_G.query_buffer);
+     buffer_addstr(&_G.query_buffer, query);
+-- 
+2.12.0
+
diff --git a/nixpkgs/pkgs/servers/mail/postfix/default.nix b/nixpkgs/pkgs/servers/mail/postfix/default.nix
new file mode 100644
index 000000000000..e2a78477bb63
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/default.nix
@@ -0,0 +1,98 @@
+{ stdenv, lib, fetchurl, makeWrapper, gnused, db, openssl, cyrus_sasl, libnsl
+, coreutils, findutils, gnugrep, gawk, icu, pcre, m4
+, withLDAP ? true, openldap
+, withPgSQL ? false, postgresql
+, withMySQL ? false, mysql
+, withSQLite ? false, sqlite
+}:
+
+let
+  ccargs = lib.concatStringsSep " " ([
+    "-DUSE_TLS" "-DUSE_SASL_AUTH" "-DUSE_CYRUS_SASL" "-I${cyrus_sasl.dev}/include/sasl"
+    "-DHAS_DB_BYPASS_MAKEDEFS_CHECK"
+   ] ++ lib.optional withPgSQL "-DHAS_PGSQL"
+     ++ lib.optionals withMySQL [ "-DHAS_MYSQL" "-I${mysql.connector-c}/include/mysql" "-L${mysql.connector-c}/lib/mysql" ]
+     ++ lib.optional withSQLite "-DHAS_SQLITE"
+     ++ lib.optionals withLDAP ["-DHAS_LDAP" "-DUSE_LDAP_SASL"]);
+   auxlibs = lib.concatStringsSep " " ([
+     "-ldb" "-lnsl" "-lresolv" "-lsasl2" "-lcrypto" "-lssl"
+   ] ++ lib.optional withPgSQL "-lpq"
+     ++ lib.optional withMySQL "-lmysqlclient"
+     ++ lib.optional withSQLite "-lsqlite3"
+     ++ lib.optional withLDAP "-lldap");
+
+in stdenv.mkDerivation rec {
+
+  name = "postfix-${version}";
+
+  version = "3.3.2";
+
+  src = fetchurl {
+    url = "ftp://ftp.cs.uu.nl/mirror/postfix/postfix-release/official/${name}.tar.gz";
+    sha256 = "0nxkszdgs6fs86j6w1lf3vhxvjh1hw2jmrii5icqx9a9xqgg74rw";
+  };
+
+  nativeBuildInputs = [ makeWrapper m4 ];
+  buildInputs = [ db openssl cyrus_sasl icu libnsl pcre ]
+                ++ lib.optional withPgSQL postgresql
+                ++ lib.optional withMySQL mysql.connector-c
+                ++ lib.optional withSQLite sqlite
+                ++ lib.optional withLDAP openldap;
+
+  hardeningDisable = [ "format" ];
+  hardeningEnable = [ "pie" ];
+
+  patches = [
+    ./postfix-script-shell.patch
+    ./postfix-3.0-no-warnings.patch
+    ./post-install-script.patch
+    ./relative-symlinks.patch
+  ];
+
+  preBuild = ''
+    sed -e '/^PATH=/d' -i postfix-install
+    sed -e "s|@PACKAGE@|$out|" -i conf/post-install
+
+    # post-install need skip permissions check/set on all symlinks following to /nix/store
+    sed -e "s|@NIX_STORE@|$NIX_STORE|" -i conf/post-install
+
+    export command_directory=$out/sbin
+    export config_directory=/etc/postfix
+    export meta_directory=$out/etc/postfix
+    export daemon_directory=$out/libexec/postfix
+    export data_directory=/var/lib/postfix/data
+    export html_directory=$out/share/postfix/doc/html
+    export mailq_path=$out/bin/mailq
+    export manpage_directory=$out/share/man
+    export newaliases_path=$out/bin/newaliases
+    export queue_directory=/var/lib/postfix/queue
+    export readme_directory=$out/share/postfix/doc
+    export sendmail_path=$out/bin/sendmail
+
+    make makefiles CCARGS='${ccargs}' AUXLIBS='${auxlibs}'
+  '';
+
+  installTargets = [ "non-interactive-package" ];
+
+  installFlags = [ "install_root=installdir" ];
+
+  postInstall = ''
+    mkdir -p $out
+    mv -v installdir/$out/* $out/
+    cp -rv installdir/etc $out
+    sed -e '/^PATH=/d' -i $out/libexec/postfix/post-install
+    wrapProgram $out/libexec/postfix/post-install \
+      --prefix PATH ":" ${lib.makeBinPath [ coreutils findutils gnugrep ]}
+    wrapProgram $out/libexec/postfix/postfix-script \
+      --prefix PATH ":" ${lib.makeBinPath [ coreutils findutils gnugrep gawk gnused ]}
+  '';
+
+  meta = {
+    homepage = http://www.postfix.org/;
+    description = "A fast, easy to administer, and secure mail server";
+    license = with lib.licenses; [ ipl10 epl20 ];
+    platforms = lib.platforms.linux;
+    maintainers = [ lib.maintainers.rickynils ];
+  };
+
+}
diff --git a/nixpkgs/pkgs/servers/mail/postfix/pfixtools.nix b/nixpkgs/pkgs/servers/mail/postfix/pfixtools.nix
new file mode 100644
index 000000000000..8c00bcdbee25
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/pfixtools.nix
@@ -0,0 +1,55 @@
+{ stdenv, lib, fetchFromGitHub, git, gperf, pcre, unbound, libev, tokyocabinet, pkgconfig, bash, libsrs2 }:
+
+let
+  version = "0.9";
+
+  pfixtoolsSrc = fetchFromGitHub {
+    owner = "Fruneau";
+    repo = "pfixtools";
+    rev = "pfixtools-${version}";
+    sha256 = "1vmbrw686f41n6xfjphfshn96vl07ynvnsyjdw9yfn9bfnldcjcq";
+  };
+
+  srcRoot = pfixtoolsSrc.name;
+
+  libCommonSrc = fetchFromGitHub {
+    owner = "Fruneau";
+    repo = "libcommon";
+    rev = "b07e6bdea3d24748e0d39783d7d817096d10cc67";
+    sha256 = "14fxldp29j4vmfmhfgwwi37pj8cz0flm1aykkxlbgakz92d4pm35";
+  };
+
+in
+
+stdenv.mkDerivation {
+  name = "pfixtools-${version}";
+
+  src = pfixtoolsSrc;
+
+  patches = [ ./0001-Fix-build-with-unbound-1.6.1.patch ];
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [git gperf pcre unbound libev tokyocabinet bash libsrs2];
+
+  postUnpack = ''
+    cp -Rp ${libCommonSrc}/* ${srcRoot}/common;
+    chmod -R +w ${srcRoot}/common;
+  '';
+
+  postPatch = ''
+    substituteInPlace postlicyd/policy_tokens.sh \
+                      --replace /bin/bash ${bash}/bin/bash;
+  '';
+
+  NIX_CFLAGS_COMPILE = "-Wno-error=unused-result -Wno-error=nonnull-compare";
+
+  makeFlags = "DESTDIR=$(out) prefix=";
+
+  meta = {
+    description = "A collection of postfix-related tools";
+    license = with lib.licenses; [ bsd3 ];
+    homepage = https://github.com/Fruneau/pfixtools;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with lib.maintainers; [ jerith666 ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/postfix/pflogsumm.nix b/nixpkgs/pkgs/servers/mail/postfix/pflogsumm.nix
new file mode 100644
index 000000000000..821999380606
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/pflogsumm.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchurl, perlPackages }:
+
+perlPackages.buildPerlPackage rec {
+  name = "pflogsumm-${version}";
+  version = "1.1.3";
+
+  src = fetchurl {
+    url = "https://jimsun.linxnet.com/downloads/${name}.tar.gz";
+    sha256 = "0hkim9s5f1yg5sfs5048jydhy3sbxafls496wcjk0cggxb113py4";
+  };
+
+  outputs = [ "out" "man" ];
+  buildInputs = [ perlPackages.DateCalc ];
+
+  preConfigure = ''
+    touch Makefile.PL
+  '';
+  doCheck = false;
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    mv "pflogsumm.pl" "$out/bin/pflogsumm"
+
+    mkdir -p "$out/share/man/man1"
+    mv "pflogsumm.1" "$out/share/man/man1"
+  '';
+
+  meta = {
+    homepage = http://jimsun.linxnet.com/postfix_contrib.html;
+    maintainers = with stdenv.lib.maintainers; [ schneefux ];
+    description = "Postfix activity overview";
+    license = stdenv.lib.licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/postfix/post-install-script.patch b/nixpkgs/pkgs/servers/mail/postfix/post-install-script.patch
new file mode 100644
index 000000000000..350fbf929b74
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/post-install-script.patch
@@ -0,0 +1,28 @@
+--- a/conf/post-install	1970-01-01 03:00:01.000000000 +0300
++++ b/conf/post-install	2016-01-20 13:25:18.382233172 +0200
+@@ -254,6 +254,8 @@
+ }
+ 
+ # Bootstrapping problem.
++meta_directory="@PACKAGE@/etc/postfix"
++command_directory="@PACKAGE@/bin"
+ 
+ if [ -n "$command_directory" ]
+ then
+@@ -528,7 +530,16 @@
+ 	    # Skip uninstalled files.
+ 	    case $path in
+ 	    no|no/*) continue;;
++        # Skip immutable files from package, correct permissions provided by Nix.
++        @PACKAGE@/*) continue;
+ 	    esac
++        # Also skip symlinks following to /nix/store
++        if test -L $path; then
++            case "$(readlink $path)" in
++                @NIX_STORE@/*) continue;
++            esac
++        fi
++
+ 	    # Pick up the flags.
+ 	    case $flags in *u*) upgrade_flag=1;; *) upgrade_flag=;; esac
+ 	    case $flags in *c*) create_flag=1;; *) create_flag=;; esac
diff --git a/nixpkgs/pkgs/servers/mail/postfix/postfix-3.0-no-warnings.patch b/nixpkgs/pkgs/servers/mail/postfix/postfix-3.0-no-warnings.patch
new file mode 100644
index 000000000000..d93eaf0aaa0d
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/postfix-3.0-no-warnings.patch
@@ -0,0 +1,86 @@
+diff -ru3 postfix-3.0.3/conf/postfix-script postfix-3.0.3-new/conf/postfix-script
+--- postfix-3.0.3/conf/postfix-script	2014-06-27 18:05:15.000000000 +0400
++++ postfix-3.0.3-new/conf/postfix-script	2016-01-09 17:51:38.545733631 +0300
+@@ -84,24 +84,6 @@
+ 	exit 1
+ }
+ 
+-# If this is a secondary instance, don't touch shared files.
+-
+-instances=`test ! -f $def_config_directory/main.cf ||
+-    $command_directory/postconf -c $def_config_directory \
+-    -h multi_instance_directories | sed 's/,/ /'` || {
+-	$FATAL cannot execute $command_directory/postconf!
+-	exit 1
+-}
+-
+-check_shared_files=1
+-for name in $instances
+-do
+-    case "$name" in
+-    "$def_config_directory") ;;
+-    "$config_directory") check_shared_files=; break;;
+-    esac
+-done
+-
+ #
+ # Parse JCL
+ #
+@@ -262,22 +244,6 @@
+ 	    -prune \( -perm -020 -o -perm -002 \) \
+ 	    -exec $WARN group or other writable: {} \;
+ 
+-	# Check Postfix root-owned directory tree owner/permissions.
+-
+-	todo="$config_directory/."
+-	test -n "$check_shared_files" && {
+-		todo="$daemon_directory/. $meta_directory/. $todo"
+-		test "$shlib_directory" = "no" || 
+-		    todo="$shlib_directory/. $todo"
+-	}
+-	todo=`echo "$todo" | tr ' ' '\12' | sort -u`
+-
+-	find $todo ! -user root \
+-	    -exec $WARN not owned by root: {} \;
+-
+-	find $todo \( -perm -020 -o -perm -002 \) \
+-	    -exec $WARN group or other writable: {} \;
+-
+ 	# Check Postfix mail_owner-owned directory tree owner/permissions.
+ 
+ 	find $data_directory/. ! -user $mail_owner \
+@@ -302,18 +268,11 @@
+ 	# Check Postfix setgid_group-owned directory and file group/permissions.
+ 
+ 	todo="$queue_directory/public $queue_directory/maildrop"
+-	test -n "$check_shared_files" && 
+-	   todo="$command_directory/postqueue $command_directory/postdrop $todo"
+ 
+ 	find $todo \
+ 	    -prune ! -group $setgid_group \
+ 	    -exec $WARN not owned by group $setgid_group: {} \;
+ 
+-	test -n "$check_shared_files" &&
+-	find $command_directory/postqueue $command_directory/postdrop \
+-	    -prune ! -perm -02111 \
+-	    -exec $WARN not set-gid or not owner+group+world executable: {} \;
+-
+ 	# Check non-Postfix root-owned directory tree owner/content.
+ 
+ 	for dir in bin etc lib sbin usr
+@@ -334,15 +293,6 @@
+ 
+ 	find corrupt -type f -exec $WARN damaged message: {} \;
+ 
+-	# Check for non-Postfix MTA remnants.
+-
+-	test -n "$check_shared_files" -a -f /usr/sbin/sendmail -a \
+-		-f /usr/lib/sendmail && {
+-	    cmp -s /usr/sbin/sendmail /usr/lib/sendmail || {
+-		$WARN /usr/lib/sendmail and /usr/sbin/sendmail differ
+-		$WARN Replace one by a symbolic link to the other
+-	    }
+-	}
+ 	exit 0
+ 	;;
+ 
diff --git a/nixpkgs/pkgs/servers/mail/postfix/postfix-script-shell.patch b/nixpkgs/pkgs/servers/mail/postfix/postfix-script-shell.patch
new file mode 100644
index 000000000000..4f5d2f611110
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/postfix-script-shell.patch
@@ -0,0 +1,21 @@
+diff --git a/conf/postfix-script b/conf/postfix-script
+index 19088a6..04fae23 100755
+--- a/conf/postfix-script
++++ b/conf/postfix-script
+@@ -43,7 +43,6 @@ FATAL="$LOGGER -p fatal"
+ PANIC="$LOGGER -p panic"
+ 
+ umask 022
+-SHELL=/bin/sh
+ 
+ #
+ # Can't do much without these in place.
+@@ -229,7 +228,7 @@ status)
+ check-fatal)
+ 	# This command is NOT part of the public interface.
+ 
+-	$SHELL $daemon_directory/post-install create-missing || {
++	$daemon_directory/post-install create-missing || {
+ 		$FATAL unable to create missing queue directories
+ 		exit 1
+ 	}
diff --git a/nixpkgs/pkgs/servers/mail/postfix/relative-symlinks.patch b/nixpkgs/pkgs/servers/mail/postfix/relative-symlinks.patch
new file mode 100644
index 000000000000..f7a2078c0343
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postfix/relative-symlinks.patch
@@ -0,0 +1,13 @@
+diff --git a/postfix-install b/postfix/postfix-install
+index 1662c3d..0f20ec0 100644
+--- a/postfix-install
++++ b/postfix-install
+@@ -336,7 +336,7 @@ compare_or_symlink() {
+ 	# 2) we cannot use mv to replace a symlink-to-directory;
+ 	# 3) "ln -n" is not in POSIX, therefore it's not portable.
+ 	# rm+ln is less atomic but this affects compatibility symlinks only.
+-	rm -f $2 && ln -sf $link $2 || exit 1
++	rm -f $2 && ln -rsf $link $2 || exit 1
+     }
+ }
+ 
diff --git a/nixpkgs/pkgs/servers/mail/postgrey/default.nix b/nixpkgs/pkgs/servers/mail/postgrey/default.nix
new file mode 100644
index 000000000000..3e7163cb1541
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postgrey/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchurl, perl, perlPackages, lib, runCommand, postfix }:
+
+let
+    mk-perl-flags = inputs: lib.concatStringsSep " " (map (dep: "-I ${dep}/lib/perl5/site_perl") inputs);
+    postgrey-flags = mk-perl-flags (with perlPackages; [
+      NetServer BerkeleyDB DigestSHA1 NetAddrIP IOMultiplex
+    ]);
+    policy-test-flags = mk-perl-flags (with perlPackages; [
+      ParseSyslog
+    ]);
+    version = "1.37";
+    name = "postgrey-${version}";
+in runCommand name {
+  src = fetchurl {
+    url = "https://postgrey.schweikert.ch/pub/${name}.tar.gz";
+    sha256 = "1xx51xih4711vrvc6d57il9ccallbljj5zhgqdb07jzmz11rakgz";
+  };
+  meta = with stdenv.lib; {
+    description = "A postfix policy server to provide greylisting";
+    homepage = https://postgrey.schweikert.ch/;
+    platforms = postfix.meta.platforms;
+    license = licenses.gpl2;
+  };
+} ''
+    mkdir -p $out/bin
+    cd $out
+    tar -xzf $src --strip-components=1
+    mv postgrey policy-test bin
+    sed -i -e "s,#!/usr/bin/perl -T,#!${perl}/bin/perl -T ${postgrey-flags}," \
+           -e "s#/etc/postfix#$out#" \
+        bin/postgrey
+    sed -i -e "s,#!/usr/bin/perl,#!${perl}/bin/perl ${policy-test-flags}," \
+        bin/policy-test
+''
diff --git a/nixpkgs/pkgs/servers/mail/postsrsd/default.nix b/nixpkgs/pkgs/servers/mail/postsrsd/default.nix
new file mode 100644
index 000000000000..01eeeb15efaf
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/postsrsd/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub, cmake, help2man }:
+
+stdenv.mkDerivation rec {
+  name = "postsrsd-${version}";
+  version = "1.4";
+
+  src = fetchFromGitHub {
+    owner = "roehling";
+    repo = "postsrsd";
+    rev = version;
+    sha256 = "09yzb0fvnbfy534maqlqk79c41p1yz8r9f73n7bahm5lwd0livk9";
+  };
+
+  cmakeFlags = [ "-DGENERATE_SRS_SECRET=OFF" "-DINIT_FLAVOR=systemd" ];
+
+  preConfigure = ''
+    sed -i "s,\"/etc\",\"$out/etc\",g" CMakeLists.txt
+  '';
+
+  nativeBuildInputs = [ cmake help2man ];
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/roehling/postsrsd;
+    description = "Postfix Sender Rewriting Scheme daemon";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/pypolicyd-spf/default.nix b/nixpkgs/pkgs/servers/mail/pypolicyd-spf/default.nix
new file mode 100644
index 000000000000..d5e410a86c1f
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/pypolicyd-spf/default.nix
@@ -0,0 +1,26 @@
+{ lib, buildPythonApplication, fetchurl, pyspf }:
+
+buildPythonApplication rec {
+  name = "pypolicyd-spf-${version}";
+  majorVersion = "2.0";
+  version = "${majorVersion}.2";
+
+  src = fetchurl {
+    url = "https://launchpad.net/pypolicyd-spf/${majorVersion}/${version}/+download/${name}.tar.gz";
+    sha256 = "1nm8y1jjgx6mxrbcxrbdnmkf8vglwp0wiw6jipzh641wb24gi76z";
+  };
+
+  propagatedBuildInputs = [ pyspf ];
+
+  preBuild = ''
+    substituteInPlace setup.py --replace "'/etc'" "'$out/etc'"
+  '';
+
+  meta = with lib; {
+    homepage = https://launchpad.net/pypolicyd-spf/;
+    description = "Postfix policy engine for Sender Policy Framework (SPF) checking";
+    maintainers = with maintainers; [ abbradar ];
+    license = licenses.asl20;
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/rmilter/default.nix b/nixpkgs/pkgs/servers/mail/rmilter/default.nix
new file mode 100644
index 000000000000..739270326e5b
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/rmilter/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchFromGitHub, cmake, bison, flex, pkgconfig, openssl, pcre
+, libmilter, opendkim, libmemcached, glib }:
+
+let patchedLibmilter = stdenv.lib.overrideDerivation  libmilter (_ : {
+    patches = libmilter.patches ++ [ ./fd-passing-libmilter.patch ];
+});
+in
+
+stdenv.mkDerivation rec {
+  name = "rmilter-${version}";
+  version = "1.10.0";
+
+  src = fetchFromGitHub {
+    owner = "vstakhov";
+    repo = "rmilter";
+    rev = version;
+    sha256 = "1gbp6jah88l6xqgflim01ycyp63l733bgir65fxnnrmifj1qzymh";
+  };
+
+  nativeBuildInputs = [ bison cmake flex pkgconfig ];
+  buildInputs = [ libmemcached patchedLibmilter openssl pcre opendkim glib ];
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/vstakhov/rmilter;
+    license = licenses.asl20;
+    description = ''
+      Daemon to integrate rspamd and milter compatible MTA, for example
+      postfix or sendmail
+    '';
+    maintainers = with maintainers; [ avnik fpletz ];
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/rmilter/fd-passing-libmilter.patch b/nixpkgs/pkgs/servers/mail/rmilter/fd-passing-libmilter.patch
new file mode 100644
index 000000000000..3ab61a6fab00
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/rmilter/fd-passing-libmilter.patch
@@ -0,0 +1,80 @@
+Description: systemd-like socket activation support for libmilter
+Author: Mikhail Gusarov <dottedmag@debian.org
+diff --git a/libmilter/docs/smfi_setconn.html b/libmilter/docs/smfi_setconn.html
+index 70a510e..013f04e 100644
+--- a/libmilter/docs/smfi_setconn.html
++++ b/libmilter/docs/smfi_setconn.html
+@@ -43,6 +43,7 @@ Set the socket through which this filter should communicate with sendmail.
+ 	<LI><CODE>{unix|local}:/path/to/file</CODE> -- A named pipe.
+ 	<LI><CODE>inet:port@{hostname|ip-address}</CODE> -- An IPV4 socket.
+ 	<LI><CODE>inet6:port@{hostname|ip-address}</CODE> -- An IPV6 socket.
++	<LI><CODE>fd:number</CODE> -- Pre-opened file descriptor.
+ 	</UL>
+ 	</TD></TR>
+     </TABLE>
+diff --git a/libmilter/listener.c b/libmilter/listener.c
+index 48c552f..2249a1f 100644
+--- a/libmilter/listener.c
++++ b/libmilter/listener.c
+@@ -197,6 +197,11 @@ mi_milteropen(conn, backlog, rmsocket, name)
+ 			L_socksize = sizeof addr.sin6;
+ 		}
+ #endif /* NETINET6 */
++		else if (strcasecmp(p, "fd") == 0)
++		{
++			addr.sa.sa_family = AF_UNSPEC;
++			L_socksize = sizeof (_SOCK_ADDR);
++		}
+ 		else
+ 		{
+ 			smi_log(SMI_LOG_ERR, "%s: unknown socket type %s",
+@@ -443,7 +448,21 @@ mi_milteropen(conn, backlog, rmsocket, name)
+ 	}
+ #endif /* NETINET || NETINET6 */
+ 
+-	sock = socket(addr.sa.sa_family, SOCK_STREAM, 0);
++	if (addr.sa.sa_family == AF_UNSPEC)
++	{
++		char *end;
++		sock = strtol(colon, &end, 10);
++		if (*end != '\0' || sock < 0)
++		{
++			smi_log(SMI_LOG_ERR, "%s: expected positive integer as fd, got %s", name, colon);
++			return INVALID_SOCKET;
++		}
++	}
++	else
++	{
++		sock = socket(addr.sa.sa_family, SOCK_STREAM, 0);
++	}
++
+ 	if (!ValidSocket(sock))
+ 	{
+ 		smi_log(SMI_LOG_ERR,
+@@ -466,6 +485,7 @@ mi_milteropen(conn, backlog, rmsocket, name)
+ #if NETUNIX
+ 	    addr.sa.sa_family != AF_UNIX &&
+ #endif /* NETUNIX */
++	    addr.sa.sa_family != AF_UNSPEC &&
+ 	    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &sockopt,
+ 		       sizeof(sockopt)) == -1)
+ 	{
+@@ -511,7 +531,8 @@ mi_milteropen(conn, backlog, rmsocket, name)
+ 	}
+ #endif /* NETUNIX */
+ 
+-	if (bind(sock, &addr.sa, L_socksize) < 0)
++	if (addr.sa.sa_family != AF_UNSPEC &&
++	    bind(sock, &addr.sa, L_socksize) < 0)
+ 	{
+ 		smi_log(SMI_LOG_ERR,
+ 			"%s: Unable to bind to port %s: %s",
+@@ -817,7 +838,7 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
+ # ifdef BSD4_4_SOCKADDR
+ 		     cliaddr.sa.sa_len == 0 ||
+ # endif /* BSD4_4_SOCKADDR */
+-		     cliaddr.sa.sa_family != L_family))
++		     (L_family != AF_UNSPEC && cliaddr.sa.sa_family != L_family)))
+ 		{
+ 			(void) closesocket(connfd);
+ 			connfd = INVALID_SOCKET;
diff --git a/nixpkgs/pkgs/servers/mail/rspamd/default.nix b/nixpkgs/pkgs/servers/mail/rspamd/default.nix
new file mode 100644
index 000000000000..fda7a1a80ef7
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/rspamd/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, lib, fetchFromGitHub, cmake, perl
+, file, glib, libevent, luajit, openssl, pcre, pkgconfig, sqlite, ragel, icu
+, hyperscan, libfann, gd, jemalloc, openblas
+, withFann ? true
+, withGd ? false
+, withBlas ? true
+, withHyperscan ? stdenv.isx86_64
+}:
+
+assert withHyperscan -> stdenv.isx86_64;
+
+let libmagic = file;  # libmagic provided by file package ATM
+in
+
+stdenv.mkDerivation rec {
+  name = "rspamd-${version}";
+  version = "1.8.3";
+
+  src = fetchFromGitHub {
+    owner = "rspamd";
+    repo = "rspamd";
+    rev = version;
+    sha256 = "1aikmscb3hywac4sf4xkl4kw0x3syzphfrmxhigz2jjqzxn8f50k";
+  };
+
+  nativeBuildInputs = [ cmake pkgconfig perl ];
+  buildInputs = [ glib libevent libmagic luajit openssl pcre sqlite ragel icu jemalloc ]
+    ++ lib.optional withFann libfann
+    ++ lib.optional withGd gd
+    ++ lib.optional withHyperscan hyperscan
+    ++ lib.optional withBlas openblas;
+
+  cmakeFlags = [
+    "-DDEBIAN_BUILD=ON"
+    "-DRUNDIR=/var/run/rspamd"
+    "-DDBDIR=/var/lib/rspamd"
+    "-DLOGDIR=/var/log/rspamd"
+    "-DLOCAL_CONFDIR=/etc/rspamd"
+    "-DENABLE_JEMALLOC=ON"
+  ] ++ lib.optional withFann "-DENABLE_FANN=ON"
+    ++ lib.optional withHyperscan "-DENABLE_HYPERSCAN=ON"
+    ++ lib.optional withGd "-DENABLE_GD=ON";
+
+  meta = with stdenv.lib; {
+    homepage = https://rspamd.com;
+    license = licenses.asl20;
+    description = "Advanced spam filtering system";
+    maintainers = with maintainers; [ avnik fpletz ];
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/spamassassin/default.nix b/nixpkgs/pkgs/servers/mail/spamassassin/default.nix
new file mode 100644
index 000000000000..d32957210132
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/spamassassin/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchurl, perl, perlPackages, HTMLParser, NetDNS, NetAddrIP, DBFile
+, HTTPDate, MailDKIM, LWP, IOSocketSSL, makeWrapper, gnupg1
+}:
+
+perlPackages.buildPerlPackage rec {
+  name = "SpamAssassin-3.4.1";
+
+  src = fetchurl {
+    url = "mirror://apache/spamassassin/source/Mail-${name}.tar.bz2";
+    sha256 = "0la6s5ilamf9129kyjckcma8cr6fpb6b5f2fb64v7106iy0ckhd0";
+  };
+
+  # https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7434
+  patches = [ ./sa-update_add--siteconfigpath.patch ];
+
+  buildInputs = with perlPackages; [ makeWrapper HTMLParser NetDNS NetAddrIP DBFile HTTPDate MailDKIM
+    LWP IOSocketSSL DBI EncodeDetect IPCountry NetIdent Razor2ClientAgent MailSPF NetDNSResolverProgrammable ];
+
+  # Enabling 'taint' mode is desirable, but that flag disables support
+  # for the PERL5LIB environment variable. Needs further investigation.
+  makeFlags = "PERL_BIN=${perl}/bin/perl PERL_TAINT=no";
+
+  makeMakerFlags = "CONFDIR=/homeless/shelter LOCALSTATEDIR=/var/lib/spamassassin";
+
+  doCheck = false;
+
+  postInstall = ''
+    mkdir -p $out/share/spamassassin
+    mv "rules/"* $out/share/spamassassin/
+
+    for n in "$out/bin/"*; do
+      wrapProgram "$n" --prefix PERL5LIB : "$PERL5LIB" --prefix PATH : "${gnupg1}/bin"
+    done
+  '';
+
+  meta = {
+    homepage = http://spamassassin.apache.org/;
+    description = "Open-Source Spam Filter";
+    license = stdenv.lib.licenses.asl20;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ peti qknight ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/mail/spamassassin/sa-update_add--siteconfigpath.patch b/nixpkgs/pkgs/servers/mail/spamassassin/sa-update_add--siteconfigpath.patch
new file mode 100644
index 000000000000..3264aefc0722
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/spamassassin/sa-update_add--siteconfigpath.patch
@@ -0,0 +1,59 @@
+From 60abf3ee8864980a95b32e2d6cf60e26b49654c0 Mon Sep 17 00:00:00 2001
+From: joachim schiele <js@lastlog.de>
+Date: Wed, 7 Jun 2017 22:15:39 +0200
+Subject: [PATCH 2/2] Adding --siteconfigpath to not be forced to use global /etc/spamasassin configuration directory but to provide an alternative location.
+
+---
+ sa-update.raw | 5 +++++
+ lib/Mail/SpamAssassin/PerMsgStatus.pm | 2 +
+ 2 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/sa-update.raw b/sa-update.raw
+index bb7396d..39f681f 100755
+--- a/sa-update.raw
++++ b/sa-update.raw
+@@ -196,6 +196,7 @@ GetOptions(
+   'gpgkeyfile=s'			=> \$opt{'gpgkeyfile'},
+   'channelfile=s'			=> \$opt{'channelfile'},
+   'updatedir=s'				=> \$opt{'updatedir'},
++  'siteconfigpath=s'                           => \$opt{'siteconfigpath'},
+   'gpg!'				=> \$GPG_ENABLED,
+ 
+   '4'                                   => sub { $opt{'force_pf'} = 'inet' },
+@@ -267,6 +268,9 @@ else {
+   $opt{'updatedir'} = $SA->sed_path('__local_state_dir__/__version__');
+ }
+ 
++if (defined $opt{'siteconfigpath'}) {
++  $LOCAL_RULES_DIR = untaint_file_path($opt{'siteconfigpath'});
++}
+ 
+ # check only disabled gpg
+ # https://issues.apache.org/SpamAssassin/show_bug.cgi?id=5854
+@@ -1808,6 +1812,7 @@ Options:
+   --updatedir path        Directory to place updates, defaults to the
+                           SpamAssassin site rules directory
+                           (default: @@LOCAL_STATE_DIR@@/@@VERSION@@)
++  --siteconfigpath=path   Path for site configs
+   --refreshmirrors        Force the MIRRORED.BY file to be updated
+   -D, --debug [area=n,...]  Print debugging messages
+   -v, --verbose           Be verbose, like print updated channel names;
+-- 
+diff --git a/lib/Mail/SpamAssassin/PerMsgStatus.pm b/lib/Mail/SpamAssassin/PerMsgStatus.pm
+index 6d8beaa..6ad87dc 100644
+--- a/lib/Mail/SpamAssassin/PerMsgStatus.pm
++++ b/lib/Mail/SpamAssassin/PerMsgStatus.pm
+@@ -389,7 +389,8 @@ sub check_timed {
+     if (!$self->{main}->have_plugin("check_main")) {
+       die "check: no loaded plugin implements 'check_main': cannot scan!\n".
+             "Check that the necessary '.pre' files are in the config directory.\n".
+-              "At a minimum, v320.pre loads the Check plugin which is required.\n";
++              "At a minimum, v320.pre loads the Check plugin which is required.\n".
++              "NixOS: Since there is no '/etc/spamassassin' simply restart 'spamd.service' which on its behalf will run 'sa-learn --siteconfigpath=/nix/store/l4hr4yxk8mb4wbkha6vm6rh92pj19rj6-spamd-env ...' to update the /var/lib/spamassassin configs.\n";
+     }
+   }
+ 
+-- 
+
+2.12.2
+
diff --git a/nixpkgs/pkgs/servers/mail/system-sendmail/default.nix b/nixpkgs/pkgs/servers/mail/system-sendmail/default.nix
new file mode 100644
index 000000000000..0e290f135181
--- /dev/null
+++ b/nixpkgs/pkgs/servers/mail/system-sendmail/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, writeText }:
+
+let script = writeText "script" ''
+  #!/bin/sh
+
+  if command -v sendmail > /dev/null 2>&1 && [ "$(command -v sendmail)" != "{{MYPATH}}" ]; then
+    exec sendmail "$@"
+  elif [ -x /run/wrappers/bin/sendmail ]; then
+    exec /run/wrappers/bin/sendmail "$@"
+  elif [ -x /run/current-system/sw/bin/sendmail ]; then
+    exec /run/current-system/sw/bin/sendmail "$@"
+  else
+    echo "Unable to find system sendmail." >&2
+    exit 1
+  fi
+''; in
+stdenv.mkDerivation {
+  name = "system-sendmail-1.0";
+
+  src = script;
+
+  phases = [ "buildPhase" ];
+  buildPhase = ''
+    mkdir -p $out/bin
+    < $src sed "s#{{MYPATH}}#$out/bin/sendmail#" > $out/bin/sendmail
+    chmod +x $out/bin/sendmail
+  '';
+
+  meta = with stdenv.lib; {
+    description = ''
+      A sendmail wrapper that calls the system sendmail. Do not install as system-wide sendmail!
+    '';
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ ekleog ];
+  };
+}