user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 09/13] EmlContentFoo: relax Encode version requirement
Date: Thu,  7 May 2020 21:05:52 +0000	[thread overview]
Message-ID: <20200507210556.22995-10-e@yhbt.net> (raw)
In-Reply-To: <20200507210556.22995-1-e@yhbt.net>

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;

  parent reply	other threads:[~2020-05-07 21:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 21:05 [PATCH 00/13] eml: pure-Perl replacement for Email::MIME Eric Wong
2020-05-07 21:05 ` [PATCH 01/13] msg_iter: make ->each_part method for PublicInbox::MIME Eric Wong
2020-05-07 21:05 ` [PATCH 02/13] msg_iter: pass $idx as a scalar, not array Eric Wong
2020-05-07 21:05 ` [PATCH 03/13] filter/rubylang: avoid recursing subparts to strip trailers Eric Wong
2020-05-07 21:05 ` [PATCH 04/13] smsg: use capitalization for header retrieval Eric Wong
2020-05-07 21:05 ` [PATCH 05/13] eml: pure-Perl replacement for Email::MIME Eric Wong
2020-05-07 21:05 ` [PATCH 06/13] switch read-only Email::Simple users to Eml Eric Wong
2020-05-07 21:05 ` [PATCH 07/13] replace most uses of PublicInbox::MIME with Eml Eric Wong
2020-05-07 21:05 ` [PATCH 08/13] EmlContentFoo: Email::MIME::ContentType replacement Eric Wong
2020-05-07 21:05 ` Eric Wong [this message]
2020-05-07 21:05 ` [PATCH 10/13] eml: remove dependency on Email::MIME::Encodings Eric Wong
2020-05-07 21:05 ` [PATCH 11/13] xt: eml comparison tests Eric Wong
2020-05-08  4:47   ` Eric Wong
2020-05-07 21:05 ` [PATCH 12/13] remove most internal Email::MIME usage Eric Wong
2020-05-07 21:05 ` [PATCH 13/13] eml: drop trailing blank line on missing epilogue Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200507210556.22995-10-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).