procmail
[Top] [All Lists]

Re: Nested recipes... (sorry if this is sent twice.. )

2005-01-23 14:46:22
Dallman Ross said the following on 1/23/2005 6:53 AM:

Better, in that it probably at least works.  :)  It's okay, but
we can make it look prettier.
Yes it does, at least :))

Not exactly what I'm saying, no.  I'm not intending to
rule out what you call pre-filtering.  I'm simply wanting to
avoid needless repetition.

For one thing, think about how procmail is complying with your
condition requests: it is feeding the header to the condition's
regex for evaluation.  The header for this email posting that
I'm responding to has, for example, 93 lines on my system.
So now we have the procmail equivalent of:

  93 lines | egrep -i ^List-Post:(_dot_)*(_at_)freebsd[any-one-char]org

and assuming that passes muster, we run another recipe:

  93 lines | egrep -i ^List-Post:.*advocacy[followed-by-zero-or-many-anythings]

and assuming that evaluates true, write a log, and open another recipe to
save the message.  Or if it didn't evaluate true, run another recipe:

  93 lines | egrep -i ^List-Post.*chat[and-zero-or-more-anythings]

and ditto with the log and new delivery recipe.

Well, it's kind of okay, in that it works.  But it's, pardon the
expression, butt-ugly, and full of unnecessary extra things for procmail
to do.
As opposed to what I had been doing, which was a little recipe for each FreeBSD list I subscribed to. I won't even post those old recipes, as now, after seeing your recipe at the end, I hang my head in shame at them! :)

Once you put your head into the mind-set of thinking through just how procmail
is seeing your code, and you start thinking about minimalism and the logic,
it gets easier, with practice, to improve the elegance and skill of what
you're trying to code.  And that feels good!  For you, I mean; procmail
doesn't really care.

(grin) True enough! :) Part of this is I really need to learn regular expressions. I know I have a copy of the O'Reilly book around somewhere in a box. I need to dig it out and actually read it.. that'll probably help tons. :-/

Well, that's all I'm trying to get across, here:
a mind-set for improved, creative, more logical thinking.  You know,
there are usually quite a number of different ways to do things, any
one of which we might call "right."  But the right way to train your own
mind -- your programmatic rigor -- is to practice thinking the task through
with procmail's "eyes."  As for me, I'm never satisfied with my own
solutions, if you must know, and am always searching for ways to improve
them and learn more.  The approach may cause me mental restlessness, but
you'll never persuade me that it's not the right way, or Tao.  :-)
(grin) I hear you.. my old .procmailrc worked just fine for years.. but I figured if I did some pre-filtering (especially in the above example of the FreeBSD lists I belong to), it would save *some* processing time (if the email doesn't match ^List-Post:(_dot_)*(_at_)freebsd(_dot_)org then don't bother with the nested recipes...). (I see now, from further reading, that this can be even *better* than I had originally conceived!!)

Grouping, and speed, and efficiency, and elegance, are all highly useful.
I didn't mean to imply otherwise.  I'm glad you've thought of some of
them!  What I was objecting to was extraneous effort,  but not the
core concepts.  Here are a couple of quick ideas for your task:

  :0
  * ^TO_root(_at_)\/(Wingfoot|Database)[.]org\>
  * MATCH ?? ^^\/[^.]+
  {
      LOG = "$NL$MATCH Root Mail$NL"

      :0
      .$MATCH.Root/
  }
Oh! Nifty indeed! :) I see (from the manpage) that MATCH will contain anything past the \/ token. Overall, I can certainly see how this can make it TONS easier to do my FreeBSD list recipes, as well!

:0
* ^List-Post:.*\/(advocacy|announce|chat|config|doc|hackers|jobs|newbies|performance|ports|questions|stable|testing|user-groups|www)@.*freebsd\.org
* MATCH ?? ^^\/[^(_at_)]+
{
   LOG = "(FreeBSD $MATCH Mailing List)$NL"

   :0
   .FreeBSD.$MATCH/
}

Am I getting the general gist here, I hope? :) The light is beginning to turn on here.. :) Let me see if I can explain it in English how I'm seeing this...

If you have a line beginning with List-Post: followed by 0 or more anycharacters, splitting the expression for MATCH so that anything to the right of \/ is assigned to MATCH. We then check for advocacy or announce, etc, followed by an @, then match 0 or more anycharacters and freebsd.org. We then tell MATCH to begin extraction at \/ and include any character up until, but excluding @. At this point, we set LOG to be (FreeBSD $MATCH Mailing List)$NL", and we move the email to the proper mailbox under .FreeBSD depending on what $MATCH equals.

Did I get the logic right here? I got some help from http://www.ii.com/internet/robots/procmail/qs/#extractionMore where Nancy talks about MATCH and it's syntax. (The procmailrc (5) manpage was kind of sparse on that detail, IMHO.. :-/)

Thanks so much for your help, Dallman! This is giving me tons of ideas! :)

Best,
--Glenn

--
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." ~Benjamin Franklin, Historical Review of Pennsylvania, 1759


--
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." ~Benjamin Franklin, Historical Review of Pennsylvania, 1759


____________________________________________________________
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