When David B. Little asked,
| >Since these large files are typically files with attachments I was curious
| >if there was a way to tell procmail within the rc file to only grep the
| >first 30 lines or so of each message?
Philip Guenther asked,
| No, there isn't.
We can if we resort to an outside process:
LINES_TO_SEARCH=number_of_lines_to_search_at_top_of_body
pattern=regexp_to_search_for
:0b
AREA_TO_SEARCH=| head -$LINES_TO_SEARCH
# sed ${LINES_TO_SEARCH}q if you don't have head(1)
:0
* $ AREA_TO_SEARCH ?? $pattern
action
We could do it inside procmail for shorter mail items, such as most text-only
messages that have no attachments, but in those David Little was discussing,
the method would overrun $LINEBUF. Nonetheless, here it is:
LINES_TO_SEARCH=number_of_lines_to_search_at_top_of_body
pattern=regexp_to_search_for
:0B # find first occurrence of $pattern and extract to end of body
* $ ()\/$pattern(.*$)*
{
FROM_PATTERN_ON=$MATCH
:0B # see if search maximum plus lines extracted exceeds total lines
* 1^1 FROM_PATTERN_ON ?? ^.*$
* $ $LINES_TO_SEARCH^0
* -1^1 ^.*$
action
}
We could extract * B ?? ^^\/(.*$)*.*$pattern, count the lines in there,
subtract from $LINES_TO_SEARCH, and add 1, but that would extract through
the last appearance of $pattern and give us a false negative if $pattern
occurred both within and after the first $LINES_TO_SEARCH lines.