Query postfix for maildir

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Query postfix for maildir

Mark O'Dell

Hi,

 

I have searched but can’t find this anywhere, is there a command that will return the maildir(s) that a given address will deliver to?

 

I have a folder with thousands of emails (it’s a journal from another server) in it and I want to distribute them to the appropriate maildir based on the intended recipients.  I have pretty much written a PHP script that queries MySQL and find this information, but it seems to be a bit inefficient when Postfix already has the ability and is presumably faster than my PHP.

 

At the same time, possibly off topic, is there a better way of writing this email to the new maildir than using PHP?

 

Running Fedora 6 and postfix 2.3.3 with dovecot.

 

Many Thanks

Mark

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Query postfix for maildir

/dev/rob0
On Tue May 20 2008 10:50:31 Mark O'Dell wrote:
> I have searched but can't find this anywhere, is there a command that
> will return the maildir(s) that a given address will deliver to?

That depends entirely on the delivery agent in use. Postfix delivery
agents local(8) and virtual(8) are different. For non-Postfix delivery
agents, see the documentation therefor.

Since you said "MySQL" I'll guess you might be using virtual(8). The
combined output of "postconf -h virtual_mailbox_base" and "postmap -q
[hidden email] mysql:/path/to/your/virtual_mailbox_maps/query" would
do it.

> I have a folder with thousands of emails (it's a journal from another
> server) in it and I want to distribute them to the appropriate
> maildir based on the intended recipients.  I have pretty much written

How did you determine the intended recipient?

> a PHP script that queries MySQL and find this information, but it
> seems to be a bit inefficient when Postfix already has the ability
> and is presumably faster than my PHP.

I wouldn't think so, at least not in any significant way.

> At the same time, possibly off topic, is there a better way of
> writing this email to the new maildir than using PHP?

Redirection?
--
    Offlist mail to this address is discarded unless
    "/dev/rob0" or "not-spam" is in Subject: header
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Query postfix for maildir

Mark O'Dell

OK, so I have used taken that and used passed both the mailboxes and
aliases to it which returns when it is found in either, but it doesn't
return anything when I have a *@domain.co.uk used?

postmap -q [hidden email]
'mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf'
'mysql:/etc/postfix/mysql_virtual_alias_maps.cf'

I can then just look it passing back each address until it gives me a
maildir, not an email address(es).  But I am staring to think you might
be right about it not being any better than just writing my own PHP,
especially as I need to wrap this in something to read out the addresses
anyway

>How did you determine the intended recipient?
Parsing the headers of the email, not perfect as I doesn't allow BCC's
etc. but good enough for my needs





-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of /dev/rob0
Sent: 20 May 2008 17:16
To: [hidden email]
Subject: Re: Query postfix for maildir

On Tue May 20 2008 10:50:31 Mark O'Dell wrote:
> I have searched but can't find this anywhere, is there a command that
> will return the maildir(s) that a given address will deliver to?

That depends entirely on the delivery agent in use. Postfix delivery
agents local(8) and virtual(8) are different. For non-Postfix delivery
agents, see the documentation therefor.

Since you said "MySQL" I'll guess you might be using virtual(8). The
combined output of "postconf -h virtual_mailbox_base" and "postmap -q
[hidden email] mysql:/path/to/your/virtual_mailbox_maps/query" would
do it.

> I have a folder with thousands of emails (it's a journal from another
> server) in it and I want to distribute them to the appropriate
> maildir based on the intended recipients.  I have pretty much written

How did you determine the intended recipient?

> a PHP script that queries MySQL and find this information, but it
> seems to be a bit inefficient when Postfix already has the ability
> and is presumably faster than my PHP.

I wouldn't think so, at least not in any significant way.

> At the same time, possibly off topic, is there a better way of
> writing this email to the new maildir than using PHP?

Redirection?
--
    Offlist mail to this address is discarded unless
    "/dev/rob0" or "not-spam" is in Subject: header
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Query postfix for maildir

mouss-2
Mark O'Dell wrote:
> OK, so I have used taken that and used passed both the mailboxes and
> aliases to it which returns when it is found in either, but it doesn't
> return anything when I have a *@domain.co.uk used?
>
> postmap -q [hidden email]
> 'mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf'
> 'mysql:/etc/postfix/mysql_virtual_alias_maps.cf'
>  

Please do not top post. Google if you don't know what this means.

postmap does only one query. you need to repeat what postfix does.

for example:

# postmap -q [hidden email] mysql:$path/virtual_alias_maps.cf
# postmap -q @example.com mysql:$path/virtual_alias_maps.cf

# postmap -q [hidden email] mysql:$path/virtual_mailbox_maps.cf
# postmap -q @example.com mysql:$path/virtual_mailbox_maps.cf


and do it one map at a time. more precisely, you'll need to "recurse" in
virtual_alias_maps if necessary (if an alias redirects to an alias... etc).

> I can then just look it passing back each address until it gives me a
> maildir, not an email address(es).  But I am staring to think you might
> be right about it not being any better than just writing my own PHP,
> especially as I need to wrap this in something to read out the addresses
> anyway
>
>  

one possibility is to a find a way to get the "original" recipient and
the original sender, and use sendmail to submit the messages (you may
need to strip a delivered-To header so that postfix does not think there
is a loop).

The original sender should be found in the return-Path header. if you
are lucky, the original recipient is in the Delivered-To header, but
this depends how the messages were delivered.

>> How did you determine the intended recipient?

> Parsing the headers of the email, not perfect as I doesn't allow BCC's
> etc. but good enough for my needs

This is broken. you may be delivering mail to people who were not to receive them.

check if there is a Delivered-To header (or equivalent) and use it.









Loading...