[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading envelope in process.cf



Hi there,

I've been playing around with zmsh, namely I tried to read in the envelope
part of the message within proecess() code (to find out all receipients of
the message). So I typed in the following code in process.cf:

        while read line; do
            case "$line" in
              env-end)
#               echo "The end!"
                break
                ;;
              "to <"*)
#               echo "T: $line";
                ssift "$line" in
                (.+)@(.+)>
                  rcptuser="\1"
                  rcpthost="\2"
#                 echo "host: $rcpthost"
                  lappend dom $rcpthost
                  ;;
                tfiss
                ;;
              *)
#               echo "L: $line";
                ;;
             esac
        done < $file
 
This code reads the file with name in $file and for each line it tries to
locate strings starting with "to <......>". For each one it adds the
receipient to the receipients' list ($dom) with lappend command. It breaks
at the end of the envelope (env-end marker).

Unfortunately, after processing several thousand messages this code broke.
All router processes spit out regularly the following message: 

[19654] router[19654] realloc(4282384384): virtual memory exceeded, sleeping


and of course the router queue is not processed. I've played with the gdb
and found out that the "read line" part of the code is responsible (within
sh_read() function). The "read" tries to allocate about 4GB of RAM, no
wonder if fails to do so. So there is probably some bug in zmsh with respect
to this code, since the message (even whole) is obviously much more smaller
(max 4MB, actually). 

Haven't been able to locate the message in question, though. After
restarting the router everything went on smoothly, and router processed all
queued messages without interruption. Tricky.

Anyway, it occured to me that maybe such a loop is not an effective way to
read in all the receipients from the envelope. Despite the fact that it
breaks, I guess such construct "while read line; do ...; done < $file" is
not a very efficient way of handling the file IO, it probably reads the
whole file and allocates a lot of memory to read the file in one go, even
though I call "break" immediately after the envelope's end. 

Is there any other way to get the receipients addresses _before_ I call
rfc822() function? This code is executed in process() before calling the
rfc822(), so all I have is $file with file name to process. Since it is
called for every message, no forks can be involved, so calling external
program is out of question. I could write my own built-in function, but
maybe there is some easier way...

Any ideas?

Thanks,
Marek
-
To unsubscribe from this list: send the line "unsubscribe zmailer" in
the body of a message to majordomo@nic.funet.fi