From 778853929562100fc111afa8a244111c24747e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 27 May 2021 19:25:28 +0200 Subject: m-pop: Fix From: header parsing Now, it handles From: headers split across multiple lines. --- src/m-pop | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/m-pop b/src/m-pop index e7cebae..7b34086 100755 --- a/src/m-pop +++ b/src/m-pop @@ -87,17 +87,18 @@ for my $id (@ids) { chomp(@msg = @{$pop->get($id)}); } - # Make From_ line - my ($from, $from_alt); + # Find address in From: header and make From_ line + my $from; my $j = 0; # index of empty line before message body for (@msg) { last if /^$/; + if (/^[Ff]rom: / .. not $msg[$j+1] =~ /^[ \t]/) { + /^(?: From:\ | [ \t]+) (.*)/x; + $from .= " $1" if $1; + } $j++; - $from = $1 if /^From: (.*)$/; - $from_alt = $1 if /^from: (.*)$/; } - $from = $from_alt if $from_alt and not $from; - $from = $1 if $from and $from =~ /^.* <(.*?@.*?)>$/; + $from = $1 if $from and $from =~ /^.* <(.*?@.*?)>$/s; $from = 'MAILER-DAEMON@' . hostname if not $from; my $from_ = "From $from $date"; -- cgit v1.2.3