Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I select or control the format of the input key?

Status
Not open for further replies.

stenton

IS-IT--Management
Sep 2, 2011
2
IE
Hi,

I have recently configured a postfix mail server to use mysql for aliases. It seems to be most, but not all, of what I want.

using the above, I can have mail sent to webmaster@mydomain.com forwarded to me@gmail.com. Which is nifty.

However, I am hosting a number of domains on the server, and I want to be able to set up a different alias for webmaster@otherdomain.com be sent to a different address.

So far, it seems that the input key '%s' only contains "webmaster", and so I am unable to distinguish between them. I need to be able to map my aliases depending on the full mail address, including domain.

The manual offers the following advice:

%s This is replaced by the input key. SQL
quoting is used to make sure that the input
key does not add unexpected metacharacters.

%u When the input key is an address of the form
user@domain, %u is replaced by the SQL
quoted local part of the address. Other-
wise, %u is replaced by the entire search
string. If the localpart is empty, the
query is suppressed and returns no results.

%d When the input key is an address of the form
user@domain, %d is replaced by the SQL
quoted domain part of the address. Other-
wise, the query is suppressed and returns no
results.

My problem appears to be that the input key used is not of the form "user@domain.com", but rather is of the form "user". How can I set the format of the input key to be "user@domain.com"? I couldn't see that anywhere.

Thanks in advance.
 
There are a couple of places that can effect this. First, you could have a SQL configuration file with the select statement. I think you would want a statement like the following:
Code:
#query = SELECT goto FROM alias WHERE address='%u' AND active = '1'

In my installation, which hosts multiple virtual domains via SQL lookup and the ID is user@domain, this line has been commented out. Instead, I believe the lookup is done via Dovecot (SASL Authentication). Here is the line from my dovecot configuration. As you notice, the user is %u, but in the select statement there is also the %d and %n and I am pretty sure the %d is the domain.

What this is telling me is that you may need a concat statement to put together the whole thing. When this is done, though, the maildir format must match and will be per domain with users underneath.

Here is my example:
Code:
user_query = SELECT '/var/vmail/%d/%n' as home, 'maildir:/var/vmail/%d/%n' as user, 5555 AS uid, 13 AS gid, concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
 
Thanks for your time Noway2,

But I may not have expressed myself properly. My issue is not pon the SQL end. I know the query I want to run. My problem is that, when it comes to the different alises of 'webmaster@domain1.com' and 'webmaster@domain2.com', %s is only populated with 'webmaster', and %u and %d are both blank, so far as I can tell, making it impossible to determine which webmaster the mail was intended for.

The manual, as I quoted, seems to suggest that the "input key" which is used to populate %s, %u and %d, can either be in the form 'user@domain' or just 'user'. In my case, it appears that it is just 'user'.

I just need to know how to control how the "Input key" is filled. If that is populated with the full domain, then the %s, %u and %d variables get populated, and writing the query is straightforward.

I have looked through the manuals and config files, but have failed to find any options which control this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top