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 2/3] import_mbox: use MboxReader
  2021-02-12  7:05  6% [PATCH 0/3] MboxReader usage and changes Eric Wong
@ 2021-02-12  7:05  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-02-12  7:05 UTC (permalink / raw)
  To: meta

It supports more mbox variants and it's trailing newline
behavior is probably more correct despite the previous change
to PublicInbox::Filter::Vger.
---
 lib/PublicInbox/InboxWritable.pm | 44 +++++++-------------------------
 1 file changed, 9 insertions(+), 35 deletions(-)

diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index c3acc4f9..d4a9040f 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -158,49 +158,23 @@ sub import_maildir {
 	$im->done;
 }
 
-# asctime: From example@example.com Fri Jun 23 02:56:55 2000
-my $from_strict = qr/^From \S+ +\S+ \S+ +\S+ [^:]+:[^:]+:[^:]+ [^:]+/;
-
-sub mb_add ($$$$) {
-	my ($im, $variant, $filter, $msg) = @_;
-	$$msg =~ s/(\r?\n)+\z/$1/s;
-	if ($variant eq 'mboxrd') {
-		$$msg =~ s/^>(>*From )/$1/gms;
-	} elsif ($variant eq 'mboxo') {
-		$$msg =~ s/^>From /From /gms;
-	}
-	my $mime = PublicInbox::Eml->new($msg);
+sub _mbox_eml_cb { # MboxReader->mbox* callback
+	my ($eml, $im, $filter) = @_;
 	if ($filter) {
-		my $ret = $filter->scrub($mime) or return;
+		my $ret = $filter->scrub($eml) or return;
 		return if $ret == REJECT();
-		$mime = $ret;
+		$eml = $ret;
 	}
-	$im->add($mime)
+	$im->add($eml);
 }
 
 sub import_mbox {
 	my ($self, $fh, $variant) = @_;
-	if ($variant !~ /\A(?:mboxrd|mboxo)\z/) {
-		die "variant must be 'mboxrd' or 'mboxo'\n";
-	}
+	require PublicInbox::MboxReader;
+	my $cb = PublicInbox::MboxReader->can($variant) or
+		die "$variant not supported\n";
 	my $im = $self->importer(1);
-	my $prev = undef;
-	my $msg = '';
-	my $filter = $self->filter;
-	while (defined(my $l = <$fh>)) {
-		if ($l =~ /$from_strict/o) {
-			if (!defined($prev) || $prev =~ /^\r?$/) {
-				mb_add($im, $variant, $filter, \$msg) if $msg;
-				$msg = '';
-				$prev = $l;
-				next;
-			}
-			warn "W[$.] $l\n";
-		}
-		$prev = $l;
-		$msg .= $l;
-	}
-	mb_add($im, $variant, $filter, \$msg) if $msg;
+	$cb->(undef, $fh, \&_mbox_eml_cb, $im, $self->filter);
 	$im->done;
 }
 

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/3] MboxReader usage and changes
@ 2021-02-12  7:05  6% Eric Wong
  2021-02-12  7:05  7% ` [PATCH 2/3] import_mbox: use MboxReader Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-02-12  7:05 UTC (permalink / raw)
  To: meta

*** BLURB HERE ***

Eric Wong (3):
  filter/vger: kill trailing newlines aggressively
  import_mbox: use MboxReader
  mbox_reader: do not chomp non-blank EOL

 lib/PublicInbox/Filter/Vger.pm   |  2 +-
 lib/PublicInbox/InboxWritable.pm | 44 +++++++-------------------------
 lib/PublicInbox/MboxReader.pm    |  2 +-
 t/mbox_reader.t                  | 22 +++++++++++++++-
 4 files changed, 32 insertions(+), 38 deletions(-)


^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-02-12  7:05  6% [PATCH 0/3] MboxReader usage and changes Eric Wong
2021-02-12  7:05  7% ` [PATCH 2/3] import_mbox: use MboxReader 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).