procmail
[Top] [All Lists]

Getting partial matches from a string without forking an outside process

2005-01-08 12:49:22
Hi,

Jari Aalto's pm-tips contains a section "Getting partial matches from
a string" (chapter 7.14), online available at
http://pm-doc.sourceforge.net/pm-tips-body.html#strings_getting_partial_matches_from

The current version (v2.28 as of 2004-10-06) says "Getting a match to
the right is quite easy with procmail's match operator but deleting 2
characters from the end is nearly impossible without forking an
outside process". However, it is possible without forking an outside
process. 

The example to get '12345678' from '1234567890' calls the 'expr'
program. In my latest procmail-driven anti-virus filter, SoftlabsAV
0.8.3 (released today), I wrote a pure-procmail routine to split a
string into two pieces, thus it does not need to call any outside
process. SoftlabsAV is available via it's homepage at
http://softlabsav.sourceforge.net/

The Release Notes and ChangeLog of v0.8.3 can be viewed online at
http://sourceforge.net/project/shownotes.php?release_id=295358
and SoftlabsAV 0.8.3 can be downloaded directly via
http://prdownloads.sourceforge.net/softlabsav/SoftlabsAV-0.8.3.tar.bz2?download

Once it has been installed into '/etc/procmailrcs/SoftlabsAV', the
following code splits '1234567890' into '12345678' and '90':

 my_VAR = '1234567890'

 av_INSTALLDIR = '/etc/procmailrcs/SoftlabsAV'
 av_SPLIT_STRING = $my_VAR
 av_N = '8'
 av_SPLIT_LEFT
 INCLUDERC = "$av_INSTALLDIR/inc/av_split.inc"

 my_result = $av_SPLIT_LEFT
 LOG = "'$my_VAR' -> '$my_result' + '$av_SPLIT_RIGHT'
"

This will write

'1234567890' -> '12345678' + '90'

into the log file. Setting
 av_N = '7'
(instead of assigning the value '8') would result in

'1234567890' -> '1234567' + '890'

and so on. Maybe pm-tips should add a note on this possible method?

best,
rob.

--


____________________________________________________________
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