From 57af9c8d0bedafac3267b5b42f963bb8aa5c2ea1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 May 2020 21:05:48 +0000 Subject: eml: pure-Perl replacement for Email::MIME Email::MIME eats memory, wastes time parsing out all the headers, and some problems can't be fixed without breaking compatibility for other projects which depend on it. Informal benchmarks show a ~2x improvement in general stats gathering scripts and ~10% improvement in HTML view rendering. We also don't need the ability to create MIME messages, just parse them and maybe drop an attachment. While this isn't the zero-copy or streaming MIME parser of my dreams; it's still an improvement in that it doesn't keep a scalar copy of the raw body around along with subparts. It also doesn't parse subparts up front, so it can also replace our uses of Email::Simple. --- lib/PublicInbox/TestCommon.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/TestCommon.pm') diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index cd73b5b6..600843f0 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -9,7 +9,7 @@ use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek); use POSIX qw(dup2); use IO::Socket::INET; our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods - run_script start_script key2sub xsys xqx mime_load); + run_script start_script key2sub xsys xqx mime_load eml_load); sub mime_load ($) { my ($path) = @_; @@ -17,6 +17,13 @@ sub mime_load ($) { PublicInbox::MIME->new(\(do { local $/; <$fh> })); } +sub eml_load ($) { + my ($path, $cb) = @_; + open(my $fh, '<', $path) or die "open $path: $!"; + binmode $fh; + PublicInbox::Eml->new(\(do { local $/; <$fh> })); +} + sub tmpdir (;$) { my ($base) = @_; require File::Temp; -- cgit v1.2.3-24-ge0c7