[Mimedefang] Problem matching occurrences other than first line in email.

Kees Theunissen C.J.Theunissen at differ.nl
Tue Apr 2 07:12:29 EDT 2013


On Tue, 2 Apr 2013, Lars Sorensen wrote:

>Hello,
>
>Trying to get heads and tails of Mimedefang and Perl, I'm stuck understanding why the below code in Mimedefang will only match on the first line of an email and ignore the rest.
>
>So:
>"open something anotherthing thirdthing" only matches if on the first line of the email, and additional lines are ignored.
>I'm trying to match all occurrences of lines with this pattern and add headers accordingly.
>Can anybody throw me a bone on this one?
>
>###########################################################################
>sub filter {
>	my($entity) = @_;
>
>	if (grep {/email\@example\.com/i} @Recipients) {
>		my $io;
>		if ($io = $entity->open("r")) {
>			while (defined($_ = $io->getline)) {
>				if  ( $_ =~ /\bopen\W+([a-z]+)(\W+)?([a-z]+)?(\W+)?([a-z]+)?/i) {
>					action_add_header('X-header',"$1, $3, $5");
>					last;
>				}
>			}
>        	$io->close;
>        	}
>	}
>}
>###########################################################################

Quoting from the output of the command: perldoc -f last

       last LABEL
       last    The "last" command is like the "break" statement in C (as used
               in loops); it immediately exits the loop in question.


So the "last;" command in your code will end the while-loop after processing
the first line that matches the regular expression.

Non-matching lines at the start of the message will be processed (ie: just
skipped) though if I read your code correctly.


Regards,

Kees Theunissen.

-- 
Kees Theunissen,  System and network manager,   Tel: +31 (0)30 6096724
Dutch Institute For Fundamental Energy Research (DIFFER)
e-mail address:   C.J.Theunissen at differ.nl
postal address:   PO Box 1207, 3430 BE Nieuwegein, NL
visitors address: Edisonbaan 14, 3439 MN Nieuwegein, NL




More information about the MIMEDefang mailing list