Re: [Exim] Redirecting mail to a Maildir subdirectory

Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Greg Ward
Fecha:  
A: Derek Broughton
Cc: exim-users
Asunto: Re: [Exim] Redirecting mail to a Maildir subdirectory
On 29 November 2001, Derek Broughton said:
> I'd like to search $header_subject: for "\[.*\]" and, if found, write
> the message to ~/Maildir/.$subdir (where $subdir is what was found
> between the brackets). I'd like it even better, if it would just fall
> through to ~/Maildir if .$subdir doesn't exist.


Obviously, you need to write a filter to do this. But you don't want
this done by a *system* filter, because that runs once on a message with
possibly many recipients. You need a per-user filter, but you might not
want to put it in the user's ~/.forward, because then it's out of your
control. The solution is a director that runs if the local-part
corresponds to a local user and that runs the same per-user filter for
all messages and all recipients.

Try this: add this director to exim.conf:

  central_filter:
    driver = forwardfile
    file_transport = address_file
    pipe_transport = address_pipe
    reply_transport = address_reply
    file = /etc/exim/user_filter
    check_local_user
    filter
    allow_system_actions


This should come after any system_aliase-style director, but before a
localuser director. If you want to support both ~/.forward and
/etc/exim/user_filter, you'd probably want the ~/.forward director to
come first, so people can get mail out of your server entirely if they
want to.

Then /etc/exim/user_filter should look something like this:

# exim filter

  if $header_subject: matches [(\\w+)] then:
    save Maildir/$1
  else:
    save Maildir


This is COMPLETELY UNTESTED and off the top of my head. I didn't even
check the docs; you should do so to see how badly I've screwed this up.

Also, on re-reading your requirements:

> I'd like to search $header_subject: for "\[.*\]" and, if found, write
> the message to ~/Maildir/.$subdir (where $subdir is what was found
> between the brackets).


...I think you're making several serious mistakes.

First, .* could include slashes, spaces, and other things you don't want
or can't have in a filename. That's why I used \w+.

Second, it sounds like you're seriously perverting Maildir. A Maildir
should contain three subdirectories: new, tmp, and cur. Anything beyond
that and you risk confusing MUAs, POP/IMAP servers, or whoever is going
to look at this Maildir.

Finally, lots of perfectly ordinary mail includes "[...]" in the header
-- mail from this list, for one. Why should you, the sys-admin, dictate
how your users sort their mail? If this is for sorting some system
email, I think you'd be much better off adding a "X-..." header and
testing for that in your filter.

        Greg
-- 
Greg Ward - software developer                gward@???
MEMS Exchange                            http://www.mems-exchange.org