From 61fc4c7942a5690f5c3bbae5f953ddc89500c67b Mon Sep 17 00:00:00 2001 From: "Eric Wong (Contractor, The Linux Foundation)" Date: Tue, 6 Mar 2018 03:49:42 +0000 Subject: import: fall back to Sender for extracting name and email MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This seems like a reasonable course of action for old messages. Cc: Nicolás Ojeda Bär --- lib/PublicInbox/Import.pm | 62 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 7ba16683..664bec69 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -208,15 +208,50 @@ sub parse_date ($) { "$ts $zone"; } -# returns undef on duplicate -# returns the :MARK of the most recent commit -sub add { - my ($self, $mime, $check_cb) = @_; # mime = Email::MIME +sub extract_author_info ($) { + my ($mime) = @_; + my $sender = ''; my $from = $mime->header('From'); my ($email) = PublicInbox::Address::emails($from); my ($name) = PublicInbox::Address::names($from); + if (!defined($name) || !defined($email)) { + $sender = $mime->header('Sender'); + if (!defined($name)) { + ($name) = PublicInbox::Address::names($sender); + } + if (!defined($email)) { + ($email) = PublicInbox::Address::emails($sender); + } + } + if (defined $email) { + # quiet down wide character warnings with utf8::encode + utf8::encode($email); + } else { + $email = ''; + warn "no email in From: $from or Sender: $sender\n"; + } + + # git gets confused with: + # "'A U Thor ' via foo" + # ref: + # + if (defined $name) { + $name =~ tr/<>//d; + utf8::encode($name); + } else { + $name = ''; + warn "no name in From: $from or Sender: $sender\n"; + } + ($name, $email); +} + +# returns undef on duplicate +# returns the :MARK of the most recent commit +sub add { + my ($self, $mime, $check_cb) = @_; # mime = Email::MIME + my ($name, $email) = extract_author_info($mime); my $date_raw = parse_date($mime); my $subject = $mime->header('Subject'); $subject = '(no subject)' unless defined $subject; @@ -263,25 +298,6 @@ sub add { print $w "reset $ref\n" or wfail; } - # quiet down wide character warnings with utf8::encode - if (defined $email) { - utf8::encode($email); - } else { - $email = ''; - warn "no email in From: $from\n"; - } - - # git gets confused with: - # "'A U Thor ' via foo" - # ref: - # - if (defined $name) { - $name =~ tr/<>//d; - utf8::encode($name); - } else { - $name = ''; - warn "no name in From: $from\n"; - } utf8::encode($subject); print $w "commit $ref\nmark :$commit\n", "author $name <$email> $date_raw\n", -- cgit v1.2.3-24-ge0c7