Handle more than one entitiy in From: etc.
authorThomas Hochstein <thh@inter.net>
Wed, 4 Sep 2013 09:11:27 +0000 (11:11 +0200)
committerThomas Hochstein <thh@inter.net>
Sun, 8 Sep 2013 15:53:21 +0000 (17:53 +0200)
From:, Sender: etc. may contain more than one
entity in a comma separated list, i.e. a From:
line like
"From: Me <me@example.com>, You <you@example.com>"
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 <thh@inter.net>
bin/parsedb.pl

index fc29747..1a0fa39 100755 (executable)
@@ -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 <addr@ess> (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);
       }
     }
   }
This page took 0.01232 seconds and 4 git commands to generate.