From 7a34f221883bc6f5f38b2ed40ce9754941bc99df Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Fri, 19 Mar 2021 14:26:15 -0700 Subject: [PATCH] adding mail server configs --- etc/dovecot/conf.d/10-auth.conf | 128 +++ etc/dovecot/conf.d/10-mail.conf | 420 ++++++++++ etc/dovecot/conf.d/10-master.conf | 136 +++ etc/dovecot/conf.d/10-ssl.conf | 82 ++ etc/dovecot/conf.d/15-mailboxes.conf | 88 ++ etc/dovecot/conf.d/20-imap.conf | 98 +++ etc/dovecot/conf.d/90-quota.conf | 94 +++ etc/dovecot/conf.d/auth-sql.conf.ext | 30 + etc/dovecot/dovecot-sql.conf.ext | 146 ++++ etc/exim4/autowhitelist.filter | 22 + etc/exim4/exim4.conf | 1135 ++++++++++++++++++++++++++ etc/exim4/exim_local.conf | 16 + etc/exim4/return-resender.sh | 19 + etc/exim4/skip_greylisting_hosts | 1 + etc/spamassassin/local.cf | 112 +++ etc/spamassassin/sql.cf | 4 + 16 files changed, 2531 insertions(+) create mode 100644 etc/dovecot/conf.d/10-auth.conf create mode 100644 etc/dovecot/conf.d/10-mail.conf create mode 100644 etc/dovecot/conf.d/10-master.conf create mode 100644 etc/dovecot/conf.d/10-ssl.conf create mode 100644 etc/dovecot/conf.d/15-mailboxes.conf create mode 100644 etc/dovecot/conf.d/20-imap.conf create mode 100644 etc/dovecot/conf.d/90-quota.conf create mode 100644 etc/dovecot/conf.d/auth-sql.conf.ext create mode 100644 etc/dovecot/dovecot-sql.conf.ext create mode 100644 etc/exim4/autowhitelist.filter create mode 100644 etc/exim4/exim4.conf create mode 100644 etc/exim4/exim_local.conf create mode 100644 etc/exim4/return-resender.sh create mode 100644 etc/exim4/skip_greylisting_hosts create mode 100644 etc/spamassassin/local.cf create mode 100644 etc/spamassassin/sql.cf diff --git a/etc/dovecot/conf.d/10-auth.conf b/etc/dovecot/conf.d/10-auth.conf new file mode 100644 index 0000000..9d4f062 --- /dev/null +++ b/etc/dovecot/conf.d/10-auth.conf @@ -0,0 +1,128 @@ +## +## Authentication processes +## + +# Disable LOGIN command and all other plaintext authentications unless +# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP +# matches the local IP (ie. you're connecting from the same computer), the +# connection is considered secure and plaintext authentication is allowed. +# See also ssl=required setting. +disable_plaintext_auth = yes + +# Authentication cache size (e.g. 10M). 0 means it's disabled. Note that +# bsdauth, PAM and vpopmail require cache_key to be set for caching to be used. +#auth_cache_size = 0 +# Time to live for cached data. After TTL expires the cached record is no +# longer used, *except* if the main database lookup returns internal failure. +# We also try to handle password changes automatically: If user's previous +# authentication was successful, but this one wasn't, the cache isn't used. +# For now this works only with plaintext authentication. +#auth_cache_ttl = 1 hour +# TTL for negative hits (user not found, password mismatch). +# 0 disables caching them completely. +#auth_cache_negative_ttl = 1 hour + +# Space separated list of realms for SASL authentication mechanisms that need +# them. You can leave it empty if you don't want to support multiple realms. +# Many clients simply use the first one listed here, so keep the default realm +# first. +#auth_realms = + +# Default realm/domain to use if none was specified. This is used for both +# SASL realms and appending @domain to username in plaintext logins. +#auth_default_realm = + +# List of allowed characters in username. If the user-given username contains +# a character not listed in here, the login automatically fails. This is just +# an extra check to make sure user can't exploit any potential quote escaping +# vulnerabilities with SQL/LDAP databases. If you want to allow all characters, +# set this value to empty. +#auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@ + +# Username character translations before it's looked up from databases. The +# value contains series of from -> to characters. For example "#@/@" means +# that '#' and '/' characters are translated to '@'. +#auth_username_translation = + +# Username formatting before it's looked up from databases. You can use +# the standard variables here, eg. %Lu would lowercase the username, %n would +# drop away the domain if it was given, or "%n-AT-%d" would change the '@' into +# "-AT-". This translation is done after auth_username_translation changes. +#auth_username_format = %Lu + +# If you want to allow master users to log in by specifying the master +# username within the normal username string (ie. not using SASL mechanism's +# support for it), you can specify the separator character here. The format +# is then . UW-IMAP uses "*" as the +# separator, so that could be a good choice. +#auth_master_user_separator = + +# Username to use for users logging in with ANONYMOUS SASL mechanism +#auth_anonymous_username = anonymous + +# Maximum number of dovecot-auth worker processes. They're used to execute +# blocking passdb and userdb queries (eg. MySQL and PAM). They're +# automatically created and destroyed as needed. +#auth_worker_max_count = 30 + +# Host name to use in GSSAPI principal names. The default is to use the +# name returned by gethostname(). Use "$ALL" (with quotes) to allow all keytab +# entries. +#auth_gssapi_hostname = + +# Kerberos keytab to use for the GSSAPI mechanism. Will use the system +# default (usually /etc/krb5.keytab) if not specified. You may need to change +# the auth service to run as root to be able to read this file. +#auth_krb5_keytab = + +# Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon and +# ntlm_auth helper. +#auth_use_winbind = no + +# Path for Samba's ntlm_auth helper binary. +#auth_winbind_helper_path = /usr/bin/ntlm_auth + +# Time to delay before replying to failed authentications. +#auth_failure_delay = 2 secs + +# Require a valid SSL client certificate or the authentication fails. +#auth_ssl_require_client_cert = no + +# Take the username from client's SSL certificate, using +# X509_NAME_get_text_by_NID() which returns the subject's DN's +# CommonName. +#auth_ssl_username_from_cert = no + +# Space separated list of wanted authentication mechanisms: +# plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey +# gss-spnego +# NOTE: See also disable_plaintext_auth setting. +auth_mechanisms = plain login + +## +## Password and user databases +## + +# +# Password database is used to verify user's password (and nothing more). +# You can have multiple passdbs and userdbs. This is useful if you want to +# allow both system users (/etc/passwd) and virtual users to login without +# duplicating the system users into virtual database. +# +# +# +# User database specifies where mails are located and what user/group IDs +# own them. For single-UID configuration use "static" userdb. +# +# + +#!include auth-deny.conf.ext +#!include auth-master.conf.ext + +#!include auth-system.conf.ext +!include auth-sql.conf.ext +#!include auth-ldap.conf.ext +#!include auth-passwdfile.conf.ext +#!include auth-checkpassword.conf.ext +#!include auth-vpopmail.conf.ext +#!include auth-static.conf.ext diff --git a/etc/dovecot/conf.d/10-mail.conf b/etc/dovecot/conf.d/10-mail.conf new file mode 100644 index 0000000..0327b36 --- /dev/null +++ b/etc/dovecot/conf.d/10-mail.conf @@ -0,0 +1,420 @@ +## +## Mailbox locations and namespaces +## + +# Location for users' mailboxes. The default is empty, which means that Dovecot +# tries to find the mailboxes automatically. This won't work if the user +# doesn't yet have any mail, so you should explicitly tell Dovecot the full +# location. +# +# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u) +# isn't enough. You'll also need to tell Dovecot where the other mailboxes are +# kept. This is called the "root mail directory", and it must be the first +# path given in the mail_location setting. +# +# There are a few special variables you can use, eg.: +# +# %u - username +# %n - user part in user@domain, same as %u if there's no domain +# %d - domain part in user@domain, empty if there's no domain +# %h - home directory +# +# See doc/wiki/Variables.txt for full list. Some examples: +# +# mail_location = maildir:~/Maildir +# mail_location = mbox:~/mail:INBOX=/var/mail/%u +# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n +# +# +# +mail_location = maildir:/var/vmail/%d/%n/Maildir + +# If you need to set multiple mailbox locations or want to change default +# namespace settings, you can do it by defining namespace sections. +# +# You can have private, shared and public namespaces. Private namespaces +# are for user's personal mails. Shared namespaces are for accessing other +# users' mailboxes that have been shared. Public namespaces are for shared +# mailboxes that are managed by sysadmin. If you create any shared or public +# namespaces you'll typically want to enable ACL plugin also, otherwise all +# users can access all the shared mailboxes, assuming they have permissions +# on filesystem level to do so. +namespace inbox { + # Namespace type: private, shared or public + type = private + + # Hierarchy separator to use. You should use the same separator for all + # namespaces or some clients get confused. '/' is usually a good one. + # The default however depends on the underlying mail storage format. + separator = / + + # Prefix required to access this namespace. This needs to be different for + # all namespaces. For example "Public/". + #prefix = + + # Physical location of the mailbox. This is in same format as + # mail_location, which is also the default for it. + #location = + + # There can be only one INBOX, and this setting defines which namespace + # has it. + inbox = yes + + # If namespace is hidden, it's not advertised to clients via NAMESPACE + # extension. You'll most likely also want to set list=no. This is mostly + # useful when converting from another server with different namespaces which + # you want to deprecate but still keep working. For example you can create + # hidden namespaces with prefixes "~/mail/", "~%u/mail/" and "mail/". + #hidden = no + + # Show the mailboxes under this namespace with LIST command. This makes the + # namespace visible for clients that don't support NAMESPACE extension. + # "children" value lists child mailboxes, but hides the namespace prefix. + #list = yes + + # Namespace handles its own subscriptions. If set to "no", the parent + # namespace handles them (empty prefix should always have this as "yes") + #subscriptions = yes + + # See 15-mailboxes.conf for definitions of special mailboxes. +} + +# Example shared namespace configuration +#namespace { + #type = shared + #separator = / + + # Mailboxes are visible under "shared/user@domain/" + # %%n, %%d and %%u are expanded to the destination user. + #prefix = shared/%%u/ + + # Mail location for other users' mailboxes. Note that %variables and ~/ + # expands to the logged in user's data. %%n, %%d, %%u and %%h expand to the + # destination user's data. + #location = maildir:%%h/Maildir:INDEX=~/Maildir/shared/%%u + + # Use the default namespace for saving subscriptions. + #subscriptions = no + + # List the shared/ namespace only if there are visible shared mailboxes. + #list = children +#} +# Should shared INBOX be visible as "shared/user" or "shared/user/INBOX"? +#mail_shared_explicit_inbox = no + +# System user and group used to access mails. If you use multiple, userdb +# can override these by returning uid or gid fields. You can use either numbers +# or names. +mail_uid = vmail +mail_gid = vmail + +# Group to enable temporarily for privileged operations. Currently this is +# used only with INBOX when either its initial creation or dotlocking fails. +# Typically this is set to "mail" to give access to /var/mail. +mail_privileged_group = mail + +# Grant access to these supplementary groups for mail processes. Typically +# these are used to set up access to shared mailboxes. Note that it may be +# dangerous to set these if users can create symlinks (e.g. if "mail" group is +# set here, ln -s /var/mail ~/mail/var could allow a user to delete others' +# mailboxes, or ln -s /secret/shared/box ~/mail/mybox would allow reading it). +#mail_access_groups = + +# Allow full filesystem access to clients. There's no access checks other than +# what the operating system does for the active UID/GID. It works with both +# maildir and mboxes, allowing you to prefix mailboxes names with eg. /path/ +# or ~user/. +#mail_full_filesystem_access = no + +# Dictionary for key=value mailbox attributes. This is used for example by +# URLAUTH and METADATA extensions. +#mail_attribute_dict = + +# A comment or note that is associated with the server. This value is +# accessible for authenticated users through the IMAP METADATA server +# entry "/shared/comment". +#mail_server_comment = "" + +# Indicates a method for contacting the server administrator. According to +# RFC 5464, this value MUST be a URI (e.g., a mailto: or tel: URL), but that +# is currently not enforced. Use for example mailto:admin@example.com. This +# value is accessible for authenticated users through the IMAP METADATA server +# entry "/shared/admin". +#mail_server_admin = + +## +## Mail processes +## + +# Don't use mmap() at all. This is required if you store indexes to shared +# filesystems (NFS or clustered filesystem). +#mmap_disable = no + +# Rely on O_EXCL to work when creating dotlock files. NFS supports O_EXCL +# since version 3, so this should be safe to use nowadays by default. +#dotlock_use_excl = yes + +# When to use fsync() or fdatasync() calls: +# optimized (default): Whenever necessary to avoid losing important data +# always: Useful with e.g. NFS when write()s are delayed +# never: Never use it (best performance, but crashes can lose data) +#mail_fsync = optimized + +# Locking method for index files. Alternatives are fcntl, flock and dotlock. +# Dotlocking uses some tricks which may create more disk I/O than other locking +# methods. NFS users: flock doesn't work, remember to change mmap_disable. +#lock_method = fcntl + +# Directory where mails can be temporarily stored. Usually it's used only for +# mails larger than >= 128 kB. It's used by various parts of Dovecot, for +# example LDA/LMTP while delivering large mails or zlib plugin for keeping +# uncompressed mails. +#mail_temp_dir = /tmp + +# Valid UID range for users, defaults to 500 and above. This is mostly +# to make sure that users can't log in as daemons or other system users. +# Note that denying root logins is hardcoded to dovecot binary and can't +# be done even if first_valid_uid is set to 0. +#first_valid_uid = 500 +#last_valid_uid = 0 + +# Valid GID range for users, defaults to non-root/wheel. Users having +# non-valid GID as primary group ID aren't allowed to log in. If user +# belongs to supplementary groups with non-valid GIDs, those groups are +# not set. +#first_valid_gid = 1 +#last_valid_gid = 0 + +# Maximum allowed length for mail keyword name. It's only forced when trying +# to create new keywords. +#mail_max_keyword_length = 50 + +# ':' separated list of directories under which chrooting is allowed for mail +# processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too). +# This setting doesn't affect login_chroot, mail_chroot or auth chroot +# settings. If this setting is empty, "/./" in home dirs are ignored. +# WARNING: Never add directories here which local users can modify, that +# may lead to root exploit. Usually this should be done only if you don't +# allow shell access for users. +#valid_chroot_dirs = + +# Default chroot directory for mail processes. This can be overridden for +# specific users in user database by giving /./ in user's home directory +# (eg. /home/./user chroots into /home). Note that usually there is no real +# need to do chrooting, Dovecot doesn't allow users to access files outside +# their mail directory anyway. If your home directories are prefixed with +# the chroot directory, append "/." to mail_chroot. +#mail_chroot = + +# UNIX socket path to master authentication server to find users. +# This is used by imap (for shared users) and lda. +#auth_socket_path = /var/run/dovecot/auth-userdb + +# Directory where to look up mail plugins. +#mail_plugin_dir = /usr/lib/dovecot/modules + +# Space separated list of plugins to load for all services. Plugins specific to +# IMAP, LDA, etc. are added to this list in their own .conf files. +mail_plugins = $mail_plugins quota + +## +## Mailbox handling optimizations +## + +# Mailbox list indexes can be used to optimize IMAP STATUS commands. They are +# also required for IMAP NOTIFY extension to be enabled. +#mailbox_list_index = yes + +# Trust mailbox list index to be up-to-date. This reduces disk I/O at the cost +# of potentially returning out-of-date results after e.g. server crashes. +# The results will be automatically fixed once the folders are opened. +#mailbox_list_index_very_dirty_syncs = yes + +# Should INBOX be kept up-to-date in the mailbox list index? By default it's +# not, because most of the mailbox accesses will open INBOX anyway. +#mailbox_list_index_include_inbox = no + +# The minimum number of mails in a mailbox before updates are done to cache +# file. This allows optimizing Dovecot's behavior to do less disk writes at +# the cost of more disk reads. +#mail_cache_min_mail_count = 0 + +# When IDLE command is running, mailbox is checked once in a while to see if +# there are any new mails or other changes. This setting defines the minimum +# time to wait between those checks. Dovecot can also use inotify and +# kqueue to find out immediately when changes occur. +#mailbox_idle_check_interval = 30 secs + +# Save mails with CR+LF instead of plain LF. This makes sending those mails +# take less CPU, especially with sendfile() syscall with Linux and FreeBSD. +# But it also creates a bit more disk I/O which may just make it slower. +# Also note that if other software reads the mboxes/maildirs, they may handle +# the extra CRs wrong and cause problems. +#mail_save_crlf = no + +# Max number of mails to keep open and prefetch to memory. This only works with +# some mailbox formats and/or operating systems. +#mail_prefetch_count = 0 + +# How often to scan for stale temporary files and delete them (0 = never). +# These should exist only after Dovecot dies in the middle of saving mails. +#mail_temp_scan_interval = 1w + +# How many slow mail accesses sorting can perform before it returns failure. +# With IMAP the reply is: NO [LIMIT] Requested sort would have taken too long. +# The untagged SORT reply is still returned, but it's likely not correct. +#mail_sort_max_read_count = 0 + +protocol !indexer-worker { + # If folder vsize calculation requires opening more than this many mails from + # disk (i.e. mail sizes aren't in cache already), return failure and finish + # the calculation via indexer process. Disabled by default. This setting must + # be 0 for indexer-worker processes. + #mail_vsize_bg_after_count = 0 +} + +## +## Maildir-specific settings +## + +# By default LIST command returns all entries in maildir beginning with a dot. +# Enabling this option makes Dovecot return only entries which are directories. +# This is done by stat()ing each entry, so it causes more disk I/O. +# (For systems setting struct dirent->d_type, this check is free and it's +# done always regardless of this setting) +#maildir_stat_dirs = no + +# When copying a message, do it with hard links whenever possible. This makes +# the performance much better, and it's unlikely to have any side effects. +#maildir_copy_with_hardlinks = yes + +# Assume Dovecot is the only MUA accessing Maildir: Scan cur/ directory only +# when its mtime changes unexpectedly or when we can't find the mail otherwise. +#maildir_very_dirty_syncs = no + +# If enabled, Dovecot doesn't use the S= in the Maildir filenames for +# getting the mail's physical size, except when recalculating Maildir++ quota. +# This can be useful in systems where a lot of the Maildir filenames have a +# broken size. The performance hit for enabling this is very small. +#maildir_broken_filename_sizes = no + +# Always move mails from new/ directory to cur/, even when the \Recent flags +# aren't being reset. +#maildir_empty_new = no + +## +## mbox-specific settings +## + +# Which locking methods to use for locking mbox. There are four available: +# dotlock: Create .lock file. This is the oldest and most NFS-safe +# solution. If you want to use /var/mail/ like directory, the users +# will need write access to that directory. +# dotlock_try: Same as dotlock, but if it fails because of permissions or +# because there isn't enough disk space, just skip it. +# fcntl : Use this if possible. Works with NFS too if lockd is used. +# flock : May not exist in all systems. Doesn't work with NFS. +# lockf : May not exist in all systems. Doesn't work with NFS. +# +# You can use multiple locking methods; if you do the order they're declared +# in is important to avoid deadlocks if other MTAs/MUAs are using multiple +# locking methods as well. Some operating systems don't allow using some of +# them simultaneously. +# +# The Debian value for mbox_write_locks differs from upstream Dovecot. It is +# changed to be compliant with Debian Policy (section 11.6) for NFS safety. +# Dovecot: mbox_write_locks = dotlock fcntl +# Debian: mbox_write_locks = fcntl dotlock +# +#mbox_read_locks = fcntl +#mbox_write_locks = fcntl dotlock + +# Maximum time to wait for lock (all of them) before aborting. +#mbox_lock_timeout = 5 mins + +# If dotlock exists but the mailbox isn't modified in any way, override the +# lock file after this much time. +#mbox_dotlock_change_timeout = 2 mins + +# When mbox changes unexpectedly we have to fully read it to find out what +# changed. If the mbox is large this can take a long time. Since the change +# is usually just a newly appended mail, it'd be faster to simply read the +# new mails. If this setting is enabled, Dovecot does this but still safely +# fallbacks to re-reading the whole mbox file whenever something in mbox isn't +# how it's expected to be. The only real downside to this setting is that if +# some other MUA changes message flags, Dovecot doesn't notice it immediately. +# Note that a full sync is done with SELECT, EXAMINE, EXPUNGE and CHECK +# commands. +#mbox_dirty_syncs = yes + +# Like mbox_dirty_syncs, but don't do full syncs even with SELECT, EXAMINE, +# EXPUNGE or CHECK commands. If this is set, mbox_dirty_syncs is ignored. +#mbox_very_dirty_syncs = no + +# Delay writing mbox headers until doing a full write sync (EXPUNGE and CHECK +# commands and when closing the mailbox). This is especially useful for POP3 +# where clients often delete all mails. The downside is that our changes +# aren't immediately visible to other MUAs. +#mbox_lazy_writes = yes + +# If mbox size is smaller than this (e.g. 100k), don't write index files. +# If an index file already exists it's still read, just not updated. +#mbox_min_index_size = 0 + +# Mail header selection algorithm to use for MD5 POP3 UIDLs when +# pop3_uidl_format=%m. For backwards compatibility we use apop3d inspired +# algorithm, but it fails if the first Received: header isn't unique in all +# mails. An alternative algorithm is "all" that selects all headers. +#mbox_md5 = apop3d + +## +## mdbox-specific settings +## + +# Maximum dbox file size until it's rotated. +#mdbox_rotate_size = 10M + +# Maximum dbox file age until it's rotated. Typically in days. Day begins +# from midnight, so 1d = today, 2d = yesterday, etc. 0 = check disabled. +#mdbox_rotate_interval = 0 + +# When creating new mdbox files, immediately preallocate their size to +# mdbox_rotate_size. This setting currently works only in Linux with some +# filesystems (ext4, xfs). +#mdbox_preallocate_space = no + +## +## Mail attachments +## + +# sdbox and mdbox support saving mail attachments to external files, which +# also allows single instance storage for them. Other backends don't support +# this for now. + +# Directory root where to store mail attachments. Disabled, if empty. +#mail_attachment_dir = + +# Attachments smaller than this aren't saved externally. It's also possible to +# write a plugin to disable saving specific attachments externally. +#mail_attachment_min_size = 128k + +# Filesystem backend to use for saving attachments: +# posix : No SiS done by Dovecot (but this might help FS's own deduplication) +# sis posix : SiS with immediate byte-by-byte comparison during saving +# sis-queue posix : SiS with delayed comparison and deduplication +#mail_attachment_fs = sis posix + +# Hash format to use in attachment filenames. You can add any text and +# variables: %{md4}, %{md5}, %{sha1}, %{sha256}, %{sha512}, %{size}. +# Variables can be truncated, e.g. %{sha256:80} returns only first 80 bits +#mail_attachment_hash = %{sha1} + +# Settings to control adding $HasAttachment or $HasNoAttachment keywords. +# By default, all MIME parts with Content-Disposition=attachment, or inlines +# with filename parameter are consired attachments. +# add-flags-on-save - Add the keywords when saving new mails. +# content-type=type or !type - Include/exclude content type. Excluding will +# never consider the matched MIME part as attachment. Including will only +# negate an exclusion (e.g. content-type=!foo/* content-type=foo/bar). +# exclude-inlined - Exclude any Content-Disposition=inline MIME part. +#mail_attachment_detection_options = diff --git a/etc/dovecot/conf.d/10-master.conf b/etc/dovecot/conf.d/10-master.conf new file mode 100644 index 0000000..a8fc5c9 --- /dev/null +++ b/etc/dovecot/conf.d/10-master.conf @@ -0,0 +1,136 @@ +#default_process_limit = 100 +#default_client_limit = 1000 + +# Default VSZ (virtual memory size) limit for service processes. This is mainly +# intended to catch and kill processes that leak memory before they eat up +# everything. +#default_vsz_limit = 256M + +# Login user is internally used by login processes. This is the most untrusted +# user in Dovecot system. It shouldn't have access to anything at all. +#default_login_user = dovenull + +# Internal user is used by unprivileged processes. It should be separate from +# login user, so that login processes can't disturb other processes. +#default_internal_user = dovecot + +service imap-login { + inet_listener imap { + port = 143 + } + inet_listener imaps { + port = 993 + ssl = yes + } + + # Number of connections to handle before starting a new process. Typically + # the only useful values are 0 (unlimited) or 1. 1 is more secure, but 0 + # is faster. + #service_count = 1 + + # Number of processes to always keep waiting for more connections. + #process_min_avail = 0 + + # If you set service_count=0, you probably need to grow this. + #vsz_limit = $default_vsz_limit +} + +service pop3-login { + inet_listener pop3 { + port = 110 + } + inet_listener pop3s { + port = 995 + ssl = yes + } +} + +service submission-login { + inet_listener submission { + #port = 587 + } +} + +service lmtp { + unix_listener lmtp { + #mode = 0666 + } + + # Create inet listener only if you can't use the above UNIX socket + #inet_listener lmtp { + # Avoid making LMTP visible for the entire internet + #address = + #port = + #} +} + +service imap { + # Most of the memory goes to mmap()ing files. You may need to increase this + # limit if you have huge mailboxes. + #vsz_limit = $default_vsz_limit + + # Max. number of IMAP processes (connections) + #process_limit = 1024 +} + +service pop3 { + # Max. number of POP3 processes (connections) + #process_limit = 1024 +} + +service submission { + # Max. number of SMTP Submission processes (connections) + #process_limit = 1024 +} + +service auth { + # auth_socket_path points to this userdb socket by default. It's typically + # used by dovecot-lda, doveadm, possibly imap process, etc. Users that have + # full permissions to this socket are able to get a list of all usernames and + # get the results of everyone's userdb lookups. + # + # The default 0666 mode allows anyone to connect to the socket, but the + # userdb lookups will succeed only if the userdb returns an "uid" field that + # matches the caller process's UID. Also if caller's uid or gid matches the + # socket's uid or gid the lookup succeeds. Anything else causes a failure. + # + # To give the caller full permissions to lookup all users, set the mode to + # something else than 0666 and Dovecot lets the kernel enforce the + # permissions (e.g. 0777 allows everyone full permissions). + unix_listener auth-userdb { + #mode = 0666 + #user = + #group = + } + + unix_listener auth-client { + mode = 0660 + user = mail + group = Debian-exim + } + + # Postfix smtp-auth + #unix_listener /var/spool/postfix/private/auth { + # mode = 0666 + #} + + # Auth process is run as this user. + #user = $default_internal_user +} + +service auth-worker { + # Auth worker process is run as root by default, so that it can access + # /etc/shadow. If this isn't necessary, the user should be changed to + # $default_internal_user. + #user = root +} + +service dict { + # If dict proxy is used, mail processes should have access to its socket. + # For example: mode=0660, group=vmail and global mail_access_groups=vmail + unix_listener dict { + #mode = 0600 + #user = + #group = + } +} diff --git a/etc/dovecot/conf.d/10-ssl.conf b/etc/dovecot/conf.d/10-ssl.conf new file mode 100644 index 0000000..41c595a --- /dev/null +++ b/etc/dovecot/conf.d/10-ssl.conf @@ -0,0 +1,82 @@ +## +## SSL settings +## + +# SSL/TLS support: yes, no, required. +ssl = required + +# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before +# dropping root privileges, so keep the key file unreadable by anyone but +# root. Included doc/mkcert.sh can be used to easily generate self-signed +# certificate, just make sure to update the domains in dovecot-openssl.cnf +ssl_cert = + +## +## Quota limits +## + +# Quota limits are set using "quota_rule" parameters. To get per-user quota +# limits, you can set/override them by returning "quota_rule" extra field +# from userdb. It's also possible to give mailbox-specific limits, for example +# to give additional 100 MB when saving to Trash: + +plugin { + quota_rule = *:storage=1G + quota_rule2 = Trash:ignore + quota_rule3 = Junk:ignore + #quota_rule2 = Trash:storage=+100M + + # LDA/LMTP allows saving the last mail to bring user from under quota to + # over quota, if the quota doesn't grow too high. Default is to allow as + # long as quota will stay under 10% above the limit. Also allowed e.g. 10M. + quota_grace = 10%% + + # Quota plugin can also limit the maximum accepted mail size. + #quota_max_mail_size = 100M +} + +## +## Quota warnings +## + +# You can execute a given command when user exceeds a specified quota limit. +# Each quota root has separate limits. Only the command for the first +# exceeded limit is executed, so put the highest limit first. +# The commands are executed via script service by connecting to the named +# UNIX socket (quota-warning below). +# Note that % needs to be escaped as %%, otherwise "% " expands to empty. + +plugin { + quota_warning = storage=95%% quota-warning 95 %u + quota_warning2 = storage=80%% quota-warning 90 %u +} + +# Example quota-warning service. The unix listener's permissions should be +# set in a way that mail processes can connect to it. Below example assumes +# that mail processes run as vmail user. If you use mode=0666, all system users +# can generate quota warnings to anyone. +#service quota-warning { +# executable = script /usr/local/bin/quota-warning.sh +# user = dovecot +# unix_listener quota-warning { +# user = vmail +# } +#} +service quota-warning { + executable = script /usr/local/sbin/quota-warning.sh + user = dovecot + unix_listener quota-warning { + user = dovecot + group = mail + mode = 0660 + } +} + +## +## Quota backends +## + +# Multiple backends are supported: +# dirsize: Find and sum all the files found from mail directory. +# Extremely SLOW with Maildir. It'll eat your CPU and disk I/O. +# dict: Keep quota stored in dictionary (eg. SQL) +# maildir: Maildir++ quota +# fs: Read-only support for filesystem quota + +plugin { + #quota = dirsize:User quota + quota = maildir:User quota + #quota = dict:User quota::proxy::quota + #quota = fs:User quota +} + +# Multiple quota roots are also possible, for example this gives each user +# their own 100MB quota and one shared 1GB quota within the domain: +plugin { + #quota = dict:user::proxy::quota + #quota2 = dict:domain:%d:proxy::quota_domain + #quota_rule = *:storage=102400 + #quota2_rule = *:storage=1048576 +} diff --git a/etc/dovecot/conf.d/auth-sql.conf.ext b/etc/dovecot/conf.d/auth-sql.conf.ext new file mode 100644 index 0000000..cd601e7 --- /dev/null +++ b/etc/dovecot/conf.d/auth-sql.conf.ext @@ -0,0 +1,30 @@ +# Authentication for SQL users. Included from 10-auth.conf. +# +# + +passdb { + driver = sql + + # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext + args = /etc/dovecot/dovecot-sql.conf.ext +} + +# "prefetch" user database means that the passdb already provided the +# needed information and there's no need to do a separate userdb lookup. +# +userdb { + driver = prefetch +} + +#userdb { +# driver = sql +# args = /etc/dovecot/dovecot-sql.conf.ext +#} + +# If you don't have any user-specific settings, you can avoid the user_query +# by using userdb static instead of userdb sql, for example: +# +userdb { + driver = static + args = uid=vmail gid=vmail home=/var/vmail/%d/%n +} diff --git a/etc/dovecot/dovecot-sql.conf.ext b/etc/dovecot/dovecot-sql.conf.ext new file mode 100644 index 0000000..949ec1d --- /dev/null +++ b/etc/dovecot/dovecot-sql.conf.ext @@ -0,0 +1,146 @@ +# This file is commonly accessed via passdb {} or userdb {} section in +# conf.d/auth-sql.conf.ext + +# This file is opened as root, so it should be owned by root and mode 0600. +# +# http://wiki2.dovecot.org/AuthDatabase/SQL +# +# For the sql passdb module, you'll need a database with a table that +# contains fields for at least the username and password. If you want to +# use the user@domain syntax, you might want to have a separate domain +# field as well. +# +# If your users all have the same uig/gid, and have predictable home +# directories, you can use the static userdb module to generate the home +# dir based on the username and domain. In this case, you won't need fields +# for home, uid, or gid in the database. +# +# If you prefer to use the sql userdb module, you'll want to add fields +# for home, uid, and gid. Here is an example table: +# +# CREATE TABLE users ( +# username VARCHAR(128) NOT NULL, +# domain VARCHAR(128) NOT NULL, +# password VARCHAR(64) NOT NULL, +# home VARCHAR(255) NOT NULL, +# uid INTEGER NOT NULL, +# gid INTEGER NOT NULL, +# active CHAR(1) DEFAULT 'Y' NOT NULL +# ); + +# Database driver: mysql, pgsql, sqlite +driver = mysql + +# Database connection string. This is driver-specific setting. +# +# HA / round-robin load-balancing is supported by giving multiple host +# settings, like: host=sql1.host.org host=sql2.host.org +# +# pgsql: +# For available options, see the PostgreSQL documentation for the +# PQconnectdb function of libpq. +# Use maxconns=n (default 5) to change how many connections Dovecot can +# create to pgsql. +# +# mysql: +# Basic options emulate PostgreSQL option names: +# host, port, user, password, dbname +# +# But also adds some new settings: +# client_flags - See MySQL manual +# connect_timeout - Connect timeout in seconds (default: 5) +# read_timeout - Read timeout in seconds (default: 30) +# write_timeout - Write timeout in seconds (default: 30) +# ssl_ca, ssl_ca_path - Set either one or both to enable SSL +# ssl_cert, ssl_key - For sending client-side certificates to server +# ssl_cipher - Set minimum allowed cipher security (default: HIGH) +# ssl_verify_server_cert - Verify that the name in the server SSL certificate +# matches the host (default: no) +# option_file - Read options from the given file instead of +# the default my.cnf location +# option_group - Read options from the given group (default: client) +# +# You can connect to UNIX sockets by using host: host=/var/run/mysql.sock +# Note that currently you can't use spaces in parameters. +# +# sqlite: +# The path to the database file. +# +# Examples: +# connect = host=192.168.1.1 dbname=users +# connect = host=sql.example.com dbname=virtual user=virtual password=blarg +# connect = /etc/dovecot/authdb.sqlite +# +connect = host=localhost dbname=vmail user=vmail password=password + +# Default password scheme. +# +# List of supported schemes is in +# http://wiki2.dovecot.org/Authentication/PasswordSchemes +# +default_pass_scheme = SHA512-CRYPT + +# passdb query to retrieve the password. It can return fields: +# password - The user's password. This field must be returned. +# user - user@domain from the database. Needed with case-insensitive lookups. +# username and domain - An alternative way to represent the "user" field. +# +# The "user" field is often necessary with case-insensitive lookups to avoid +# e.g. "name" and "nAme" logins creating two different mail directories. If +# your user and domain names are in separate fields, you can return "username" +# and "domain" fields instead of "user". +# +# The query can also return other fields which have a special meaning, see +# http://wiki2.dovecot.org/PasswordDatabase/ExtraFields +# +# Commonly used available substitutions (see http://wiki2.dovecot.org/Variables +# for full list): +# %u = entire user@domain +# %n = user part of user@domain +# %d = domain part of user@domain +# +# Note that these can be used only as input to SQL query. If the query outputs +# any of these substitutions, they're not touched. Otherwise it would be +# difficult to have eg. usernames containing '%' characters. +# +# Example: +# password_query = SELECT userid AS user, pw AS password \ +# FROM users WHERE userid = '%u' AND active = 'Y' +# +#password_query = \ +# SELECT username, domain, password \ +# FROM users WHERE username = '%n' AND domain = '%d' + +# userdb query to retrieve the user information. It can return fields: +# uid - System UID (overrides mail_uid setting) +# gid - System GID (overrides mail_gid setting) +# home - Home directory +# mail - Mail location (overrides mail_location setting) +# +# None of these are strictly required. If you use a single UID and GID, and +# home or mail directory fits to a template string, you could use userdb static +# instead. For a list of all fields that can be returned, see +# http://wiki2.dovecot.org/UserDatabase/ExtraFields +# +# Examples: +# user_query = SELECT home, uid, gid FROM users WHERE userid = '%u' +# user_query = SELECT dir AS home, user AS uid, group AS gid FROM users where userid = '%u' +# user_query = SELECT home, 501 AS uid, 501 AS gid FROM users WHERE userid = '%u' +# +#user_query = \ +# SELECT home, uid, gid \ +# FROM users WHERE username = '%n' AND domain = '%d' + +# If you wish to avoid two SQL lookups (passdb + userdb), you can use +# userdb prefetch instead of userdb sql in dovecot.conf. In that case you'll +# also have to return userdb fields in password_query prefixed with "userdb_" +# string. For example: +#password_query = \ +# SELECT userid AS user, password, \ +# home AS userdb_home, uid AS userdb_uid, gid AS userdb_gid \ +# FROM users WHERE userid = '%u' + +password_query = SELECT vm_mboxes.passwd AS password, CONCAT('*:bytes=', vm_mboxes.quota, 'G') AS userdb_quota_rule, '/var/vmail/%d/%n' AS userdb_home, '/var/vmail/%d/%n/Maildir' AS userdb_mail, 'vmail' AS userdb_uid, 'vmail' AS userdb_gid FROM vm_domains, vm_mboxes WHERE vm_domains.domain = '%d' AND vm_domains.id = vm_mboxes.domain_id AND vm_mboxes.mbox = '%n' + +# Query to get a list of all usernames. +#iterate_query = SELECT username AS user FROM users diff --git a/etc/exim4/autowhitelist.filter b/etc/exim4/autowhitelist.filter new file mode 100644 index 0000000..498dd1f --- /dev/null +++ b/etc/exim4/autowhitelist.filter @@ -0,0 +1,22 @@ +# Exim filter + +if error_message then finish endif + +# check for and delete type = MANUAL. don't need to insert anything??? +if "${lookup mysql{SELECT COUNT(*) FROM vm_greylisting WHERE sender = \"$local_part@$domain\" AND recipient = '$sender_address' AND type = 'MANUAL'}}" is 0 then + if "${lookup mysql{INSERT INTO vm_greylisting SET sender = \"$local_part@$domain\", recipient = '$sender_address', create_time = NOW()}}" is not 0 then + if "${lookup mysql{DELETE FROM vm_greylisting WHERE sender = \"$local_part@$domain\" AND recipient = '$sender_address' AND type = 'AUTO'}}" is not 0 then + # done updated greylisting + endif + endif +endif + +if "${lookup mysql{SELECT COUNT(*) FROM sa_userpref WHERE username = '$sender_address' AND preference = 'whitelist_from' AND value = \"$local_part@$domain\"}}" is 0 then + if "${lookup mysql{INSERT INTO sa_userpref SET username = '$sender_address', preference = 'whitelist_from', value = \"$local_part@$domain\"}}" is not 0 then + if "${lookup mysql{DELETE FROM sa_userpref WHERE username = '$sender_address' AND preference != 'whitelist_from' AND value = \"$local_part@$domain\"}}" is not 0 then + # done updated sa_userpref + endif + endif +endif + +finish diff --git a/etc/exim4/exim4.conf b/etc/exim4/exim4.conf new file mode 100644 index 0000000..b591d52 --- /dev/null +++ b/etc/exim4/exim4.conf @@ -0,0 +1,1135 @@ +# $Id: exim.conf 228 2005-07-27 17:06:36Z root $ +###################################################################### +# Runtime configuration file for Exim # +###################################################################### + +disable_ipv6 = true +keep_environment = +add_environment = PATH=/usr/sbin:/usr/bin:/sbin:/bin +smtp_enforce_sync = false + +smtp_accept_max = 50 +smtp_accept_max_per_host = 10 +smtp_accept_queue_per_connection = 50 + +.include /etc/exim4/exim_local.conf + +tls_advertise_hosts = * +tls_certificate = ${if exists{/etc/ssl/letsencrypt/${tls_sni}.pem}{/etc/ssl/letsencrypt/${tls_sni}.pem}} + +tls_on_connect_ports = 465 +daemon_smtp_ports = 25 : 465 : 587 + +# This is a default configuration file which will operate correctly in +# uncomplicated installations. Please see the manual for a complete list +# of all the runtime configuration options that can be included in a +# configuration file. There are many more than are mentioned here. The +# manual is in the file doc/spec.txt in the Exim distribution as a plain +# ASCII file. Other formats (PostScript, Texinfo, HTML, PDF) are available +# from the Exim ftp sites. The manual is also online at the Exim web sites. + + +# This file is divided into several parts, all but the first of which are +# headed by a line starting with the word "begin". Only those parts that +# are required need to be present. Blank lines, and lines starting with # +# are ignored. + + +########### IMPORTANT ########## IMPORTANT ########### IMPORTANT ########### +# # +# Whenever you change Exim's configuration file, you *must* remember to # +# HUP the Exim daemon, because it will not pick up the new configuration # +# until you do. However, any other Exim processes that are started, for # +# example, a process started by an MUA in order to send a message, will # +# see the new configuration as soon as it is in place. # +# # +# You do not need to HUP the daemon for changes in auxiliary files that # +# are referenced from this file. They are read every time they are used. # +# # +# It is usually a good idea to test a new configuration for syntactic # +# correctness before installing it (for example, by running the command # +# "exim -C /config/file.new -bV"). # +# # +########### IMPORTANT ########## IMPORTANT ########### IMPORTANT ########### + + + +###################################################################### +# MAIN CONFIGURATION SETTINGS # +###################################################################### + +# Specify your host's canonical name here. This should normally be the fully +# qualified "official" name of your host. If this option is not set, the +# uname() function is called to obtain the name. In many cases this does +# the right thing and you need not set anything explicitly. + +queue_only_load = 3 +log_selector = +all + +# The next three settings create two lists of domains and one list of hosts. +# These lists are referred to later in this configuration using the syntax +# +local_domains, +relay_to_domains, and +relay_from_hosts, respectively. They +# are all colon-separated lists: + +domainlist local_domains = ${lookup mysql{SELECT domain FROM vm_domains WHERE domain='$domain' AND status = '1'}} +domainlist relay_to_domains = /etc/exim4/relay_domains +hostlist relay_from_hosts = 127.0.0.1 +hostlist skip_greylisting_hosts = /etc/exim4/skip_greylisting_hosts + +# overide default sender checks +untrusted_set_sender = * +local_from_check = false +local_sender_retain = true + +# trusted users, needed by spamcheck +trusted_users = mail + +# local whitelist check macro: +WHITELISTED = ${lookup mysql{\ + SELECT prefid FROM sa_userpref \ + WHERE (username = '${quote_mysql:$local_part@$domain}' \ + OR username = '\$GLOBAL' \ + OR username = CONCAT('%','${quote_mysql:$domain}')) \ + AND preference = 'whitelist_from' \ + AND (value = '${quote_mysql:$sender_address}' \ + OR value = CONCAT('\*@','${quote_mysql:$sender_address_domain}')) \ + }{true}{false}} + +# greylist options +# these need to be valid as xxx in mysql's DATE_ADD(..,INTERVAL xxx) +# not valid, for example, are plurals: "2 HOUR" instead of "2 HOURS" +GREYLIST_INITIAL_DELAY = 4 MINUTE +GREYLIST_INITIAL_LIFETIME = 12 HOUR +GREYLIST_WHITE_LIFETIME = 36 DAY +GREYLIST_BOUNCE_LIFETIME = 0 HOUR + +# you can change the table names +GREYLIST_TABLE=vm_greylisting +GREYLIST_RESENDERS_TABLE=vm_greylisting_resenders + +.ifdef GREYLIST_ENABLED +# database macros +GREYLIST_TEST = SELECT CASE \ + WHEN now() > block_expires THEN "accepted" \ + ELSE "deferred" \ + END AS result, id \ + FROM GREYLIST_TABLE \ + WHERE (now() < record_expires) \ + AND (sender = '${quote_mysql:$sender_address}' \ + OR (type='MANUAL' \ + AND ( sender IS NULL \ + OR sender = '${quote_mysql:*@$sender_address_domain}' \ + ) \ + ) \ + ) \ + AND (recipient = '${quote_mysql:$local_part@$domain}' \ + OR (type = 'MANUAL' \ + AND ( recipient IS NULL \ + OR recipient = '${quote_mysql:$local_part@*}' \ + OR recipient = '${quote_mysql:*@$domain}' \ + ) \ + ) \ + ) \ + AND (relay_hostname = '${quote_mysql:$acl_m_sender}' \ + OR (type='MANUAL' \ + AND relay_hostname IS NULL) \ + ) \ + ORDER BY result DESC LIMIT 1 + +GREYLIST_ADD = INSERT INTO GREYLIST_TABLE \ + (relay_hostname, relay_ip, sender, recipient, block_expires, \ + record_expires, create_time, type) \ + VALUES ( '${quote_mysql:$acl_m_sender}', \ + '${quote_mysql:$sender_host_address}', \ + '${quote_mysql:$sender_address}', \ + '${quote_mysql:$local_part@$domain}', \ + DATE_ADD(now(), INTERVAL GREYLIST_INITIAL_DELAY), \ + DATE_ADD(now(), INTERVAL GREYLIST_INITIAL_LIFETIME), \ + now(), \ + 'AUTO' \ +) + +GREYLIST_DEFER_HIT = UPDATE GREYLIST_TABLE \ + SET blockcount=blockcount+1 \ + WHERE id = $acl_m9 + +GREYLIST_OK_COUNT = UPDATE GREYLIST_TABLE \ + SET passcount=passcount+1 \ + WHERE id = $acl_m9 + +GREYLIST_OK_NEWTIME = UPDATE GREYLIST_TABLE \ + SET record_expires = DATE_ADD(now(), INTERVAL GREYLIST_WHITE_LIFETIME) \ + WHERE id = $acl_m9 AND type='AUTO' + +GREYLIST_OK_BOUNCE = UPDATE GREYLIST_TABLE \ + SET record_expires = DATE_ADD(now(), INTERVAL GREYLIST_BOUNCE_LIFETIME) \ + WHERE id = $acl_m9 AND type='AUTO' + +GREYLIST_RESENDERS_UPDATE = REPLACE INTO GREYLIST_RESENDERS_TABLE SET hostname = '${quote_mysql:$acl_m_sender}' +.endif +# No deliveries will ever be run under the uids of these users (a colon- +# separated list). An attempt to do so causes a panic error to be logged, and +# the delivery to be deferred. This is a paranoic safety catch. Note that the +# default setting means you cannot deliver mail addressed to root as if it +# were a normal user. This isn't usually a problem, as most sites have an alias +# for root that redirects such mail to a human administrator. + +never_users = root + + +# The setting below causes Exim to do a reverse DNS lookup on all incoming +# IP calls, in order to get the true host name. If you feel this is too +# expensive, you can specify the networks for which a lookup is done, or +# remove the setting entirely. + +host_lookup = * + + +# The settings below, which are actually the same as the defaults in the +# code, cause Exim to make RFC 1413 (ident) callbacks for all incoming SMTP +# calls. You can limit the hosts to which these calls are made, and/or change +# the timeout that is used. If you set the timeout to zero, all RFC 1413 calls +# are disabled. RFC 1413 calls are cheap and can provide useful information +# for tracing problem messages, but some hosts and firewalls have problems +# with them. This can result in a timeout instead of an immediate refused +# connection, leading to delays on starting up an SMTP session. + +rfc1413_hosts = * +rfc1413_query_timeout = 0s + +# This option unfreezes frozen bounce messages after two days, tries +# once more to deliver them, and ignores any delivery failures. + +ignore_bounce_errors_after = 0s + +# This option cancels (removes) frozen messages that are older than a week. + +timeout_frozen_after = 1d + +# Treat DNS failures (SERVFAIL) as lookup failures. +# This is so that we can later reject sender addresses +# within non-existing domains, or domains for which no +# nameserver exists. +dns_again_means_nonexist = !+local_domains + +# Enable HELO verification in ACLs for all hosts +helo_try_verify_hosts = * + +# Advertise ESMTP "PIPELINING" to all hosts +pipelining_advertise_hosts = * + +acl_smtp_connect = acl_connect +acl_smtp_helo = acl_helo +acl_smtp_mail = acl_mail_from +acl_smtp_dkim = acl_check_dkim +acl_smtp_rcpt = acl_rcpt_to +acl_smtp_data = acl_data + +# set the av scanner to clamav +##av_scanner = clamd:/run/clamav/clamd.ctl + +begin acl + +# this acl returns either deny or accept +# since we use it inside a defer with acl = greylist_acl, +# accepting here makes the condition TRUE thus deferring, +# denying here makes the condition FALSE thus not deferring +.ifdef GREYLIST_ENABLED +greylist_acl: + # For regular deliveries, check greylist. + + # check greylist tuple, returning "accepted", "deferred" or "unknown" + # in acl_m8, and the record id in acl_m9 + + warn set acl_m8 = ${lookup mysql{GREYLIST_TEST}{$value}{result=unknown}} + # here acl_m8 = "result=x id=y" + + set acl_m9 = ${extract{id}{$acl_m8}{$value}{-1}} + # now acl_m9 contains the record id (or -1) + + set acl_m8 = ${extract{result}{$acl_m8}{$value}{unknown}} + # now acl_m8 contains unknown/deferred/accepted + + # check if we know a certain triple, add and defer message if not + accept + # if above check returned unknown (no record yet) + condition = ${if eq{$acl_m8}{unknown}{1}} + # then also add a record + condition = ${lookup mysql{GREYLIST_ADD}{yes}{no}} + + # check if the triple is still blocked + accept + # if above check returned deferred then defer + condition = ${if eq{$acl_m8}{deferred}{1}} + # and note it down + condition = ${lookup mysql{GREYLIST_DEFER_HIT}{yes}{yes}} + + # use a warn verb to count records that were hit + warn condition = ${lookup mysql{GREYLIST_OK_COUNT}} + + # use a warn verb to set a new expire time on automatic records, + # but only if the mail was not a bounce, otherwise set to now(). + warn !senders = : postmaster@* + condition = ${lookup mysql{GREYLIST_OK_NEWTIME}} + warn senders = : postmaster@* + condition = ${lookup mysql{GREYLIST_OK_BOUNCE}} + + deny + add_header = X-DNS-Greylist: mail from $sender_address to $local_part@$domain accepted by greylisting + condition = ${lookup mysql{GREYLIST_RESENDERS_UPDATE}} +.endif +# This access control list is used at the start of an incoming +# connection. The tests are run in order until the connection +# is either accepted or denied. + +acl_connect: + + # In this pass, we do not perform any checks here. + accept + + +# This access control list is used for the HELO or EHLO command in +# an incoming SMTP transaction. The tests are run in order until the +# greeting is either accepted or denied. + +acl_helo: + + # Early rejection of brute-force bots under the name 'ylmf-pc' + deny + condition = ${if eq{$sender_helo_name}{ylmf-pc}{yes}{no}} + + # In this pass, we do not perform any checks here. + accept + +# This access control list is used for the MAIL FROM: command in an +# incoming SMTP transaction. The tests are run in order until the +# sender address is either accepted or denied. +# + +acl_mail_from: + + # Accept the command. + accept + +# This access control list is used for every RCPT command in an +# incoming SMTP message. The tests are run in order until the +# recipient address is either accepted or denied. + +acl_check_dkim: + + ###################################################################### + # DomainKeys + ###################################################################### + + # DKIM fail + accept + dkim_status = fail + logwrite = DKIM test failed: $dkim_verify_reason + add_header = X-DKIM-Status: fail: $dkim_verify_reason + add_header = X-Junk-Flag: YES + + # DKIM invalid + accept + dkim_status = invalid + logwrite = DKIM test invalid: $dkim_verify_reason + add_header = X-DKIM-Status: invalid: $dkim_verify_reason + add_header = X-Junk-Flag: YES + + # DKIM none + accept + dkim_status = none + logwrite = DKIM test none + add_header = X-DKIM-Status: none + + # DKIM pass + accept + dkim_status = pass + logwrite = DKIM test passed + add_header = X-DKIM-Status: passed: (address=$sender_address domain=$dkim_cur_signer), signature is good. + + # Accept the message. + accept + +acl_rcpt_to: + + # Accept mail received over local SMTP (i.e. not over TCP/IP). + # We do this by testing for an empty sending host field. + # Also accept mails received from hosts for which we relay mail. + # + # Recipient verification is omitted here, because in many + # cases the clients are dumb MUAs that don't cope well with + # SMTP error responses. + # + accept + hosts = : +relay_from_hosts + + + # Accept if the message arrived over an authenticated connection, + # from any host. Again, these messages are usually from MUAs, so + # recipient verification is omitted. + # + accept + authenticated = * + + + ###################################################################### + # Hello checks + ###################################################################### + + # If the remote host greets with an IP address, then reject the mail. + # + deny + message = Message was delivered by ratware + log_message = remote host used IP address in HELO/EHLO greeting + condition = ${if isip {$sender_helo_name}{true}{false}} + + # Likewise if the peer greets with one of our own names + # + deny + message = Message was delivered by ratware + log_message = remote host used our name in HELO/EHLO greeting. + condition = ${if match_domain{$sender_helo_name}\ + {$primary_hostname:+local_domains}\ + {true}{false}} + + deny + message = Message was delivered by ratware + log_message = remote host did not present HELO/EHLO greeting. + condition = ${if def:sender_helo_name {false}{true}} + + + # If HELO verification fails, we add a X-HELO-Warning: header in + # the message. + # + warn + !verify = helo + message = X-HELO-Warning: Remote host $sender_host_address \ + ${if def:sender_host_name {($sender_host_name) }}\ + incorrectly presented itself as $sender_helo_name + log_message = remote host presented unverifiable HELO/EHLO greeting. + + # if "!verify = helo" & $send_host_name = '' reject??? + + ###################################################################### + # Sender Address Checks + ###################################################################### + + # If we cannot verify the sender address, deny the message. + # + # You may choose to remove the "callout" option. In particular, + # if you are sending outgoing mail through a smarthost, it will not + # give any useful information. + # + # Details regarding the failed callout verification attempt are + # included in the 550 response; to omit these, change + # "sender/callout" to "sender/callout,no_details". + # +# deny +# message = <$sender_address> does not appear to be a \ +# valid sender address. +# !verify = sender/callout + + ###################################################################### + # Recipent Address Checks + ###################################################################### + + # Deny if the local part contains @ or % or / or | or !. These are + # rarely found in genuine local parts, but are often tried by people + # looking to circumvent relaying restrictions. + # + # Also deny if the local part starts with a dot. Empty components + # aren't strictly legal in RFC 2822, but Exim allows them because + # this is common. However, actually starting with a dot may cause + # trouble if the local part is used as a file name (e.g. for a + # mailing list). + # + deny + local_parts = ^.*[@%!/|] : ^\\. + + # Drop the connection if the envelope sender is empty, but there is + # more than one recipient address. Legitimate DSNs are never sent + # to more than one address. + # + drop + message = Legitimate bounces are never sent to more than one recipient. + log_message = Legitimate bounces are never sent to more than one recipient (count: $recipients_count). + senders = : postmaster@* + condition = $recipients_count + + + # Reject the recipient address if it is not in a domain for + # which we are handling mail. + # + deny + message = relay not permitted + !domains = +local_domains : +relay_to_domains + + + # Reject the recipient if it is not a valid mailbox. + # If the mailbox is not on our system (e.g. if we are a + # backup MX for the recipient domain), then perform a + # callout verification; but if the destination server is + # not responding, accept the recipient anyway. + # + deny + message = unknown user + domains = +local_domains + !domains = +relay_to_domains + !verify = recipient/callout=no_cache,10s,defer_ok + + # skip any further checks if the address is whitelisted + accept + condition = WHITELISTED + logwrite = From: $sender_address To: $local_part@$domain is whitelisted in sa_userpref + add_header = X-Whitelist-Flag: YES + + # skip any further checks if the address is already marked Junk (by DKIM) + accept + condition = ${if eq {$header_X-Junk-Flag:}{YES}} + logwrite = Skipping SPF/DNSBL/Greylist checks as message already failed DKIM + + ###################################################################### + # DNS checks + ###################################################################### + # + # The results of these checks are cached, so multiple recipients + # does not translate into multiple DNS lookups. + # + + # check whitelists + # a match will: + # add X-DNS-Whitelist header + # skip the rest of the checks (DNS blacklist/greylist, SPF) + +## as of Aug 2019 swl.spamhaus.org appears to be offline pending redesign +## list.dnswl.org does not work with large nameresolvers (over 100k queries / 24 hours) +## accept +## domains = +local_domains +## dnslists = swl.spamhaus.org : list.dnswl.org&0.0.0.2 +## logwrite = $sender_host_address is whitelisted in $dnslist_domain ${if def:dnslist_text {($dnslist_text)}}, adding X-DNS-Whitelist header +## add_header = X-DNS-Whitelist: $sender_host_address is listed in $dnslist_domain ${if def:dnslist_text {($dnslist_text)}} + + # add SPF header + accept + condition = ${run{/usr/bin/spfquery --scope mfrom \ + --identity ${quote:$sender_address} \ + --ip-address ${quote:$sender_host_address}} \ + {no}{${if eq {$runrc}{1}{yes}{no}}}} + add_header = Received-SPF: fail + add_header = X-Junk-Flag: YES +## log_message = SPF check failed. + + warn + condition = ${if eq {$runrc}{0}{yes}{no}} + add_header = Received-SPF: pass +## log_message = SPF check: pass + + warn + condition = ${if eq {$runrc}{2}{yes}{no}} + add_header = Received-SPF: softfail +## log_message = SPF check: softfail + + warn + condition = ${if eq {$runrc}{3}{yes}{no}} + add_header = Received-SPF: neutral +## log_message = SPF check: neutral + + warn + condition = ${if eq {$runrc}{4}{yes}{no}} + add_header = Received-SPF: permerror +## log_message = SPF check: permerror + + warn + condition = ${if eq {$runrc}{5}{yes}{no}} + add_header = Received-SPF: temperror + log_message = Temporary DNS error while checking SPF record. + + warn + condition = ${if eq {$runrc}{6}{yes}{no}} + add_header = Received-SPF: none +## log_message = SPF check: none + + warn + condition = ${if >{$runrc}{6}{yes}{no}} + log_message = Unexpected error in SPF check. spfquery returned $runrc + + # check DNSbl(s) and if found add header for filtering to Junk + accept +## condition = ${if and { \ +## { ! def:header_X-DNS-Whitelist: } \ +## { eq {$header_X-Whitelist-Flag:}{YES}} \ +## } {yes}{no}} + condition = ${if !eq {$header_X-Whitelist-Flag:}{YES}} + dnslists = zen.spamhaus.org + log_message = $sender_host_address is listed in $dnslist_domain ${if def:dnslist_text {($dnslist_text)}} + add_header = X-DNS-Blacklist: $sender_host_address is listed in $dnslist_domain ${if def:dnslist_text {($dnslist_text)}} + add_header = X-Junk-Flag: YES + + # will never get here if X-Whitelist-Flag or X-Junk-Flag (gets set with X-DNS-Blacklist) or X-DNS-Whitelist headers are set above +.ifdef GREYLIST_ENABLED + # if $sender_host_name is set use that. + # run command strips of leftmost subdomain if this is a third or higher level domain + warn + condition = ${if def:sender_host_name} + set acl_m_sender = ${run{/bin/bash /etc/exim4/return-resender.sh $sender_host_name}{$value}{$sender_host_name}} + # if $sender_host_name is not set use $sender_helo_name + # if sender_helo_name not set email was already rejected (deny) earlier in this acl + warn + condition = ${if !def:sender_host_name} + set acl_m_sender = $sender_helo_name + # bypass greylisting if the sending host is a known resender + accept + condition = ${lookup mysql{SELECT id FROM GREYLIST_RESENDERS_TABLE WHERE hostname = '${quote_mysql:$acl_m_sender}'}{yes}{no}} + condition = ${lookup mysql{UPDATE GREYLIST_RESENDERS_TABLE SET count=count+1, timestamp = NOW() WHERE hostname = '${quote_mysql:$acl_m_sender}'}{yes}{yes}} + add_header = X-DNS-Greylist: known resender + logwrite = skipping greylisting for $acl_m_sender due to match in GREYLIST_RESENDERS_TABLE + accept + hosts = +skip_greylisting_hosts + log_message = skipping greylisting due to match in skip_greylisting_hosts + defer + !senders = : postmaster@* + !hosts = +skip_greylisting_hosts + acl = greylist_acl + message = greylisted - try again later +.endif + + # Otherwise, the recipient address is OK. + # + accept + +# This access control list is used for message data received via +# SMTP. The tests are run in order until the recipient address +# is either accepted or denied. + +acl_data: + + # Add Message-ID if missing in messages received from our own hosts. + warn + condition = ${if !def:h_Message-ID: {1}} + hosts = : +relay_from_hosts + message = Message-ID: + + # add domain keys status header +# warn +# message = DomainKey-Status: $dk_status +# !condition = ${if eq{$dk_status}{}{1}{0}} + + # Accept mail received over local SMTP (i.e. not over TCP/IP). + # We do this by testing for an empty sending host field. + # Also accept mails received from hosts for which we relay mail. + # + accept + hosts = : +relay_from_hosts + + # Accept if the message arrived over an authenticated connection, from + # any host. + # + accept + authenticated = * + + # Enforce a message-size limit + # + #deny + # message = Message size $message_size is larger than limit of \ + # MESSAGE_SIZE_LIMIT + # condition = ${if >{$message_size}{MESSAGE_SIZE_LIMIT}{true}{false}} + + # skip any further checks if the address is already marked Junk + accept + condition = ${if eq {$header_X-Junk-Flag:}{YES}} + logwrite = Skipping header_syntax and header_sender checks as message already marked Junk + + # Deny unless the address list header is syntactically correct. + # Note that some specialized MTAs, such as certain mailing list + # servers, do not automatically generate a Message-ID for bounces. + # Thus, we add the check for a non-empty sender. + # (email feedback reports from aol fail this check) + #deny + accept + message = X-RFC2822-Error: Your message does not conform to RFC2822 standard + log_message = message header failed RFC2822 syntax check + !hosts = +relay_from_hosts + !senders = : postmaster@* + !verify = header_syntax + add_header = X-RFC2822-Error: Your message does not conform to RFC2822 standard + add_header = X-Junk-Flag: YES + + # Warn unless there is a verifiable sender address in at least + # one of the "Sender:", "Reply-To:", or "From:" header lines. + # + # + accept + message = X-Sender-Verify-Failed: No valid sender in message header + log_message = No valid sender in message header + !verify = header_sender + add_header = X-Sender-Verify-Failed: No valid sender in message header + add_header = X-Junk-Flag: YES + + # Deny if the message contains a virus. Before enabling this check, you + # must install a virus scanner and set the av_scanner option above. + +## accept +## condition = ${if ! def:header_X-Junk-Flag: } +## malware = */defer_ok +## log_message = This message contains a virus ($malware_name). +## add_header = X-Virus-Warning: This message contains a virus ($malware_name). +## add_header = X-Junk-Flag: YES + + # Accept the message. + # + accept + + +###################################################################### +# ROUTERS CONFIGURATION # +# Specifies how addresses are handled # +###################################################################### +# THE ORDER IN WHICH THE ROUTERS ARE DEFINED IS IMPORTANT! # +# An address is passed to each router in turn until it is accepted. # +###################################################################### + +begin routers + +autowhitelist_filter: + driver = redirect + domains = ! +local_domains + ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8 + condition = ${lookup mysql{SELECT vm_mboxes.id FROM vm_domains, vm_mboxes WHERE vm_domains.domain = "$sender_address_domain" AND vm_mboxes.mbox = "$sender_address_local_part" AND vm_domains.id = vm_mboxes.domain_id}} + check_local_user = false + user = Debian-exim + file = /etc/exim4/autowhitelist.filter + no_verify + unseen + allow_filter = true + +# This router routes addresses that are not in local domains by doing a DNS +# lookup on the domain name. Any domain that resolves to 0.0.0.0 or to a +# loopback interface address (127.0.0.0/8) is treated as if it had no DNS +# entry. Note that 0.0.0.0 is the same as 0.0.0.0/32, which is commonly treated +# as the local host inside the network stack. It is not 0.0.0.0/0, the default +# route. If the DNS lookup fails, no further routers are tried because of +# the no_more setting, and consequently the address is unrouteable. + +dnslookup: + driver = dnslookup + self = pass + transport = remote_smtp + ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8 + no_more + +# The remaining routers handle addresses in the local domain(s). + +junk_filter: + driver = accept + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + condition = ${if eq {$header_X-Junk-Flag:}{YES}} + condition = ${lookup mysql{SELECT vm_mboxes.id FROM vm_domains, vm_mboxes WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id}} + transport = junk_delivery + +spam_filter: + driver = accept + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + condition = ${if and { \ + { eq {$received_protocol}{spam-scanned}} \ + { eq {$header_X-Spam-Flag:}{YES}} \ + } {yes}{no}} + condition = ${lookup mysql{SELECT vm_mboxes.id FROM vm_domains, vm_mboxes WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id}} + transport = junk_delivery + +virtual_vacation: + driver = accept + domains = +local_domains + # do not reply to errors or lists or spam-scanned messages, require vacation message in db + condition = ${if and { \ + { !eq {$received_protocol}{spam-scanned}} \ + {!match {$h_precedence:} {(?i)junk|bulk|list}} \ + {!eq {$sender_address} {}} \ + { eq {${lookup mysql{SELECT vm_autoresponders.mode FROM vm_domains, vm_mboxes, vm_autoresponders WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_autoresponders.mbox_id = vm_mboxes.id AND vm_autoresponders.status='1'}{$value}fail}}{Vacation}} \ + } {yes} {no}} + # add options for start & end date fields + no_expn + # do not reply to errors and bounces or lists + senders = " ! ^.*-request@.*:\ + ! ^owner-.*@.*:\ + ! ^postmaster@.*:\ + ! ^listmaster@.*:\ + ! ^mailer-daemon@.*\ + ! ^root@.*" + transport = vacation_transport + unseen + no_verify + +virtual_autoresponder: + driver = accept + domains = +local_domains + # currently configured to *not* autorespond to + aliases + #local_part_suffix = +* + #local_part_suffix_optional = true + # do not reply to errors or lists or spam-scanned messages, require autoresponder message in db + condition = ${if and { \ + { !eq {$received_protocol}{spam-scanned}} \ + {!match {$h_precedence:} {(?i)junk|bulk|list}} \ + {!eq {$sender_address} {}} \ + { eq {${lookup mysql{SELECT vm_autoresponders.mode FROM vm_domains, vm_mboxes, vm_autoresponders WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_autoresponders.mbox_id = vm_mboxes.id AND vm_autoresponders.status='1'}{$value}fail}}{Autoresponder} } \ + } {yes} {no}} + # add options for start & end date fields + no_expn + # do not reply to errors and bounces or lists + senders = " ! ^.*-request@.*:\ + ! ^owner-.*@.*:\ + ! ^postmaster@.*:\ + ! ^listmaster@.*:\ + ! ^mailer-daemon@.*\ + ! ^root@.*" + transport = autoresponder_transport + unseen + no_verify + +virtual_forward: + driver = redirect + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + condition = ${if !eq {$received_protocol}{spam-scanned}} + data = ${lookup mysql{SELECT vm_forwards.forward_to FROM vm_domains, vm_mboxes, vm_forwards WHERE vm_domains.domain='${domain}' AND vm_domains.id = vm_mboxes.domain_id AND vm_mboxes.mbox='${local_part}' AND vm_mboxes.id=vm_forwards.mbox_id }} + unseen = ${lookup mysql{SELECT vm_forwards.id FROM vm_domains, vm_mboxes, vm_forwards WHERE vm_domains.domain='${domain}' AND vm_domains.id = vm_mboxes.domain_id AND vm_mboxes.mbox='${local_part}' AND vm_mboxes.id=vm_forwards.mbox_id AND vm_forwards.save_local='1'}{true}{false}} + +virtual_alias: + driver = redirect + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + condition = ${if !eq {$received_protocol}{spam-scanned}} + data = ${lookup mysql{SELECT CONCAT(vm_mboxes.mbox,'@${domain}') FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.alias='${local_part}' AND vm_aliases.mbox_id = vm_mboxes.id AND vm_mboxes.domain_id = vm_domains.id AND vm_domains.domain='${domain}'}} + +spamcheck_router: + driver = accept + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + condition = ${if and { \ + { !eq {$received_protocol}{spam-scanned}} \ + { !eq {$sender_address_domain}{$domain}} \ + { < {$message_size}{512k}} \ + { !eq {$header_X-Junk-Flag:}{YES}} \ + { !eq {$header_X-Whitelist-Flag:}{YES}} \ + { eq {${lookup mysql{SELECT vm_mboxes.status FROM vm_domains, vm_mboxes WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id}{$value}fail}}{1} } \ + } {yes} {no}} + # check domain & mbox 'status'? + # Check for other headers too? Blacklist, SPF, DKIM failers go directly to Spam folder without spam scan??? - actually they should go to spam folder before this router is hit? + headers_remove = X-Spam-Checker-Version:X-Spam-Flag:X-Spam-Level:X-Spam-Status:X-Spam-Score:X-Spam-Report + transport = spamcheck + +user_filter: + driver = redirect + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + data = ${lookup mysql{SELECT vm_filters.filter FROM vm_domains, vm_mboxes, vm_filters WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_mboxes.id = vm_filters.mbox_id }} + user = vmail + no_verify + no_expn + check_ancestor + allow_filter + file_transport = address_file + pipe_transport = address_pipe + reply_transport = address_reply + directory_transport = user_filter_maildir_delivery + allow_fail + +lmtp_localuser: + driver = accept + domains = +local_domains + local_part_suffix = +* + local_part_suffix_optional = true + condition = ${lookup mysql{SELECT vm_mboxes.id FROM vm_domains, vm_mboxes WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_mboxes.status = '1'}} + # add checks to query for domain & mbox being active + transport = dovecot_lmtp + cannot_route_message = Unknown user + +# This router handles aliasing using a linearly searched alias file with the +# name SYSTEM_ALIASES_FILE. When this configuration is installed automatically, +# the name gets inserted into this file from whatever is set in Exim's +# build-time configuration. The default path is the traditional /etc/aliases. +# If you install this configuration by hand, you need to specify the correct +# path in the "data" setting below. +# +##### NB You must ensure that the alias file exists. It used to be the case +##### NB that every Unix had that file, because it was the Sendmail default. +##### NB These days, there are systems that don't have it. Your aliases +##### NB file should at least contain an alias for "postmaster". +# +# If any of your aliases expand to pipes or files, you will need to set +# up a user and a group for these deliveries to run under. You can do +# this by uncommenting the "user" option below (changing the user name +# as appropriate) and adding a "group" option if necessary. Alternatively, you +# can specify "user" on the transports that are used. Note that the transports +# listed below are the same as are used for .forward files; you might want +# to set up different ones for pipe and file deliveries from aliases. + +system_aliases: + driver = redirect + domains = +local_domains + allow_fail + allow_defer + data = ${lookup{$local_part}lsearch{/etc/aliases}} +# user = exim + file_transport = address_file + pipe_transport = address_pipe + + +# This router handles forwarding using traditional .forward files in users' +# home directories. If you want it also to allow mail filtering when a forward +# file starts with the string "# Exim filter", uncomment the "allow_filter" +# option. + +# The no_verify setting means that this router is skipped when Exim is +# verifying addresses. Similarly, no_expn means that this router is skipped if +# Exim is processing an EXPN command. + +# The check_ancestor option means that if the forward file generates an +# address that is an ancestor of the current one, the current one gets +# passed on instead. This covers the case where A is aliased to B and B +# has a .forward file pointing to A. + +# The three transports specified at the end are those that are used when +# forwarding generates a direct delivery to a file, or to a pipe, or sets +# up an auto-reply, respectively. + +#userforward: +# driver = redirect +# check_local_user +# file = $home/.forward +# no_verify +# no_expn +# check_ancestor +## allow_filter +# file_transport = address_file +# pipe_transport = address_pipe +# reply_transport = address_reply + + +# This router matches local user mailboxes. + +#localuser: +# driver = accept +# check_local_user +# transport = local_delivery + + + +###################################################################### +# TRANSPORTS CONFIGURATION # +###################################################################### +# ORDER DOES NOT MATTER # +# Only one appropriate transport is called for each delivery. # +###################################################################### + +# A transport is used only when referenced from a router that successfully +# handles an address. + +begin transports + +# This transport is used for delivering messages over SMTP connections. + +remote_smtp: + driver = smtp + dkim_domain = ${lc:${domain:$h_from:}} + dkim_canon = relaxed + dkim_selector = ${if exists{/etc/ssl/dkim/${dkim_domain}.selector}{${readfile{/etc/ssl/dkim/${dkim_domain}.selector}{}}}{0}} + dkim_private_key = ${if exists{/etc/ssl/dkim/${dkim_domain}.pem}{/etc/ssl/dkim/${dkim_domain}.pem}{0}} + +# This transport is used for local delivery to user mailboxes in traditional +# BSD mailbox format. By default it will be run under the uid and gid of the +# local user, and requires the sticky bit to be set on the /var/mail directory. +# Some systems use the alternative approach of running mail deliveries under a +# particular group instead of using the sticky bit. The commented options below +# show how this can be done. + +local_delivery: + driver = appendfile + file = /var/mail/$local_part + delivery_date_add + envelope_to_add + return_path_add + group = vmail + mode = 0660 + +dovecot_lmtp: + driver = lmtp + socket = /run/dovecot/lmtp + #return_path_add + #maximum number of deliveries per batch, default 1 + #batch_max = 200 + #allow suffixes/prefixes (default unset) + #rcpt_include_affixes + +#local_delivery: +# driver = appendfile +## file = /var/vmail/$local_part +# maildir_format = true +# directory = /home/$local_part/Maildir +# create_directory +# directory_mode = 770 +# delivery_date_add +# envelope_to_add +# return_path_add +# user = $local_part +# group = $local_part +# mode = 0660 + +## for vacation mail +vacation_transport: + driver = autoreply + log = /var/vmail/${domain}/${local_part}/vacation_log + once = /var/vmail/${domain}/${local_part}/vacation_once_db + return_path = ${local_part}@${domain} + to = ${sender_address} + from = ${local_part}@${domain} +# subject = ${lookup mysql{SELECT subject FROM vm_autoresponder WHERE local_part='${local_part}' AND domain='${domain}'}{$value}{"Auto Reply"}} +# text = ${lookup mysql{SELECT message FROM vm_autoresponder WHERE local_part='${local_part}' AND domain='${domain}'}{$value}fail} + subject = ${lookup mysql{SELECT vm_autoresponders.subject FROM vm_domains, vm_mboxes, vm_autoresponders WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_autoresponders.mbox_id = vm_mboxes.id}{$value}{"Auto Reply"}} + text = ${lookup mysql{SELECT vm_autoresponders.body FROM vm_domains, vm_mboxes, vm_autoresponders WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_autoresponders.mbox_id = vm_mboxes.id}{$value}fail} + user = vmail + +## for autoresponder +autoresponder_transport: + driver = autoreply + log = /var/vmail/${domain}/${local_part}/autoresponder_log + return_path = ${local_part}@${domain} + to = ${sender_address} + from = ${local_part}@${domain} + subject = ${lookup mysql{SELECT vm_autoresponders.subject FROM vm_domains, vm_mboxes, vm_autoresponders WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_autoresponders.mbox_id = vm_mboxes.id}{$value}{"Auto Reply"}} + text = ${lookup mysql{SELECT vm_autoresponders.body FROM vm_domains, vm_mboxes, vm_autoresponders WHERE vm_domains.domain='${domain}' AND vm_mboxes.mbox='${local_part}' AND vm_domains.id = vm_mboxes.domain_id AND vm_autoresponders.mbox_id = vm_mboxes.id}{$value}fail} + user = vmail + +maildir_delivery: + driver = appendfile + maildir_format + directory = /var/vmail/${domain}/${local_part}/Maildir + create_directory + directory_mode = 750 + user = vmail + +user_filter_maildir_delivery: + driver = appendfile + maildir_format + user = vmail + +junk_delivery: + driver = appendfile + maildir_format + directory = /var/vmail/${domain}/${local_part}/Maildir/.Junk + create_directory + directory_mode = 750 + user = vmail + +# SpamAssassin +spamcheck: + driver = pipe + command = /usr/sbin/exim -oMr spam-scanned -bS + use_bsmtp = true + transport_filter = /usr/bin/spamc -f -u $local_part@$domain + home_directory = "/tmp" + current_directory = "/tmp" + # must use a privileged user to set $received_protocol on the way back in! + user = mail + group = mail + log_output = true + return_fail_output = true + return_path_add = false + message_prefix = + message_suffix = + +# clamav +#clamav_scan +# driver = pipe +# command = /usr/bin/clamdscan +# user = clamav +# user_bsmtp = true + +# This transport is used for handling pipe deliveries generated by alias or +# .forward files. If the pipe generates any standard output, it is returned +# to the sender of the message as a delivery error. Set return_fail_output +# instead of return_output if you want this to happen only when the pipe fails +# to complete normally. You can set different transports for aliases and +# forwards if you want to - see the references to address_pipe in the routers +# section above. + +address_pipe: + driver = pipe + return_output + + +# This transport is used for handling deliveries directly to files that are +# generated by aliasing or forwarding. + +address_file: + driver = appendfile + delivery_date_add + envelope_to_add + return_path_add + + +# This transport is used for handling autoreplies generated by the filtering +# option of the userforward router. + +address_reply: + driver = autoreply + + + +###################################################################### +# RETRY CONFIGURATION # +###################################################################### + +begin retry + +# This single retry rule applies to all domains and all errors. It specifies +# retries every 15 minutes for 2 hours, then increasing retry intervals, +# starting at 1 hour and increasing each time by a factor of 1.5, up to 16 +# hours, then retries every 6 hours until 4 days have passed since the first +# failed delivery. + +# Domain Error Retries +# ------ ----- ------- + +* * F,2h,15m; G,16h,1h,1.5; F,4d,6h + + + +###################################################################### +# REWRITE CONFIGURATION # +###################################################################### + +# There are no rewriting specifications in this default configuration file. + +begin rewrite + + + +###################################################################### +# AUTHENTICATION CONFIGURATION # +###################################################################### + +# There are no authenticator specifications in this default configuration file. + +begin authenticators + +dovecot_login: + driver = dovecot + public_name = LOGIN + server_socket = /run/dovecot/auth-client + server_set_id = $auth1 + +dovecot_plain: + driver = dovecot + public_name = PLAIN + server_socket = /run/dovecot/auth-client + server_set_id = $auth1 + +# End of Exim configuration file diff --git a/etc/exim4/exim_local.conf b/etc/exim4/exim_local.conf new file mode 100644 index 0000000..8da0cbe --- /dev/null +++ b/etc/exim4/exim_local.conf @@ -0,0 +1,16 @@ +qualify_domain = example.com + +hide mysql_servers = localhost/vmail/vmail/password + +# comment out to disable Greylisting +GREYLIST_ENABLED= + +# only use 1 of the following at a time: +# disable for now as clamav is not currently enabled +#VIRUS_WARN= +#VIRUS_DENY= + +# Uncomment and change values to override defaults already in main config +#smtp_accept_max = 50 +#smtp_accept_max_per_host = 10 +#smtp_accept_queue_per_connection = 50 diff --git a/etc/exim4/return-resender.sh b/etc/exim4/return-resender.sh new file mode 100644 index 0000000..1007a85 --- /dev/null +++ b/etc/exim4/return-resender.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +HOSTNAME=$1 + +COUNT=`/bin/echo $HOSTNAME|/bin/grep -o '\.'|/usr/bin/wc -l` + +if [ "$COUNT" -lt '2' ]; then + # second level domain, don't munge just return + /bin/echo -n $HOSTNAME + exit 0 +elif [ "$COUNT" -ge '2' ]; then + # third or higher level domain, strip first level off + /bin/echo -n "$HOSTNAME" | /bin/sed 's/[^.]*./\*\./' + exit 0 +else + # unexpected. hostname not set? + /bin/echo -n $HOSTNAME + exit 0 +fi diff --git a/etc/exim4/skip_greylisting_hosts b/etc/exim4/skip_greylisting_hosts new file mode 100644 index 0000000..1ebf7d2 --- /dev/null +++ b/etc/exim4/skip_greylisting_hosts @@ -0,0 +1 @@ +*.example.com diff --git a/etc/spamassassin/local.cf b/etc/spamassassin/local.cf new file mode 100644 index 0000000..5b03543 --- /dev/null +++ b/etc/spamassassin/local.cf @@ -0,0 +1,112 @@ +# This is the right place to customize your installation of SpamAssassin. +# +# See 'perldoc Mail::SpamAssassin::Conf' for details of what can be +# tweaked. +# +# Only a small subset of options are listed below +# +########################################################################### + +add_header all Score _HITS_ +version_tag config-v1.0 + +# Add *****SPAM***** to the Subject header of spam e-mails +# +# rewrite_header Subject *****SPAM***** + + +# Save spam messages as a message/rfc822 MIME attachment instead of +# modifying the original message (0: off, 2: use text/plain instead) +# +report_safe 0 + + +# Set which networks or hosts are considered 'trusted' by your mail +# server (i.e. not spammers) +# +# trusted_networks 212.17.35. + + +# Set file-locking method (flock is not safe over NFS, but is faster) +# +# lock_method flock + + +# Set the threshold at which a message is considered spam (default: 5.0) +# +# required_score 5.0 + + +# Use Bayesian classifier (default: 1) +# +# use_bayes 1 + + +# Bayesian classifier auto-learning (default: 1) +# +# bayes_auto_learn 1 + + +# Set headers which may provide inappropriate cues to the Bayesian +# classifier +# +# bayes_ignore_header X-Bogosity +# bayes_ignore_header X-Spam-Flag +# bayes_ignore_header X-Spam-Status + + +# Whether to decode non- UTF-8 and non-ASCII textual parts and recode +# them to UTF-8 before the text is given over to rules processing. +# +# normalize_charset 1 + +# Textual body scan limit (default: 50000) +# +# Amount of data per email text/* mimepart, that will be run through body +# rules. This enables safer and faster scanning of large messages, +# perhaps having very large textual attachments. There should be no need +# to change this well tested default. +# +# body_part_scan_size 50000 + +# Textual rawbody data scan limit (default: 500000) +# +# Amount of data per email text/* mimepart, that will be run through +# rawbody rules. +# +# rawbody_part_scan_size 500000 + +# Some shortcircuiting, if the plugin is enabled +# +ifplugin Mail::SpamAssassin::Plugin::Shortcircuit +# +# default: strongly-whitelisted mails are *really* whitelisted now, if the +# shortcircuiting plugin is active, causing early exit to save CPU load. +# Uncomment to turn this on +# +# SpamAssassin tries hard not to launch DNS queries before priority -100. +# If you want to shortcircuit without launching unneeded queries, make +# sure such rule priority is below -100. These examples are already: +# +# shortcircuit USER_IN_WHITELIST on +# shortcircuit USER_IN_DEF_WHITELIST on +# shortcircuit USER_IN_ALL_SPAM_TO on +# shortcircuit SUBJECT_IN_WHITELIST on + +# the opposite; blacklisted mails can also save CPU +# +# shortcircuit USER_IN_BLACKLIST on +# shortcircuit USER_IN_BLACKLIST_TO on +# shortcircuit SUBJECT_IN_BLACKLIST on + +# if you have taken the time to correctly specify your "trusted_networks", +# this is another good way to save CPU +# +# shortcircuit ALL_TRUSTED on + +# and a well-trained bayes DB can save running rules, too +# +# shortcircuit BAYES_99 spam +# shortcircuit BAYES_00 ham + +endif # Mail::SpamAssassin::Plugin::Shortcircuit diff --git a/etc/spamassassin/sql.cf b/etc/spamassassin/sql.cf new file mode 100644 index 0000000..d0f8547 --- /dev/null +++ b/etc/spamassassin/sql.cf @@ -0,0 +1,4 @@ +user_scores_dsn DBI:mysql:vmail:localhost:3306 +user_scores_sql_password password +user_scores_sql_username vmail +user_scores_sql_custom_query SELECT preference, value FROM sa_userpref WHERE username = _USERNAME_ OR username = '$GLOBAL' OR username = CONCAT('%',_DOMAIN_) ORDER BY username ASC