]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NetReader.pm
get rid of unnecessary bytes::length usage
[public-inbox.git] / lib / PublicInbox / NetReader.pm
index 2795a9d4d85e4bbc21c7669a13825db1d6870ba8..23445e7a49f2200834ae5571464c97d6c00b560d 100644 (file)
@@ -236,18 +236,19 @@ W: see https://rt.cpan.org/Ticket/Display.html?id=129967 for updates
 }
 
 sub imap_uri {
-       my ($url) = @_;
+       my ($url, $ls_ok) = @_;
        require PublicInbox::URIimap;
        my $uri = PublicInbox::URIimap->new($url);
-       $uri ? $uri->canonical : undef;
+       $uri && ($ls_ok || $uri->mailbox) ? $uri->canonical : undef;
 }
 
 my %IS_NNTP = (news => 1, snews => 1, nntp => 1, nntps => 1);
 sub nntp_uri {
-       my ($url) = @_;
+       my ($url, $ls_ok) = @_;
        require PublicInbox::URInntps;
        my $uri = PublicInbox::URInntps->new($url);
-       $uri && $IS_NNTP{$uri->scheme} && $uri->group ? $uri->canonical : undef;
+       $uri && $IS_NNTP{$uri->scheme} && ($ls_ok || $uri->group) ?
+               $uri->canonical : undef;
 }
 
 sub cfg_intvl ($$$) {
@@ -367,11 +368,13 @@ sub nntp_common_init ($;$) {
 }
 
 sub add_url {
-       my ($self, $arg) = @_;
+       my ($self, $arg, $ls_ok) = @_;
        my $uri;
-       if ($uri = imap_uri($arg)) {
+       if ($uri = imap_uri($arg, $ls_ok)) {
+               $_[1] = $$uri; # canonicalized
                push @{$self->{imap_order}}, $uri;
-       } elsif ($uri = nntp_uri($arg)) {
+       } elsif ($uri = nntp_uri($arg, $ls_ok)) {
+               $_[1] = $$uri; # canonicalized
                push @{$self->{nntp_order}}, $uri;
        } else {
                push @{$self->{unsupported_url}}, $arg;
@@ -417,7 +420,8 @@ sub _imap_do_msg ($$$$$) {
        my ($self, $uri, $uid, $raw, $flags) = @_;
        # our target audience expects LF-only, save storage
        $$raw =~ s/\r\n/\n/sg;
-       my $kw = flags2kw($self, $uri, $uid, $flags) // return;
+       my $kw = defined($flags) ?
+               (flags2kw($self, $uri, $uid, $flags) // return) : undef;
        my ($eml_cb, @args) = @{$self->{eml_each}};
        $eml_cb->($uri, $uid, $kw, PublicInbox::Eml->new($raw), @args);
 }
@@ -458,8 +462,9 @@ sub each_old_flags ($$$$) {
        my ($self, $mic, $uri, $l_uid) = @_;
        $l_uid ||= 1;
        my $sec = uri_section($uri);
-       my $bs = $self->{imap_opt}->{$sec}->{batch_size} // 10000;
+       my $bs = ($self->{imap_opt}->{$sec}->{batch_size} // 1) * 10000;
        my ($eml_cb, @args) = @{$self->{eml_each}};
+       $self->{quiet} or warn "# $uri syncing flags 1:$l_uid\n";
        for (my $n = 1; $n <= $l_uid; $n += $bs) {
                my $end = $n + $bs;
                $end = $l_uid if $end > $l_uid;
@@ -534,8 +539,8 @@ E: $uri strangely, UIDVALIDLITY matches ($l_uidval)
 EOF
        $mic->Uid(1); # the default, we hope
        my $err;
-       if (!defined($single_uid) && $self->{each_old} &&
-                               perm_fl_ok($perm_fl)) {
+       my $use_fl = perm_fl_ok($perm_fl);
+       if (!defined($single_uid) && $self->{each_old} && $use_fl) {
                $err = each_old_flags($self, $mic, $uri, $l_uid);
                return $err if $err;
        }
@@ -590,8 +595,8 @@ 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,
-                                               $per_uid->{FLAGS});
+                               my $fl = $use_fl ? $per_uid->{FLAGS} : undef;
+                               _imap_do_msg($self, $uri, $uid, \$raw, $fl);
                                $last_uid = $uid;
                                last if $self->{quit};
                        }