+# may be overridden in NetWriter or Watch
+sub folder_select { $_[0]->{each_old} ? 'select' : 'examine' }
+
+sub _imap_fetch_bodies ($$$$) {
+ my ($self, $mic, $uri, $uids) = @_;
+ my $req = $mic->imap4rev1 ? 'BODY.PEEK[]' : 'RFC822.PEEK';
+ my $key = $req;
+ $key =~ s/\.PEEK//;
+ my $sec = uri_section($uri);
+ my $mbx = $uri->mailbox;
+ my $bs = $self->{cfg_opt}->{$sec}->{batch_size} // 1;
+ my ($last_uid, $err);
+ my $use_fl = $self->{-use_fl};
+
+ while (scalar @$uids) {
+ my @batch = splice(@$uids, 0, $bs);
+ my $batch = join(',', @batch);
+ local $0 = "UID:$batch $mbx $sec";
+ my $r = $mic->fetch_hash($batch, $req, 'FLAGS');
+ unless ($r) { # network error?
+ last if $!{EINTR} && $self->{quit};
+ $err = "E: $uri UID FETCH $batch error: $!";
+ last;
+ }
+ for my $uid (@batch) {
+ # messages get deleted, so holes appear
+ my $per_uid = delete $r->{$uid} // next;
+ my $raw = delete($per_uid->{$key}) // next;
+ my $fl = $use_fl ? $per_uid->{FLAGS} : undef;
+ _imap_do_msg($self, $uri, $uid, \$raw, $fl);
+ $last_uid = $uid;
+ last if $self->{quit};
+ }
+ last if $self->{quit};
+ }
+ ($last_uid, $err);
+}
+