From aef5467bfecfd4aeb83146212218c88837466de1 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Wed, 4 Sep 2013 11:11:27 +0200 Subject: [PATCH] Handle more than one entitiy in From: etc. From:, Sender: etc. may contain more than one entity in a comma separated list, i.e. a From: line like "From: Me , You " is perfectly valid. Handle multiple entities when splitting those headers and save all names and all adresses as (new) comma separated lists in the corresponding database fields. Signed-off-by: Thomas Hochstein --- bin/parsedb.pl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bin/parsedb.pl b/bin/parsedb.pl index fc29747..1a0fa39 100755 --- a/bin/parsedb.pl +++ b/bin/parsedb.pl @@ -180,19 +180,24 @@ while (my $HeadersR = $DBQuery->fetchrow_hashref) { } else { @Address = Mail::Address->parse($Headers{$_}); } - # split each Mail::Address object + # split each Mail::Address object to @Names and @Adresses + my (@Names,@Adresses); foreach (@Address) { - # take address part - $Headers{$HeaderName.'_address'} = $_->address(); + # take address part in @Addresses + push (@Adresses, $_->address()); # take name part form "phrase", if there is one: # From: My Name (Comment) # otherwise, take it from "comment": # From: addr@ess (Comment) - $Headers{$HeaderName.'_name'} = $_->comment() - unless $Headers{$HeaderName.'_name'}= $_->phrase; - $Headers{$HeaderName.'_name'} =~ s/^\((.+)\)$/$1/; - # FIMXE - handle more than one Mail::Address object! + # and push it in @Names + my ($Name); + $Name = $_->comment() unless $Name = $_->phrase; + $Name =~ s/^\((.+)\)$/$1/; + push (@Names, $Name); } + # put all @Adresses and all @Names in %Headers as comma separated lists + $Headers{$HeaderName.'_address'} = join(', ',@Adresses); + $Headers{$HeaderName.'_name'} = join(', ',@Names); } } } -- 2.20.1