user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] net_reader|net_writer: pass URI refs deeper into callbacks
Date: Sun, 23 May 2021 01:38:26 +0000	[thread overview]
Message-ID: <20210523013828.4888-2-e@80x24.org> (raw)
In-Reply-To: <20210523013828.4888-1-e@80x24.org>

This will give us more flexibility in the future w.r.t.
dealing with UIDVALIDITY and AUTH= info with IMAP.  The LoC
reduction is welcome, too.
---
 lib/PublicInbox/LeiImport.pm |  4 ++--
 lib/PublicInbox/LeiToMail.pm |  4 ++--
 lib/PublicInbox/NetReader.pm | 11 +++++------
 lib/PublicInbox/NetWriter.pm | 12 ++++--------
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm
index 55925cc5..01e6c93c 100644
--- a/lib/PublicInbox/LeiImport.pm
+++ b/lib/PublicInbox/LeiImport.pm
@@ -42,9 +42,9 @@ sub input_maildir_cb { # maildir_each_eml cb
 }
 
 sub input_net_cb { # imap_each / nntp_each
-	my ($url, $uid, $kw, $eml, $self) = @_;
+	my ($uri, $uid, $kw, $eml, $self) = @_;
 	my $vmd = $self->{-import_kw} ? { kw => $kw } : undef;
-	$vmd->{sync_info} = [ $url, $uid ] if $self->{-mail_sync};
+	$vmd->{sync_info} = [ $$uri, $uid ] if $self->{-mail_sync};
 	$self->input_eml_cb($eml, $vmd);
 }
 
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 96a1f881..b9d4c856 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -452,10 +452,10 @@ sub _do_augment_maildir {
 }
 
 sub _imap_augment_or_delete { # PublicInbox::NetReader::imap_each cb
-	my ($url, $uid, $kw, $eml, $lei, $lse, $delete_mic) = @_;
+	my ($uri, $uid, $kw, $eml, $lei, $lse, $delete_mic) = @_;
 	update_kw_maybe($lei, $lse, $eml, $kw);
 	if ($delete_mic) {
-		$lei->{net}->imap_delete_1($url, $uid, $delete_mic);
+		$lei->{net}->imap_delete_1($uri, $uid, $delete_mic);
 	} else {
 		_augment($eml, $lei);
 	}
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index a532b218..73b8b1cd 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -397,7 +397,7 @@ sub errors {
 }
 
 sub _imap_do_msg ($$$$$) {
-	my ($self, $url, $uid, $raw, $flags) = @_;
+	my ($self, $uri, $uid, $raw, $flags) = @_;
 	# our target audience expects LF-only, save storage
 	$$raw =~ s/\r\n/\n/sg;
 	my $kw = [];
@@ -408,12 +408,12 @@ sub _imap_do_msg ($$$$$) {
 		} elsif ($f eq "\\Deleted") { # not in JMAP
 			return;
 		} elsif ($self->{verbose}) {
-			warn "# unknown IMAP flag $f <$url/;UID=$uid>\n";
+			warn "# unknown IMAP flag $f <$uri/;UID=$uid>\n";
 		}
 	}
 	@$kw = sort @$kw; # for all UI/UX purposes
 	my ($eml_cb, @args) = @{$self->{eml_each}};
-	$eml_cb->($url, $uid, $kw, PublicInbox::Eml->new($raw), @args);
+	$eml_cb->($uri, $uid, $kw, PublicInbox::Eml->new($raw), @args);
 }
 
 sub run_commit_cb ($) {
@@ -532,7 +532,7 @@ EOF
 				# messages get deleted, so holes appear
 				my $per_uid = delete $r->{$uid} // next;
 				my $raw = delete($per_uid->{$key}) // next;
-				_imap_do_msg($self, $$uri, $uid, \$raw,
+				_imap_do_msg($self, $uri, $uid, \$raw,
 						$per_uid->{FLAGS});
 				$last_uid = $uid;
 				last if $self->{quit};
@@ -638,7 +638,6 @@ sub _nntp_fetch_all ($$$) {
 		warn "# $uri fetching ARTICLE $beg..$end\n";
 	}
 	my $n = $self->{max_batch};
-	my $url = $$uri;
 	for ($beg..$end) {
 		last if $self->{quit};
 		$art = $_;
@@ -661,7 +660,7 @@ sub _nntp_fetch_all ($$$) {
 		$raw = join('', @$raw);
 		$raw =~ s/\r\n/\n/sg;
 		my ($eml_cb, @args) = @{$self->{eml_each}};
-		$eml_cb->($url, $art, $kw, PublicInbox::Eml->new(\$raw), @args);
+		$eml_cb->($uri, $art, $kw, PublicInbox::Eml->new(\$raw), @args);
 		$last_art = $art;
 	}
 	run_commit_cb($self);
diff --git a/lib/PublicInbox/NetWriter.pm b/lib/PublicInbox/NetWriter.pm
index 06d69f27..2032a1fd 100644
--- a/lib/PublicInbox/NetWriter.pm
+++ b/lib/PublicInbox/NetWriter.pm
@@ -28,18 +28,14 @@ sub imap_append {
 
 sub mic_for_folder {
 	my ($self, $uri) = @_;
-	if (!ref($uri)) {
-		my $u = PublicInbox::URIimap->new($uri);
-		$_[1] = $uri = $u;
-	}
 	my $mic = $self->mic_get($uri) or die "E: not connected: $@";
 	$mic->select($uri->mailbox) or return;
 	$mic;
 }
 
 sub imap_delete_all {
-	my ($self, $url) = @_;
-	my $mic = mic_for_folder($self, my $uri = $url) or return;
+	my ($self, $uri) = @_;
+	my $mic = mic_for_folder($self, $uri) or return;
 	my $sec = $self->can('uri_section')->($uri);
 	local $0 = $uri->mailbox." $sec";
 	if ($mic->delete_message('1:*')) {
@@ -48,8 +44,8 @@ sub imap_delete_all {
 }
 
 sub imap_delete_1 {
-	my ($self, $url, $uid, $delete_mic) = @_;
-	$$delete_mic //= mic_for_folder($self, my $uri = $url) or return;
+	my ($self, $uri, $uid, $delete_mic) = @_;
+	$$delete_mic //= mic_for_folder($self, $uri) or return;
 	$$delete_mic->delete_message($uid);
 }
 

  reply	other threads:[~2021-05-23  1:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23  1:38 [PATCH 0/3] lei export-kw: IMAP support Eric Wong
2021-05-23  1:38 ` Eric Wong [this message]
2021-05-23  1:38 ` [PATCH 2/3] lei export-kw: support exporting keywords to IMAP Eric Wong
2021-05-23  1:38 ` [PATCH 3/3] lei export-kw: relax IMAP URL matching 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: https://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=20210523013828.4888-2-e@80x24.org \
    --to=e@80x24.org \
    --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).