procmail
[Top] [All Lists]

Re: recipe for statistics ?

1997-01-13 18:36:07
Being not an experienced user I have the following (probably) trivial
question :

procmail saves mail from mailing-lists I am subscribed to in their
respective folders.
What I want now, are 2 things:

1) a possibility to determine the disk-usage of every single message 
(to see the space-consuming ones)

        You could use a command like:

                formail -s wc < folder.filename

        Which will generate a list of wc output lines representing
        the lines, words, and characters of each message in the
        folder.

        You'd probably want to make that a cronjob or configure
        it so that it would only run once per day or per hour
        or whatever.  Configure a procmail recipe to happen 
        only periodically works like this:

                You keep some sort of marker file
                I like: 'date +%s > ~/tmp/timestamp'
                personally.  GNU 'date' uses the %s
                format specifier to show the number of
                seconds from the epoch (beginning of 
                Unix' system time).

                Your script checks the marker file.
                You can either check the timestamp
                of the file (as it would be updated
                with 'touch') or you can use the 
                contents of the file (as in my example).
                I'd check the file with:

                [$((`date %+s` - `cat ~/tmp/timestamp`)) \
                        gt $freq ] && do.something

                That expression reads (from the bash/ksh):

                        test that the difference between the current
                        time and the time listed in that file is 
                        greater than $freq (frequency in seconds) 
                        AND ...

                Obviously the exact values of $freq will have to
                be determined for our case.  

                The periodic event (do.something in my example)
                would have to update the timestamp file.

                There are undoubtedly more efficient methods --
                but this is the simplest to explain. (I think
                it should score points for elegance).

2) a possibility to rewrite the folder in order to eliminate the quoted
messages 

        You could use procmail to prevent them from ever getting
        into your folders -- but you might lose something interesting
        that way.  If you decide that you want to postprocess a 
        mail folder you  use something like:

        formail -s \
           procmail -m max=10000 new=./new.folder ./deepsix < $foldercopy 

        (where './deepsix' is the name of a recipe file in the 
        current directory -- $foldercopy is a copy of some folder 
        and new.folder is the copy that's been filtered).
        max and new are arbitrarily named variables.

        ./deepsix might look something like:

                :0
                * > $max
                /dev/null

                :0
                $new
                        

        Note that this consists of two trivial recipes --
        remove any messages that are larger than $max characters
        and store the rest.

        Personally I wouldn't recommend these methods for 
        trimming your mail boxes -- elm -f seems to work
        pretty well interactively.  You might write a 
        filtering rule that truncates each message down to
        a certain size (perhaps using 'fold' and 'head' --
        or just awk or perl).

        That would look something like:

                :0f
                * > $max
                | your.trimmer.script

        (where your.trimmer.script is an appropriately 
        executable trimming script or shell command).

        You should be quite careful about doing formail 
        processing on any folder which might receive mail
        while you're working on it.    In the procmail man
        page there is an extensive example using formail,
        lockfile, and procmail -- search on the word
        'postprocess' to find it.

Anyone knows how to handle this ?

TIA,

Wolfgang

<Prev in Thread] Current Thread [Next in Thread>