From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0A7A81F8CA for ; Thu, 7 May 2020 21:05:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/13] EmlContentFoo: relax Encode version requirement Date: Thu, 7 May 2020 21:05:52 +0000 Message-Id: <20200507210556.22995-10-e@yhbt.net> In-Reply-To: <20200507210556.22995-1-e@yhbt.net> References: <20200507210556.22995-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We want to support Perl v5.10.1 out-of-the-box with minimal download/installation time. Installing Encode from CPAN requires a compiler and lengthy build+install time. So mimic find_mime_encoding() using what Perl v5.10.1 provides out-of-the box. --- Makefile.PL | 2 +- lib/PublicInbox/EmlContentFoo.pm | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 27bb112c..59345edb 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -130,7 +130,7 @@ WriteMakefile( # libperl$PERL_VERSION or libencode-perl on Debian, # `perl5' on FreeBSD - 'Encode' => 0, + 'Encode' => 2.35, # 2.35 shipped with 5.10.1 # libperl$PERL_VERSION + perl-modules-$PERL_VERSION 'Compress::Raw::Zlib' => 0, diff --git a/lib/PublicInbox/EmlContentFoo.pm b/lib/PublicInbox/EmlContentFoo.pm index f507d548..7472f8d2 100644 --- a/lib/PublicInbox/EmlContentFoo.pm +++ b/lib/PublicInbox/EmlContentFoo.pm @@ -9,15 +9,38 @@ # # This license differs from the rest of public-inbox # +# ABSTRACT: Parse a MIME Content-Type or Content-Disposition Header +# # This is a fork of the Email::MIME::ContentType 1.022 with # minor improvements and incompatibilities; namely changes to # quiet warnings with legacy data. package PublicInbox::EmlContentFoo; use strict; use parent qw(Exporter); -# ABSTRACT: Parse a MIME Content-Type or Content-Disposition Header +use v5.10.1; + +# find_mime_encoding() only appeared in Encode 2.87+ (Perl 5.26+), +# while we support 2.35 shipped with Perl 5.10.1 +use Encode 2.35 qw(find_encoding); +my %mime_name_map; # $enc->mime_name => $enc object +BEGIN { + eval { Encode->import('find_mime_encoding') }; + if ($@) { + *find_mime_encoding = sub { $mime_name_map{lc($_[0])} }; + %mime_name_map = map {; + my $enc = find_encoding($_); + my $m = lc($enc->mime_name // ''); + $m => $enc; + } Encode->encodings(':all'); + + # delete fallback for encodings w/o ->mime_name: + delete $mime_name_map{''}; + + # an extra alias see Encode::MIME::NAME + $mime_name_map{'utf8'} = find_encoding('UTF-8'); + } +} -use Encode 2.87 qw(find_mime_encoding); our @EXPORT_OK = qw(parse_content_type parse_content_disposition); our $STRICT_PARAMS = 1;