home (Japanese only ;-))

remove-prepend patch for qmail

A patch for netqmail-1.05. I think it can be aplied for netqmail-1.06, I've not tried yet. And I thought it's not necessary so much, after I'd finished to write this article.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND WITHOUT ANY WARRANTIES.

BEFORE using the patch, READ preamble of the patch.

netqmail-1.05-removeprepend-0.1.patch

In qmail, If you specify forwarding a mail in ~user/.qmail, and if ~user/.qmail-owner exists, the envelope sender is modified to the form user-owner@example.jp. This address is controlled by ~user/.qmail-owner, and is created by the result of existing -owner file, so this address is alaways deliverable.

On the other hand, if user@virtual.domain is matched to control/virtualdomains controll file, prepend- is added to the local part of the receipient address. This mail will be delivered user prepend and controlled by ~prepend/.qmail-user.

In this case, if you specify forwarding in ~prepend/.qmail-user and ~prepend/.qmail-user-owner exists, the envelope sender address is modified to prepend-user-owner@virtual.domain. A mail sent to this address is matched to control/virtualdomains agian, and prefix is added once more, qmail tries to deliver the mail to prepend-prepend-user-owner@virtual.domain. This address is controlled by ~prepend/.qmail-prepend-user-owner, but this file doesn't exist in usual case, so this mail cannot be delivered.

The envelope sender is modified by qmail-local. I think it is preferrable that qmail-local removes prepend- part based on control/virtualdomains when qmail-local modifies the address. This patch uses a file named as control/removeprepend, so that you can apply some domains you choose, or you can avoid problems which occur in the operation. The same prefixed address is written to Delivered-To: header field. If the file control/removeprependdt exists, this patch will also remove the prefix from the address in the Delivered-To: header field in the same manner.

The formats of control/removeprepend and control/removeprependdt are completely same as control/virtualdomains'. So, if you want to apply all virtual users and domains, all you need is to create symbolic links to control/virtualdomains.

There is a limitation. This facility works quite well for virtual domains. But not for virtual users. For example, if control/virtualdomains has lines like this:

actual-user@virtual.domain:real
user@virtual.domain:real-actual

Mails which are sent to both virtual users are delivered to same address real-actual-user@virtual.domain. If so, we cannot deicde which rule was used to append prefix. The patch compares the delivered address against each line of control/removeprepend from following positions:

in this order. In this case, the rule actual-user@virtual.domain:real is always used, and the envelope sender address is always rewritten to actual-user-owner@virtual.domain, although the recipient address was user@virtual.domain.

The entire address is checked only against the exception rules of virtual users. If the entire address is matched and the rule is not an exception, in other words, the rule has prepend part, this address will be rewritten to "prepend-the-entire-address@and.the.domain". However, the address which is checked just now is the address without prepend part "the-entire-address@and.the.domain", so there is no case that the address matched to the rule. It's meaningless to check the entire address against virtual users which are not exceptions.

The domain part is not modified, virtual domain rules which was used at delivery certainly matches in qmail-local at forwarding. If not matched at delivery, It doesn't match at forwarding. So prepend- part is removed exactly in case of virtual domains, if specified so in control/removeprepend.

In case of forwarding, you can receive mails to the addresses like user-owner@some.domain just touching .qmail-owner file. In contrast, if you want to receive mails to the virtual user addresses like virtual-user-owner@virtual.domain for virtual-user@virtual.domain, notice that you need to add some rules (virtual users for -owner addresses, or qmail-users functionality) for the addresses.

The environment variables LOCAL and RECIPIENT passed to the command invoked from .qmail are set to the address with prepend- part. This behavior is same as the original. On the other hand, NEWSENDER and DTLINE are set to the address without prepend part if the address is matched to removeprepend or removeprependdt, respectively.

Even without this patch, You can remove prepend part by using qmail-inject with -f option in ~prepend/.qmail-user. If you want to forward a mail to several addresses after removing prepend- part, modify envelope sender address by qmail-inject with -f option and forward to the local address for the deliverly, then list up the addresses to forward to the .qmail for the deliverly address. This is similar to the mailing list.

Copyright (C) 2011 You SUZUKI

$Id: remove-prepend.en.htm,v 1.1 2011/08/27 14:12:43 you Exp $