procmail
[Top] [All Lists]

RE: message size into subject?

2008-02-29 18:36:13
Richard KLINDA wrote Thursday, February 28, 2008 1:51 PM:

So my question: is it possible to put a size indicator into the
subject of the message?  I would like to put a "." for every 10
KiB, like:

"Subject: Foo bar baz"

Becomes

"Subject: ....Foo bar baz" if it is more than 40 KiB (and under 50).

Sure, it's possible.  It's not easy, at least all in
procmail (and one formail call to rewrite the Subject).
But here it is.

First of all, I refer you to this posting of mine from 1.2 years
ago:
http://www.xray.mpe.mpg.de/mailing-lists/procmail/2006-12/msg00111.html

It starts out:

  I've put together a little function-box INCLUDERC tool in procmail
  and decided to publish it.  It can take an integer as input (stated
  in a var) and return that number of dots, up to 99 inclusive.

The version of the rcfile tool in that posting is 1.0.061215.0.
There is an incrementally newer version, 1.0.061224.0, at the 
link in that message, to wit, 
http://vsnag.spamless.us/download/toolkit/func.nndots .

So take that and put it somewhere on your system.  We'll call
it from the bit we need to fulfill your wish:

# ------------- Start of 10-KiB-annotation rcfile -------------
  SHELL = /bin/sh          # don't leave this part out!

  :0 HB 
  *  1 ^1 .
  *  1 ^1 ^.*$
  * -1 ^0
  { SIZE = $=

    :0
    * SIZE ?? .\/....^^
    { RIGHT4 = $MATCH

      SPACE = ' '
      TAB   = ' '          # a real tab char
      WS    = $SPACE$TAB

      :0
      * $ ^Subject:.*\/[^$WS].*
      { SUBJ = $MATCH }

      :0
      *   SIZE ?? ^^\/..
      * $ SIZE ?? ^^$MATCH$RIGHT4^^
      { _inout = $MATCH }

      :0 E
      *   SIZE ?? ^^\/.
      * $ SIZE ?? ^^$MATCH$RIGHT4^^
      { _inout = $MATCH }

      :0
      * _inout ?? .
      { 
        # Change path below to suit
        INCLUDERC = /net/contrib/dman/procmail/tool/func.nndots
      }

      :0 fw
      | formail -I "Subject: ${_inout:-[>999KiB]}$SUBJ"
    }
  }
# -------------- End of 10-KiB-annotation rcfile --------------

If the message is under 10-KiB in size, the Subject won't
get rewritten.

I've tested this, and it seems to work just fine.

Btw, the part near the top that finds the size is a very
old trick originally from, I believe, David W. Tamkin.

Dallman

____________________________________________________________
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

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