Personal #mail#linux 2 min

PROCMAIL and BCC problem

Translation of the original in Catalan. Read it in: CatalàCastellano

Next I will try to give a solution to a problem that I have spent all afternoon looking for on the internet and nobody has ended up giving me the solution. In fact, it is already a bit specific to know when the problem happens, but in a case like mine it is very complex.

Situation

More than one and more than two ISPs (e.g. Maestrat) when you buy a domain from them give you umpteen email accounts, but only one mailbox.

Then when we download the mail from the mailbox many of us re-distribute the mail with procmail. Basically what is done is to look at the To: and the From: to classify it into the corresponding mailbox of each user.

If we have few users it is not difficult with filters through the Subject or the From or other fields.

The problem

When a message comes addressed to a mailing list where the To: is not any of our users but a standard address or anything else except the name of a user of our system. Procmail cannot classify it into the mailbox of the relevant user.

This also happens when we are the recipient of a message from the BCC field, this is an invisible field that procmail will not be able to filter since it is not content of the message to be filtered.
Solution

After spending the afternoon looking on the internet and not finding any clear solution. So I have started to think and investigate. One thing is clear: if we don't have to do the filtering the message arrives, therefore, at some place there has to be the information and somehow the message has to travel.

Therefore, the subject is clear, the information is not in the fields of the message but in the "envelope" information, that is, what is sent before the data information (rcpt to).

Now the problem was what trace this leaves so that we can filter it. Well I have not yet been able to implement the script that does it, but the idea is the following:

-At the end of all the procmail mailboxes I add a filter

-This filter has to look at the third Received: that carries the mail and on the third and last line of this received after the word 'for', the email address of the user of our system to whom the mail was addressed appears.

-We capture this address

-We delete the original To: field of the message and put the To: with our user or simply add a Cc: field with our user.

-Then we process the mail again with our procmail and so it will be placed in the relevant mailbox.

-In case this does not happen almost 100% of the time we can be sure that the mail in question is spam.

So, besides managing to classify the mails into their mailbox we also manage to filter the spam with this idea. On Monday itself when I get to work I will implement the filter and I will post it on the portal.

5 comments

Comments from the old blog, as they were written. Comments are closed.

  1. Oriol Rius

    Després de provar-lo durant tot el mati he tret la primera versió
    de l'script que soluciona el problema comentat a l'article.



    El codi que adjunto a continuació s'ha de posar en un fitxer amb
    permisos d'execusió, aquest fitxer es cridarà tal com
    explicaré després.



    Jo l'he anomenat filtre_bcc:

    ---------------------------------------------

    DOMINI="@joor.net"

    FILE="/tmp/email.txt"



    cat > $FILE



    DESTI=`cat $FILE | grep -A 2 Received: | grep "for <" | grep "$DOMINI" |
    cut -d " " -f 2 | sed 's/>;/ /' | sed 's/</ /' | grep
    "$DOMINI"`



    cat $FILE | formail -t -I Received: -i "To: $DESTI"



    rm $FILE



    ---------------------------------------------



    A la varibale DOMINI, hem de posar el domini al que pertanyen els nostres
    usuaris, en aquest cas @joor.net



    Després al nostre .procmailrc hem d'afegir el següent:



    :0:

    * ^TO*@joor.net

    ! oriol



    :0:

    *

    | /home/oriol/bin/bcc | sendmail -t -f oriol@joor.net



    això va al final del fitxer. Amb el primer bloc enviem tot el correu que
    no va a cap bústia legal cap a un usuari per defecte. En aquest cas
    oriol.



    En el segon bloc enviem tots els mails que no s'han classificat al filtre, el
    qual els proporcionarà un camp de recipient del tipus To:
    usuari@joor.net i gràcies a això es podrà classificar a la
    bústia que correspon.



    La direcció oriol@joor.net la podem substituïr per qualsevol
    direcció legal d'internet, aquesta és necessaria perquè
    molts sendmail's quan els entre un remitent ha de tenir una direcció
    legal, en cas de no posar el paràmetre -f al sendmail la direcció
    que agafariem seria la direcció per defecte del usuari que ha tirat el
    procmail.



    Espero que aquesta primera versió vagi el millor possible si aglú
    troba algún error o s'anima a provar-la si us plau que avisi.

  2. pau

    Després d'estar una bona estona llegint documentació i jugant amb
    procmail/sendmail, he arribat a una sol·lució, que en els casos
    que he provat (TO+BCC, BCC sól, y llista de correu, amb el SMTP meu
    propi i amb el de maestrat ~ 15 proves diferents) m'ha donat un 100%
    d'efectivitat. Hi hauría que veure com es comporta en front a un
    "envelope" generat per un lotus notes, ja q no disposo dels mitjans per a
    provar-ho.

    Aquí va la sol·lució (els exemples son amb el meu cas,
    domini eslack.org, usuari pop pau i usuari redireccionat
    tripledes@eslack.org):



    (1 pas):

    FEATURE(local_procmail) y FEATURE(virtusertable) al fitxer .mc (Aixo se suposa
    q ja ho tenim)



    (2 pas):

    Al fitxer /etc/mail/virtusertable (o equivalent), anyadir la seguent
    entrada:



    @eslack.org pau+%1@localhost



    despres fer el makemap hash y reiniciar sendmail. (Jo ho tenia sense la part q
    diu "+%1@localhost" i si no li anyadeixes aixo no rula).



    (3er pas):



    Posar el seguent al $HOME/.procmailrc del usuari pop:



    root@maestratnet:~# cat /home/admins/pau/.procmailrc

    LOGFILE=$HOME/.procmail.log

    COMSAT=no





    DOMAIN=eslack.org

    ENV_TO=$1



    :0f

    * ENV_TO ?? .

    | /usr/bin/formail -i "X-Envelope-To: "$ENV_TO@$DOMAIN



    :0fE

    | /usr/bin/formail -i "X-Envelope-To: UNKNOWN"





    (4t pas):



    Posar el seguent al .procmailrc, per a que es reenvie el mail on toca:



    :0:

    * ^To.*tripledes@eslack.org

    !eth0@subdimension.com



    :0:

    * ^Cc.*tripledes@eslack.org

    !eth0@subdimension.com



    :0:

    * ^X-Envelope-To.*tripledes@eslack.org

    !eth0@subdimension.com





    I això es tot!



    Oriol: Ja farás les teves proves i em diras que tal et va per al teu cas
    concret.



    APENDIX

    --------

    http://www.ling.helsinki.fi/users/reriksso/procmail/mini-faq.html#bcc

    http://www.xray.mpe.mpg.de/mailing-lists/procmail/1998-04/msg00289.html

    http://www.sendmail.org/faq/section3.html#3.29

  3. Oriol Rius

    Demà m'ho miraré amb més calma a la feina, però
    ara li he fet una llegida ràpida i se m'acudeix una cosa que
    t'estalvia haver d posar tantes coses al .procmailrc.



    On posa:

    :0:

    * ^To.*tripledes@eslack.org

    !eth0@subdimension.com



    :0:

    * ^Cc.*tripledes@eslack.org

    !eth0@subdimension.com



    ho pots substituir per:



    :0:

    * ^TOtripledes@eslack.org

    !eth0@subdimension.com



    això fa el mateix q les altres linies i la línia del X-envelope
    tb la podries posar aquí, però d memòria no recordo com es
    fa. Apa! nanit i demà em miro amb calma tot el q m'has posat.



    THX! pels suggermients ;)

  4. Oriol Rius

    Avui se m'ha acudit començar a usar la solució que va proposar
    el pof a les redireccions de joor.net q tinc a maestratnet.net, després
    de modificar el .procmailrc tal com indica el pof, però millorant els
    tres blocs que ell usa per exemple així:



    :0:

    ^TO_.*oriol@joor.net

    ! oriol@maestratnet.net



    amb això ja funciona la redirecció el problema és que el
    camp X-envelope que s'ha de crear a vegades no conté el email del
    destintari. Ja que les linies previes del procmail (les q el pof diu q s'han d
    posar) son incapaces de determinar qui és el destinatari.



    Aquí ús enganxo un exemple d'un email on no s'ha pogut esbrinar
    el destinatari:



    From oriol@inforcomsoft.com Thu Nov 22 15:56:04 2001

    Return-Path:

    Received: from mini2 ([213.97.151.98])

    by maestratnet.maestratnet.net (8.11.6/8.11.4) with ESMTP id fAMEu3R2189

    0

    for ; Thu, 22 Nov 2001 15:56:03 +0100

    Received: from [127.0.0.1] by mini2

    (ArGoSoft Mail Server, Version 1.3 (1.3.0.1)); Thu, 22 Nov 2001 16:03:44
    +0100

    Message-ID: <3BFD13CF.9080700@inforcomsoft.com>

    Date: Thu, 22 Nov 2001 16:03:43 +0100

    From: Oriol

    Organization: Inforcom Software,S.L.

    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.6)
    Gecko/2001

    1120

    X-Accept-Language: en-us

    MIME-Version: 1.0

    To: oriol.mobil@joor.net

    Subject: testing

    Content-Type: text/plain; charset=ISO-8859-1; format=flowed

    Content-Transfer-Encoding: 8bit

    X-Envelope-To: UNKNOWN





    tot i q s'ha de dir q en general si q funciona i a mi m'allibera d'haver
    d'estar borrant molts emails. Que no van per mi cada dia.

  5. Oriol Rius

    Aquest migdia m'he llegit tot el man del .procmailrc i ja sé
    perquè no anava a vegades. Era culpa del puto virtualusertable de
    joor.net q no tenia especificat que passes com a paràmetre el
    destinatari del mail:



    @joor.net joor+%1@localhost



    ara ja ta claríssim!!! q guay! per fi no rebre el correu de la penya q
    es subscriu a les llistes de correu amb direccions de joor.net,buf! ja ha
    costat ja.