user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 0/8] some small yak shaving things
@ 2020-04-18  3:38  7% Eric Wong
  2020-04-18  3:38  5% ` [PATCH 1/8] inboxwritable: mime_from_path: reuse in more places Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-04-18  3:38 UTC (permalink / raw)
  To: meta

Eric Wong (8):
  inboxwritable: mime_from_path: reuse in more places
  searchidx: die on cat-file failures
  inbox: do not memoize description or cloneurl if missing
  inbox: replace `eval {}' with `do {}' where appropriate
  favor `do {}' over `eval {}' for localized slurp
  wwwatomstream: move {emit_header} field to $self
  mbox: use per-message line-ending for From_ line
  reduce scope of mbox From_ line removal

 Documentation/mknews.perl               |  2 +-
 MANIFEST                                |  4 ++--
 lib/PublicInbox/Inbox.pm                | 27 ++++++++++++------------
 lib/PublicInbox/InboxWritable.pm        |  4 ++--
 lib/PublicInbox/Mbox.pm                 |  7 +++++--
 lib/PublicInbox/NNTP.pm                 |  2 ++
 lib/PublicInbox/SearchIdx.pm            | 14 +++++--------
 lib/PublicInbox/WatchMaildir.pm         |  6 +++---
 lib/PublicInbox/WwwAtomStream.pm        |  5 ++---
 script/public-inbox-edit                |  5 ++---
 script/public-inbox-learn               |  6 +++---
 script/public-inbox-mda                 |  2 +-
 script/public-inbox-purge               |  2 +-
 scripts/import_maildir                  |  4 ++--
 scripts/import_slrnspool                |  2 +-
 scripts/slrnspool2maildir               |  2 +-
 scripts/ssoma-replay                    |  5 +----
 t/inbox.t                               | 19 +++++++++++++++++
 t/{iso-2202-jp.mbox => iso-2202-jp.eml} |  1 -
 t/mda.t                                 | 10 ++++-----
 t/msg_iter.t                            | 18 ++++++----------
 t/nntpd-tls.t                           |  8 +++----
 t/psgi_v2.t                             | 28 ++++++++++++++++---------
 t/search.t                              | 12 ++++-------
 t/solver_git.t                          |  4 ++--
 t/{utf8.mbox => utf8.eml}               |  1 -
 t/v2reindex.t                           |  3 +--
 t/watch_maildir_v2.t                    |  2 +-
 28 files changed, 105 insertions(+), 100 deletions(-)
 rename t/{iso-2202-jp.mbox => iso-2202-jp.eml} (84%)
 rename t/{utf8.mbox => utf8.eml} (90%)

^ permalink raw reply	[relevance 7%]

* [PATCH 1/8] inboxwritable: mime_from_path: reuse in more places
  2020-04-18  3:38  7% [PATCH 0/8] some small yak shaving things Eric Wong
@ 2020-04-18  3:38  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-04-18  3:38 UTC (permalink / raw)
  To: meta

There's nothing Maildir-specific about the function, so
`maildir_path_load' was a bad name.  So give it a more
appropriate name and use it in our tests.

This save ourselves some code and inconsistency by reusing an
existing internal library routine in more places.  We can drop
the "From_" line in some of our (formerly) mbox sample files.
---
 MANIFEST                                |  4 ++--
 lib/PublicInbox/InboxWritable.pm        |  4 ++--
 lib/PublicInbox/WatchMaildir.pm         |  6 +++---
 script/public-inbox-edit                |  5 ++---
 t/{iso-2202-jp.mbox => iso-2202-jp.eml} |  1 -
 t/mda.t                                 | 10 ++++------
 t/msg_iter.t                            | 18 ++++++------------
 t/nntpd-tls.t                           |  8 +++-----
 t/search.t                              | 12 ++++--------
 t/solver_git.t                          |  4 ++--
 t/{utf8.mbox => utf8.eml}               |  1 -
 11 files changed, 28 insertions(+), 45 deletions(-)
 rename t/{iso-2202-jp.mbox => iso-2202-jp.eml} (84%)
 rename t/{utf8.mbox => utf8.eml} (90%)

diff --git a/MANIFEST b/MANIFEST
index ba5cc6a4..92cda5d8 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -253,7 +253,7 @@ t/index-git-times.t
 t/indexlevels-mirror-v1.t
 t/indexlevels-mirror.t
 t/init.t
-t/iso-2202-jp.mbox
+t/iso-2202-jp.eml
 t/linkify.t
 t/main-bin/spamc
 t/mda.t
@@ -294,7 +294,7 @@ t/spamcheck_spamc.t
 t/spawn.t
 t/thread-cycle.t
 t/time.t
-t/utf8.mbox
+t/utf8.eml
 t/v1-add-remove-add.t
 t/v1reindex.t
 t/v2-add-remove-add.t
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index f2ba21fc..31aa76c6 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -111,7 +111,7 @@ sub is_maildir_path ($) {
 	(is_maildir_basename($p[-1]) && -f $path) ? 1 : 0;
 }
 
-sub maildir_path_load ($) {
+sub mime_from_path ($) {
 	my ($path) = @_;
 	if (open my $fh, '<', $path) {
 		local $/;
@@ -138,7 +138,7 @@ sub import_maildir {
 		opendir my $dh, "$dir/$sub" or die "opendir $dir/$sub: $!\n";
 		while (defined(my $fn = readdir($dh))) {
 			next unless is_maildir_basename($fn);
-			my $mime = maildir_path_load("$dir/$fn") or next;
+			my $mime = mime_from_path("$dir/$fn") or next;
 
 			if (my $filter = $self->filter($im)) {
 				my $ret = $filter->scrub($mime) or return;
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index e2024640..bea2ed2a 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -11,7 +11,7 @@ use PublicInbox::InboxWritable;
 use File::Temp 0.19 (); # 0.19 for ->newdir
 use PublicInbox::Filter::Base qw(REJECT);
 use PublicInbox::Spamcheck;
-*maildir_path_load = *PublicInbox::InboxWritable::maildir_path_load;
+*mime_from_path = \&PublicInbox::InboxWritable::mime_from_path;
 
 sub new {
 	my ($class, $config) = @_;
@@ -123,7 +123,7 @@ sub _remove_spam {
 	my ($self, $path) = @_;
 	# path must be marked as (S)een
 	$path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
-	my $mime = maildir_path_load($path) or return;
+	my $mime = mime_from_path($path) or return;
 	$self->{config}->each_inbox(sub {
 		my ($ibx) = @_;
 		eval {
@@ -165,7 +165,7 @@ sub _try_path {
 		$warn_cb->(@_);
 	};
 	foreach my $ibx (@$inboxes) {
-		my $mime = maildir_path_load($path) or next;
+		my $mime = mime_from_path($path) or next;
 		my $im = _importer_for($self, $ibx);
 
 		# any header match means it's eligible for the inbox:
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index ae5d8289..28b1b5e8 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -92,9 +92,8 @@ Multiple messages with different content found matching
 		warn "Will edit all of them\n";
 	}
 } else {
-	open my $fh, '<', $file or die "open($file) failed: $!";
-	my $orig = do { local $/; <$fh> };
-	my $mime = PublicInbox::MIME->new(\$orig);
+	my $mime = PublicInbox::InboxWritable::mime_from_path($file) or
+		die "open($file) failed: $!";
 	my $mids = mids($mime->header_obj);
 	find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
 	my $cid = content_id($mime);
diff --git a/t/iso-2202-jp.mbox b/t/iso-2202-jp.eml
similarity index 84%
rename from t/iso-2202-jp.mbox
rename to t/iso-2202-jp.eml
index 1a8e1974..9e0bbad4 100644
--- a/t/iso-2202-jp.mbox
+++ b/t/iso-2202-jp.eml
@@ -1,4 +1,3 @@
-From historical@ruby-dev Thu Jan  1 00:00:00 1970
 Message-Id: <199707281508.AAA24167@hoyogw.example>
 Date: Tue, 29 Jul 97 00:08:29 +0900
 From: matz@example.com
diff --git a/t/mda.t b/t/mda.t
index ddc0c279..ec09cf69 100644
--- a/t/mda.t
+++ b/t/mda.t
@@ -7,6 +7,7 @@ use Email::MIME;
 use Cwd qw(getcwd);
 use PublicInbox::MID qw(mid2path);
 use PublicInbox::Git;
+use PublicInbox::InboxWritable;
 use PublicInbox::TestCommon;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
@@ -62,12 +63,9 @@ local $ENV{GIT_COMMITTER_NAME} = eval {
 	use PublicInbox::MDA;
 	use PublicInbox::Address;
 	use Encode qw/encode/;
-	my $mbox = 't/utf8.mbox';
-	open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
-	my $str = eval { local $/; <$fh> };
-	close $fh;
-	my $msg = Email::MIME->new($str);
-
+	my $eml = 't/utf8.eml';
+	my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or
+		die "failed to open $eml: $!";
 	my $from = $msg->header('From');
 	my ($author) = PublicInbox::Address::names($from);
 	my ($email) = PublicInbox::Address::emails($from);
diff --git a/t/msg_iter.t b/t/msg_iter.t
index d303564f..573ee412 100644
--- a/t/msg_iter.t
+++ b/t/msg_iter.t
@@ -5,6 +5,7 @@ use warnings;
 use Test::More;
 use Email::MIME;
 use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::InboxWritable;
 use_ok('PublicInbox::MsgIter');
 
 {
@@ -42,12 +43,9 @@ use_ok('PublicInbox::MsgIter');
 }
 
 {
-	my $f = 't/iso-2202-jp.mbox';
-	my $mime = Email::MIME->new(do {
-		open my $fh, '<', $f or die "open($f): $!";
-		local $/;
-		<$fh>;
-	});
+	my $f = 't/iso-2202-jp.eml';
+	my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
+		die "open $f: $!";
 	my $raw = '';
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
@@ -61,12 +59,8 @@ use_ok('PublicInbox::MsgIter');
 
 {
 	my $f = 't/x-unknown-alpine.eml';
-	my $mime = Email::MIME->new(do {
-		open my $fh, '<', $f or die "open($f): $!";
-		local $/;
-		binmode $fh;
-		<$fh>;
-	});
+	my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
+		die "open $f: $!";
 	my $raw = '';
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t
index 0714631d..a0522e1f 100644
--- a/t/nntpd-tls.t
+++ b/t/nntpd-tls.t
@@ -63,11 +63,9 @@ EOF
 
 {
 	my $im = $ibx->importer(0);
-	my $mime = PublicInbox::MIME->new(do {
-		open my $fh, '<', 't/data/0001.patch' or die;
-		local $/;
-		<$fh>
-	});
+	my $eml = 't/data/0001.patch';
+	my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
+		die "open $eml: $!";
 	ok($im->add($mime), 'message added');
 	$im->done;
 	if ($version == 1) {
diff --git a/t/search.t b/t/search.t
index 839a320a..101d44e9 100644
--- a/t/search.t
+++ b/t/search.t
@@ -7,6 +7,7 @@ use PublicInbox::TestCommon;
 require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::SearchIdx;
 require PublicInbox::Inbox;
+require PublicInbox::InboxWritable;
 use Email::MIME;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/a.git";
@@ -290,14 +291,9 @@ $ibx->with_umask(sub {
 });
 
 $ibx->with_umask(sub {
-	my $str = eval {
-		my $mbox = 't/utf8.mbox';
-		open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
-		local $/;
-		<$fh>
-	};
-	$str =~ s/\AFrom [^\n]+\n//s;
-	my $mime = Email::MIME->new($str);
+	my $eml = 't/utf8.eml';
+	my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
+		die "open $eml: $!";
 	my $doc_id = $rw->add_message($mime);
 	ok($doc_id > 0, 'message indexed doc_id with UTF-8');
 	my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
diff --git a/t/solver_git.t b/t/solver_git.t
index 2dbb07b0..7f0cd999 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -28,8 +28,8 @@ my $im = PublicInbox::V2Writable->new($ibx, 1);
 $im->{parallel} = 0;
 
 my $deliver_patch = sub ($) {
-	open my $fh, '<', $_[0] or die "open: $!";
-	my $mime = PublicInbox::MIME->new(do { local $/; <$fh> });
+	my $mime = PublicInbox::InboxWritable::mime_from_path($_[0]) or
+		die "open $_[0]: $!";
 	$im->add($mime);
 	$im->done;
 };
diff --git a/t/utf8.mbox b/t/utf8.eml
similarity index 90%
rename from t/utf8.mbox
rename to t/utf8.eml
index cebaf9b0..9bf1002c 100644
--- a/t/utf8.mbox
+++ b/t/utf8.eml
@@ -1,4 +1,3 @@
-From e@yhbt.net Thu Jan 01 00:00:00 1970
 Date: Thu, 01 Jan 1970 00:00:00 +0000
 To: =?utf-8?Q?El=C3=A9anor?= <e@example.com>
 From: =?utf-8?Q?El=C3=A9anor?= <e@example.com>

^ permalink raw reply related	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-04-18  3:38  7% [PATCH 0/8] some small yak shaving things Eric Wong
2020-04-18  3:38  5% ` [PATCH 1/8] inboxwritable: mime_from_path: reuse in more places Eric Wong

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).