-
-
Notifications
You must be signed in to change notification settings - Fork 3
vdelivermail.8
vdelivermail - deliver mails to users in a virtual domain
vdelivermail [""] [default account]
vdelivermail delivers mails to users created (by vadddomain(1)) in a virtual domain. vdelivermail is called by qmail-local through an instruction in the file .qmail-default present in /var/indimail/domains directory. vdelivermail is the MDA for IndiMail. Along with a wrapper postdel, vdelivermail can also be used as the MDA for postfix. qmail-local sets the environment variables EXT and HOST. This is used by vdelivermail to set the user and the domain component of the email address. For postfix, these two environment variables are set by postdel. If the username is quoted, the quotes are removed. The user@domain is then searched in the authentication database. If there are any system problems due to which vdelivermail is unable to locate the user, it exits 111 and the mail gets deferred. vdelivermail will exit 100 in case the user is not found, locked/overquota, address is looping, or if vdelivermail is not called correctly. Bounces can be discarded if you set the environment variable DISCARD_BOUNCE. If BOUNCE_MAIL is set, vdelivermail bounces the mail. If the domain is a clustered domain, vdelivermail attempts to find the mailstore for the user. If the mailstore is local, it delivers the mail locally. If the mailstore is a remote server, it invokes qmail-remote(8) to deliver the mail. If the environment variable QMAIL_EXT is defined, vdelivermail attempts to locate the username based on qmail Extensions.
If the user is not found or user is found but is inactive, action taken is as per delivery instruction (third argument to vdelivermail). If the user is active, vdelivermail checks for any forward delivery (including aliases) and delivers appropriately. While delivering, vdelivermail creates the inbox (Maildir format) if the directories do not exist. vdelivermail defers the mail if stick bit is set on the Maildir to which the mail is being delivered.
vdelivermail adds the following headers on delivery of the mail to a Maildir
Delivered-To: specifying the address to which the mail has been delivered
[step]
Return-Path: specifying the sender's email address.
[step]
X-Filter: specifying if the mail has been filtered through vfilter.
[step]
Received: specifying the date and time, the mail was received and
delivered.
vdelivermail looks up the qmail control files blackholedsenders and blackholedpatterns. If the sender's email address matches an entry in these control files, vdelivermail discards the mail without bouncing the mail to the sender. A line in these files may be of the form @host, meaning every address at host. These files are also used by qmail-smtpd causing SMTP sessions to get blackholed.
blackholedpatterns gives qmail-smtpd the ability to blackhole E-Mails by comparing the sender address with a REGEX pattern in blackholedpatterns. Example:
*@earthlink.net !fred@earthlink.net [0-9][0-9][0-9][0-9][0-9]@[0-9][0-9][0-9].com answerme@save* *%*
blackholedpatterns file with this contents stops all mail from earthlink except from fred@earthlink.net. It also stops all mail with addresses like: 12345@123.com and answerme@savetrees.com. Further, any E-Mail with a sender address containing a percent sign (%) is rejected.
vdelivermail uses Maildir++ specification. Maildir++ quota relies on maildirsize file having correct information, so if your users can modify the file in some way (e.g. shell access), you're relying on the goodwill of your users for the quota to work. As a trade-off between accuracy and performance quota recalculation happens when the size of maildirsize file reaches 8192 bytes or update time is more than 43200 seconds. The defaults 8192 and 43200 can be changed by setting MAILDIRSIZE_MAX_SIZE & MAILDIRSIZE_MAX_AGE environment variales. The vuserinfo(1) command on a user can also be used to recalculate the quota.
The maildirsize file in the Maildir root directory contains both the quota limit information and the current quota status. It contains a header in format:
<storage limit in bytes>S,<message count limit>C
If the size of the mail is within the quota, or if the size of the mail is less than OVERQUOTA_MAILSIZE (1000 bytes as defined in indimail.h), but would bring the user overquota, the mail is delivered and the user's current quota usage updated. Else the mail is bounced back with Over Quota message. Also if /usr/libexec/indimail/overquota.sh exists, the command is executed with the following arguments
maildir_path Message_size Current_disk_usage Current_mailcount quota
The command overquota.sh can be changed by setting the environment variable OVERQUOTA_CMD. The default behaviour of bouncing mails on overquota can be changed by setting environment variable HOLDOVERQUOTA or by having a file holdoverquota in the user's homedir. In this case, the mail will be deferred till the queuelifetime gets reached. If HOLDOVERQUOTA is not defined and neither the file holdoverquota is present vdelivermail (if the user is already above quota) sets the BOUNCE FLAG for the user. Subsequent deliveries are bounced without any quota checking. Setting of the BOUNCE_FLAG reduces the load on the server when multiple mails are being sent to an overquota user. The BOUNCE FLAG is removed only after the user logs in and clears the mails to reduce the quota usage. Site administrators can customize Over Quota Bounce messages, by setting environment variables QUOTAWARN1, QUOTAWARN2 ... upto QUOTAWARN10. These variables should be set to a percentage quota usage for which warning should be sent. In addition to the EXT and HOST environment variable, RPLINE and DTLINE variables are also used by vdelivermail to set the value for Return-Path, Delivered-To lines in the mail headers.
The quota limit for a user can be set by the administrator either in size, number of mails or combination of both. e.g. 40000,2000S means quota of 40000 Bytes and 2000 mails. Administrator can use either vsetuserquota or vmoduser programs.
Additionally per day limit on deliveries per user can be set by specifying the environment variable MAILCOUNT_LIMIT and MAILSIZE_LIMIT. This can be set in the qmail-send run file to limit the daily quota of number of emails, size of emails or both. If the number of deliveries for a user exceeds this number, the mail is bounced back to the sender with over quota message.
One can use vmoduser(1) to turn on delivery to a date folder. If this option is turned on, emails can be delivered to a folder based on the current timestamp. This option is useful if you want to deliver mails based on the year, month, week, etc. vdelivermail(8) uses strftime(3) to process the date format for the folder. The file folder.dateformat in user's Maildir is used for storing the date format for the folder.
Every virtualdomain get's it's own directory under /var/indimail/domains. qmail's user/assign file gets an entry for each domain that points qmail-local deliveries into this directory. Therefore, all normal .qmail file processing works in each virtual domain. .qmail files just need the user name extension to work, i.e. .qmail-joe for user joe. ezmlm uses
If no user matches a .qmail file then the .qmail-default file is processed. This file contains invokation of vdelivermail program with arguments. vdelivermail reads the authentication database and delivers the mail into the users directory. The last parameter of vdelivermail determines what vdelivermail does when it does not find the user. See the section on Options below.
In addition to .qmail files, IndiMail has its dot-qmail processing called valias. valias can be either the file .qmail in the user's home directory or an entry made in MySQL(1) using the valias(1) program. You can have multiple delivery lines in .qmail or valias entries in MySQL(1). vdelivermail will skip processing valias lines, if a line causes exit code of 99 to be returned.
vdelivermail sends alerts in the form of UDP packets to a host and port which can be specified in the following two ways
By defining environment variables MAILHOST_ALERT and MAILHOST_PORT.
[step]
By creating a file mailalert.cfg in the control directory. The first
line of this file should have the line host x.x.x.x where x.x.x.x is an
IP address. The second line of this file should have the line port
port_num where port_num is an integer.
You can discard duplicate emails by setting ELIMINATE_DUPS environment variable. You can change the default time interval of 900 seconds by setting the ELIMINATE_DUPS_INT environment variable in seconds. You need to have the environment variable MAKESEEKABLE set for duplicate elimination to work. The duplicate elimination works exactly like ismaildup(1) and uses the same code.
vdelivermail uses 822header(1) to get the headers and calculate 32 character md5sum of the headers. It excludes the Received and Delivered-To headers from the md5sum calculation. The result is written to the file dir/dupmd5 in the following format.
unix_time md5sum
vdelivermail automatically updates the dupmd5 file with the latest timestamps, expired records are automatically removed. Hence there is no maintenance required for this file. ismaildup uses uses the following command to get the headers for md5sum calculation.
/usr/bin/822header -X Received -X Delivered-To -X X-Delivered-To
You can set ELIMINATE_DUPS_ARGS environment variable to set your own program and arguments for md5sum computation. The below command will use 822header program and use just the Subject and Date headers to decide if the mail is a duplicate.
/usr/bin/822header -I Subject -I Date
[""]
Blank double quote for backward compatibility
[default account for delivery]
If email does not match any virtual domain user (determined by EXT
and HOST environment variable, this is the default delivery
instructions. This may be one of the four values given below.
Full path to a indimail user directory
[step]
email address to forward email to
[step]
the string bounce-no-mailbox to bounce the email back to the sender.
[step]
the string delete to delete the email.
[step]
Address in SMTPROUTE format to which vdelivermail should use
SMTP to deliver the mail. e.g.
indimail.org:192.168.1.1:25
where indimail.org is the local domain, 192.168.1.1 is the IP address of an SMTP server for indimail.org and 25 is the SMTP port.
If IndiMail is configured for hard quotas (default is yes with 5 Mb quota), then the size of the user's current usage Maildir/new and Maildir/cur directories and other folders (excluding Trash) are counted and added to maildirsize. vdelivermail recalculates once maildirsize reaches 512 bytes. This ensures that quota is as accurate as possible even if files are deleted externally. If the user is over quota the email is bounced back to the user with a bounce message that can be customized (See the section 'Quota Checking' above. If the message is 1Kbytes or smaller the email will always be delivered. This allows system administration programs to always get a message through to the user.
- 0 if all steps were successful.
- 100 for permanent errors. i.e. if user is over quota or bounce-no-mailbox is set and no matching user is found.
- 111 for all temporary error occurs during mail delivery and without the error, the mail would have got delivered
vmoduser(1), vsetuserquota(1), vlimit(1), qmail-lspawn(8), spawn-filter(8), qmail-local(8), qmail-remote(8), maildirdeliver(1), ismaildup(1), strftime(3)