about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-17 09:06:59 -0100
committerEric Wong <e@80x24.org>2021-02-18 03:57:16 -0400
commitd05c52bbd84ec2df01801c62964e24f960c6cfdf (patch)
treef65c0e17cc42e971285ecd67b11a565bbc54e349 /lib
parent91dcd73962822e45fb0a768cf91d0e4e64a408a5 (diff)
downloadpublic-inbox-d05c52bbd84ec2df01801c62964e24f960c6cfdf.tar.gz
This is hopefully less surprising to users when they're prompted
for credentials.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/NetReader.pm4
-rw-r--r--lib/PublicInbox/Watch.pm17
2 files changed, 14 insertions, 7 deletions
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 8c919f66..fa337bcd 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -249,7 +249,7 @@ sub imap_common_init ($) {
         require PublicInbox::URIimap;
         my $cfg = $self->{pi_cfg};
         my $mic_args = {}; # scheme://authority => Mail:IMAPClient arg
-        for my $url (sort keys %{$self->{imap}}) {
+        for my $url (@{$self->{imap_order}}) {
                 my $uri = PublicInbox::URIimap->new($url);
                 my $sec = uri_section($uri);
                 for my $k (qw(Starttls Debug Compress)) {
@@ -273,7 +273,7 @@ sub imap_common_init ($) {
         # make sure we can connect and cache the credentials in memory
         $self->{mic_arg} = {}; # schema://authority => IMAPClient->new args
         my $mics = {}; # schema://authority => IMAPClient obj
-        for my $url (sort keys %{$self->{imap}}) {
+        for my $url (@{$self->{imap_order}}) {
                 my $uri = PublicInbox::URIimap->new($url);
                 $mics->{uri_section($uri)} //= mic_for($self, $url, $mic_args);
         }
diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 6b6be44c..c64689a1 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -46,6 +46,7 @@ sub new {
         my ($class, $cfg) = @_;
         my (%mdmap, $spamc);
         my (%imap, %nntp); # url => [inbox objects] or 'watchspam'
+        my (@imap, @nntp);
 
         # "publicinboxwatch" is the documented namespace
         # "publicinboxlearn" is legacy but may be supported
@@ -61,8 +62,10 @@ sub new {
                                 $mdmap{"$dir/cur"} = 'watchspam';
                         } elsif ($url = imap_url($dir)) {
                                 $imap{$url} = 'watchspam';
+                                push @imap, $url;
                         } elsif ($url = nntp_url($dir)) {
                                 $nntp{$url} = 'watchspam';
+                                push @nntp, $url;
                         } else {
                                 warn "unsupported $k=$dir\n";
                         }
@@ -92,11 +95,13 @@ sub new {
                         } elsif ($url = imap_url($watch)) {
                                 return if is_watchspam($url, $imap{$url}, $ibx);
                                 compile_watchheaders($ibx);
-                                push @{$imap{$url} ||= []}, $ibx;
+                                my $n = push @{$imap{$url} ||= []}, $ibx;
+                                push @imap, $url if $n == 1;
                         } elsif ($url = nntp_url($watch)) {
                                 return if is_watchspam($url, $nntp{$url}, $ibx);
                                 compile_watchheaders($ibx);
-                                push @{$nntp{$url} ||= []}, $ibx;
+                                my $n = push @{$nntp{$url} ||= []}, $ibx;
+                                push @nntp, $url if $n == 1;
                         } else {
                                 warn "watch unsupported: $k=$watch\n";
                         }
@@ -118,6 +123,8 @@ sub new {
                 pi_cfg => $cfg,
                 imap => scalar keys %imap ? \%imap : undef,
                 nntp => scalar keys %nntp? \%nntp : undef,
+                imap_order => scalar(@imap) ? \@imap : undef,
+                nntp_order => scalar(@nntp) ? \@nntp: undef,
                 importers => {},
                 opendirs => {}, # dirname => dirhandle (in progress scans)
                 ops => [], # 'quit', 'full'
@@ -643,7 +650,7 @@ sub nntp_common_init ($) {
         my ($self) = @_;
         my $cfg = $self->{pi_cfg};
         my $nn_args = {}; # scheme://authority => Net::NNTP->new arg
-        for my $url (sort keys %{$self->{nntp}}) {
+        for my $url (@{$self->{nntp_order}}) {
                 my $sec = uri_section(uri_new($url));
 
                 # Debug and Timeout are passed to Net::NNTP->new
@@ -755,10 +762,10 @@ sub watch_nntp_init ($$) {
 
         # make sure we can connect and cache the credentials in memory
         $self->{nn_arg} = {}; # schema://authority => Net::NNTP->new args
-        for my $url (sort keys %{$self->{nntp}}) {
+        for my $url (@{$self->{nntp_order}}) {
                 nn_for($self, $url, $nn_args);
         }
-        for my $url (keys %{$self->{nntp}}) {
+        for my $url (@{$self->{nntp_order}}) {
                 my $uri = uri_new($url);
                 my $sec = uri_section($uri);
                 my $intvl = $self->{nntp_opt}->{$sec}->{pollInterval};