X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FEml.pm;h=955d6a96a51c12b549478145afd45491dd5c9e25;hb=5c8909925072804901e9c3b45bbf25446d379e7b;hp=4d3fffc0387ae7653653dbae561ab03551789c29;hpb=46bd595f57cc3d425754b0d0770c125616e74448;p=public-inbox.git diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm index 4d3fffc0..955d6a96 100644 --- a/lib/PublicInbox/Eml.pm +++ b/lib/PublicInbox/Eml.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ # # Lazy MIME parser, it still slurps the full message but keeps short @@ -51,7 +51,9 @@ $MIME_ENC{quotedprint} = $MIME_ENC{'quoted-printable'} = $MIME_ENC{qp}; $MIME_DEC{quotedprint} = $MIME_DEC{'quoted-printable'} = $MIME_DEC{qp}; $MIME_ENC{$_} = \&identity_codec for qw(7bit 8bit binary); -my %DECODE_ADDRESS = map { $_ => 1 } qw(From To Cc Sender Reply-To); +my %DECODE_ADDRESS = map { + ($_ => 1, "Resent-$_" => 1) +} qw(From To Cc Sender Reply-To Bcc); my %DECODE_FULL = ( Subject => 1, 'Content-Description' => 1, @@ -217,7 +219,7 @@ sub mp_descend ($$) { # There's also a case where quoted text showed up in the # preamble # <20060515162817.65F0F1BBAE@citi.umich.edu> - unshift(@parts, new_sub(undef, \$pre)) if $pre =~ /:/s; + unshift(@parts, new_sub(undef, \$pre)) if index($pre, ':') >= 0; return \@parts; } # "multipart", but no boundary found, treat as single part @@ -234,6 +236,7 @@ sub mp_descend ($$) { # $cb - user-supplied callback sub # $arg - user-supplied arg (think pthread_create) # $once - unref body scalar during iteration +# $all - used by IMAP server, only sub each_part { my ($self, $cb, $arg, $once, $all) = @_; my $p = mp_descend($self, $once // 0) or @@ -332,7 +335,7 @@ sub body_set { sub body_str_set { my ($self, $body_str) = @_; my $charset = ct($self)->{attributes}->{charset} or - Carp::confess('body_str was given, but no charset is defined'); + croak('body_str was given, but no charset is defined'); body_set($self, \(encode($charset, $body_str, Encode::FB_CROAK))); } @@ -454,7 +457,7 @@ sub body_str { if ($STR_TYPE{$ct->{type}} && $STR_SUBTYPE{$ct->{subtype}}) { return body($self); } - Carp::confess("can't get body as a string for ", + croak("can't get body as a string for ", join("\n\t", header_raw($self, 'Content-Type'))); } decode($charset, body($self), Encode::FB_CROAK); @@ -477,6 +480,25 @@ sub charset_set { sub crlf { $_[0]->{crlf} // "\n" } +# warnings to ignore when handling spam mailboxes and maybe other places +sub warn_ignore { + my $s = "@_"; + # Email::Address::XS warnings + $s =~ /^Argument contains empty / + || $s =~ /^Element at index [0-9]+.*? contains / + # PublicInbox::MsgTime + || $s =~ /^bogus TZ offset: .+?, ignoring and assuming \+0000/ + || $s =~ /^bad Date: .+? in / + # Encode::Unicode::UTF7 + || $s =~ /^Bad UTF7 data escape at / +} + +# this expects to be RHS in this assignment: "local $SIG{__WARN__} = ..." +sub warn_ignore_cb { + my $cb = $SIG{__WARN__} // \&CORE::warn; + sub { $cb->(@_) unless warn_ignore(@_) } +} + sub willneed { re_memo($_) for @_ } willneed(qw(From To Cc Date Subject Content-Type In-Reply-To References