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 00/11] lei IMAP read support
@ 2021-02-17 10:06  7% Eric Wong
  2021-02-17 10:07  6% ` [PATCH 04/11] lei import: start rearranging code for IMAP support Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-02-17 10:06 UTC (permalink / raw)
  To: meta

IMAP write support for search results is planned, but testing
could get tricky...

Still unsure about some UI bits w.r.t --format/-f:
	https://public-inbox.org/meta/20210217044032.GA17934@dcvr/

convert and import should support parallel network xfers,
NNTP reads, and eventually JMAP...

convert and import don't support compressed mboxes, yet.

Eric Wong (11):
  lei: bless config
  watch: move imap_common_init to NetReader
  watch: connect to NNTP and IMAP in config order
  lei import: start rearranging code for IMAP support
  lei import: move check_input_format to lei
  tests: setup_public_inboxes: use IMAP-friendly newsgroups
  t/lei_to_mail: remove unnecessary arg passing
  lei convert: mail format conversion sub-command
  lei import: add IMAP, (maildir|mbox*):$PATHNAME support
  lei: consolidate the bulk of the IPC code
  lei: check for IMAP auth errors

 MANIFEST                         |  11 +-
 lib/PublicInbox/GitCredential.pm |  18 ++-
 lib/PublicInbox/LEI.pm           |  62 +++++++-
 lib/PublicInbox/LeiAuth.pm       |  70 +++++++++
 lib/PublicInbox/LeiConvert.pm    | 137 +++++++++++++++++
 lib/PublicInbox/LeiDedupe.pm     |   2 +-
 lib/PublicInbox/LeiImport.pm     | 156 +++++++++++++-------
 lib/PublicInbox/LeiMirror.pm     |  19 +--
 lib/PublicInbox/LeiOverview.pm   |   7 +-
 lib/PublicInbox/LeiToMail.pm     |   5 +-
 lib/PublicInbox/MdirReader.pm    |  26 ++++
 lib/PublicInbox/NetReader.pm     | 242 +++++++++++++++++++++++++++++--
 lib/PublicInbox/TestCommon.pm    |  15 +-
 lib/PublicInbox/Watch.pm         |  82 ++---------
 t/{home1 => home2}/.gitignore    |   0
 t/{home1 => home2}/Makefile      |   0
 t/{home1 => home2}/README        |   0
 t/lei-convert.t                  |  36 +++++
 t/lei-import-imap.t              |  28 ++++
 t/lei-import-maildir.t           |   4 +-
 t/lei_to_mail.t                  |  14 +-
 t/net_reader-imap.t              |  40 +++++
 xt/lei-auth-fail.t               |  20 +++
 23 files changed, 820 insertions(+), 174 deletions(-)
 create mode 100644 lib/PublicInbox/LeiAuth.pm
 create mode 100644 lib/PublicInbox/LeiConvert.pm
 rename t/{home1 => home2}/.gitignore (100%)
 rename t/{home1 => home2}/Makefile (100%)
 rename t/{home1 => home2}/README (100%)
 create mode 100644 t/lei-convert.t
 create mode 100644 t/lei-import-imap.t
 create mode 100644 t/net_reader-imap.t
 create mode 100644 xt/lei-auth-fail.t


^ permalink raw reply	[relevance 7%]

* [PATCH 04/11] lei import: start rearranging code for IMAP support
  2021-02-17 10:06  7% [PATCH 00/11] lei IMAP read support Eric Wong
@ 2021-02-17 10:07  6% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-02-17 10:07 UTC (permalink / raw)
  To: meta

More to come in a later commit; some error handling and failure
modes will be trickier with IMAP due to authentication.
---
 lib/PublicInbox/LeiImport.pm | 74 +++++++++++++++++++++++++-----------
 lib/PublicInbox/NetReader.pm | 19 +++++++++
 2 files changed, 71 insertions(+), 22 deletions(-)

diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm
index 8358d9d4..b25d7e97 100644
--- a/lib/PublicInbox/LeiImport.pm
+++ b/lib/PublicInbox/LeiImport.pm
@@ -29,26 +29,21 @@ sub import_done { # EOF callback for main daemon
 	$imp->wq_wait_old(\&import_done_wait, $lei);
 }
 
-sub call { # the main "lei import" method
-	my ($cls, $lei, @argv) = @_;
-	my $sto = $lei->_lei_store(1);
-	$sto->write_prepare($lei);
-	$lei->{opt}->{kw} //= 1;
+sub check_fmt ($;$) {
+	my ($lei, $f) = @_;
 	my $fmt = $lei->{opt}->{'format'};
-	my $self = $lei->{imp} = bless {}, $cls;
-	my @f;
-	for my $x (@argv) {
-		if (-f $x) { push @f, $x }
-		elsif (-d _) { require PublicInbox::MdirReader }
-	}
-	(@f && !$fmt) and
-		return $lei->fail("--format unset for regular file(s):\n@f");
-	if (@f && $fmt ne 'eml') {
-		require PublicInbox::MboxReader;
-		PublicInbox::MboxReader->can($fmt) or
-			return $lei->fail( "--format=$fmt unrecognized\n");
+	if (!$fmt) {
+		my $err = $f ? "regular file(s):\n@$f" : '--stdin';
+		return $lei->fail("--format unset for $err");
 	}
-	$self->{0} = $lei->{0} if $lei->{opt}->{stdin};
+	return 1 if $fmt eq 'eml';
+	require PublicInbox::MboxReader;
+	PublicInbox::MboxReader->can($fmt) ||
+				$lei->fail( "--format=$fmt unrecognized\n");
+}
+
+sub do_import {
+	my ($lei) = @_;
 	my $ops = {
 		'!' => [ $lei->can('fail_handler'), $lei ],
 		'x_it' => [ $lei->can('x_it'), $lei ],
@@ -56,14 +51,19 @@ sub call { # the main "lei import" method
 		'' => [ \&import_done, $lei ],
 	};
 	($lei->{pkt_op_c}, $lei->{pkt_op_p}) = PublicInbox::PktOp->pair($ops);
-	my $j = $lei->{opt}->{jobs} // scalar(@argv) || 1;
-	my $nproc = $self->detect_nproc;
-	$j = $nproc if $j > $nproc;
+	my $self = $lei->{imp};
+	my $j = $lei->{opt}->{jobs} // scalar(@{$self->{argv}}) || 1;
+	if (my $nrd = $lei->{nrd}) {
+		# $j = $nrd->net_concurrency($j); TODO
+	} else {
+		my $nproc = $self->detect_nproc;
+		$j = $nproc if $j > $nproc;
+	}
 	$self->wq_workers_start('lei_import', $j, $lei->oldset, {lei => $lei});
 	my $op = delete $lei->{pkt_op_c};
 	delete $lei->{pkt_op_p};
 	$self->wq_io_do('import_stdin', []) if $self->{0};
-	for my $x (@argv) {
+	for my $x (@{$self->{argv}}) {
 		$self->wq_io_do('import_path_url', [], $x);
 	}
 	$self->wq_close(1);
@@ -73,6 +73,36 @@ sub call { # the main "lei import" method
 	}
 }
 
+sub call { # the main "lei import" method
+	my ($cls, $lei, @argv) = @_;
+	my $sto = $lei->_lei_store(1);
+	$sto->write_prepare($lei);
+	$lei->{opt}->{kw} //= 1;
+	my $self = $lei->{imp} = bless { argv => \@argv }, $cls;
+	if ($lei->{opt}->{stdin}) {
+		@argv and return
+			$lei->fail("--stdin and locations (@argv) do not mix");
+		check_fmt($lei) or return;
+		$self->{0} = $lei->{0};
+	} else {
+		my @f;
+		for my $x (@argv) {
+			if (-f $x) { push @f, $x }
+			elsif (-d _) { require PublicInbox::MdirReader }
+			else {
+				require PublicInbox::NetReader;
+				$lei->{nrd} //= PublicInbox::NetReader->new;
+				$lei->{nrd}->add_url($x);
+			}
+		}
+		if (@f) { check_fmt($lei, \@f) or return }
+		if ($lei->{nrd} && (my @err = $lei->{nrd}->errors)) {
+			return $lei->fail(@err);
+		}
+	}
+	do_import($lei);
+}
+
 sub ipc_atfork_child {
 	my ($self) = @_;
 	$self->{lei}->lei_atfork_child;
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index fa337bcd..1d053425 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -280,4 +280,23 @@ sub imap_common_init ($) {
 	$mics;
 }
 
+sub add_url {
+	my ($self, $arg) = @_;
+	if (my $url = imap_url($arg)) {
+		push @{$self->{imap_order}}, $url;
+	} else {
+		push @{$self->{unsupported_url}}, $arg;
+	}
+}
+
+sub errors {
+	my ($self) = @_;
+	if (my $u = $self->{unsupported_url}) {
+		return "Unsupported URL(s): @$u";
+	}
+	undef;
+}
+
+sub new { bless {}, shift };
+
 1;

^ permalink raw reply related	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-02-17 10:06  7% [PATCH 00/11] lei IMAP read support Eric Wong
2021-02-17 10:07  6% ` [PATCH 04/11] lei import: start rearranging code for IMAP support 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).