procmail
[Top] [All Lists]

Re: convert all mails of a catch-all mailbox to html or .txt. files in folders named by the recipient

2007-08-29 18:20:59
At 01:16 2007-08-30 +0200, Stefan S. wrote:
I wonder if the following is possible:

I have a mailbox configured to "catch-all".

Personal, or some global affair on your mail system, say via a wildcard 
virtuserable entry?  i.e. are these all YOUR messages, or are they other 
people's messages, and what level of privacy should be expected between them?

 I want to convert the mails of this mailbox in 
/var/spoll/mail/MAILBOXNAME to html or at least .txt files and put them 
in a directory which is named like the emailadres or the part befor the 
@. (I would store them in a folder which is accessible over Apache over 
http://lanserver/FOLDER_WE_TALK_ABOUT )Example: a mail to 
XYZ(_at_)domain(_dot_)tld 
in var/spool/mail/MAILBOX should be converted and stored in a directory 
which is named XYZ or XYZ(_at_)domain(_dot_)tldThis means: Procmail has to 
look in 
the mailbox file, and to search for mails with the same recipient´s-adress,

procmail doesn't "look in" and "search through" mailboxes - individual 
messages are handed to it on stdin, one per invocation.  It also won't 
REMOVE messages from a mailbox.

and to put them into a folder which is named like the emailadress of the 
recipient.

I take it you have a catchall mailbox for a wildcard domain address?  You 
can expect a LOT of those to have no identifiable recipient, or may have 
been sent to multiple recipient names at your domain.  Once BCC steps in, 
things get ugly - and you cannot rely on the To: address actually being the 
address the message was locally delivered to (nevermind the potential for 
multiple addresses to appear in the field).  It is possible to configure 
your MTA to insert headers to identify the actual recipient - but say for 
sendmail, this only works if there was ONE RCPT.  It also only works for 
newly recieved email -- not for stuff sitting in a mailbox on your system 
from BEFORE such a config hack was employed.

Wildcard mail addresses invite spam: spammers don't need to know valid 
addresses, just send to WHATEVER, and it'll get through (not that they 
discern what is or isn't valid - so figure that all attempts to send via 
say, dictionary attack will succeed).

The program hypermail can convert mailboxes to html, so my problem would 
allready be solved if I could seperate the mails of each recipient into 
several mailboxes (the problem is that I can´t put the recipient´s name 
in a rule, beacuse I don´t know which names are choosen in the future.

Er, set up mail forwarding AT THE TIME EACH NEW USERNAME IS CHOSEN?  You 
set up accounts for them, right?

Any partial solution you're going to employ will need to rely on a regexp 
grabbing address tokens containing your domain, say:

         :0
         * ^TO\/(_dot_)*(_at_)gmx\(_dot_)de\>?
         {
                 FROMADDR=$MATCH
                 LOG="** Recipient is $FROMADDR${NL}"
         }

but this particular construct could easily match multiple addresses, 
including ones the message (or at least, this specific copy) wasn't 
delivered to.  Consider a multiply-addressed message which is delivered to 
a couple of known addresses at your host (with mailboxes), and a couple of 
addresses at the wildcard.

The wildcard will generally end up with one copy despite there being two 
wildcarded addresses, there won't be an envelope recipient identified 
(because there were multiple recipients), and even assuming all the 
recipient addresses were cleartexted (rather than some/none as To: or Cc:, 
and others as Bcc:), the wildcard processor cannot easily determine which 
of the addresses were delivered to other mailboxes (without needing to 
check with the MTA, and that also assumes it's CURRENTLY delivering for all 
the recipients that may bave previously been in the wildcard, and that some 
of the addresses in the old wildcard stored messages are not NOW actually 
configured for separate delivery).

Thats why we use a catch-all mailbox). It would be possilbe to do the rest 
with hypermail then.
any ideas or examples for a .procmailrc file?Thank you

You really want to look at formail to split the mailbox and pass the 
individual messages into procmail, which would _attempt_ to discern who the 
local recipient was.  When there are MULTIPLE local recipients, or none, it 
would need to kick the message out to a separate folder for you to 
subsequently evaluate.

The procmail rule could invoke the hypermail program directly at the time 
of delivery, instead of having to put it into another mailbox that you'd 
have to separatley invoke hypermail for.

I don't use hypermail, so don't have a manpage for it.

Have fun.

---
  Sean B. Straw / Professional Software Engineering

  Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
  Please DO NOT carbon me on list replies.  I'll get my copy from the list.

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail