]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MdirReader.pm
get rid of unnecessary bytes::length usage
[public-inbox.git] / lib / PublicInbox / MdirReader.pm
index b49c8ceb86eec87d1f56da3e20b5fe3f858d34c2..dbb74d6d9772f85afb5b9b0fc4b4b07e1b61ac60 100644 (file)
@@ -42,9 +42,10 @@ sub maildir_each_file {
                my $pfx = $dir.$d;
                opendir my $dh, $pfx or next;
                while (defined(my $bn = readdir($dh))) {
-                       maildir_basename_flags($bn) // next;
+                       my $fl = maildir_basename_flags($bn) // next;
                        next if defined($mod) && !shard_ok($bn, $mod, $shard);
-                       $cb->($pfx.$bn, @arg);
+                       next if index($fl, 'T') >= 0; # no Trashed messages
+                       $cb->($pfx.$bn, $fl, @arg);
                }
        }
 }
@@ -61,7 +62,10 @@ sub maildir_each_eml {
                while (defined(my $bn = readdir($dh))) {
                        next if substr($bn, 0, 1) eq '.';
                        my @f = split(/:/, $bn, -1);
-                       next if scalar(@f) != 1;
+
+                       # mbsync and offlineimap both use "2," in "new/"
+                       next if ($f[1] // '2,') ne '2,' || defined($f[2]);
+
                        next if defined($mod) && !shard_ok($bn, $mod, $shard);
                        my $f = $pfx.$bn;
                        my $eml = eml_from_path($f) or next;
@@ -83,4 +87,22 @@ sub maildir_each_eml {
 
 sub new { bless {}, __PACKAGE__ }
 
+sub flags2kw ($) {
+       if (wantarray) {
+               my @unknown;
+               my %kw;
+               for (split(//, $_[0])) {
+                       my $k = $c2kw{$_};
+                       if (defined($k)) {
+                               $kw{$k} = 1;
+                       } else {
+                               push @unknown, $_;
+                       }
+               }
+               (\%kw, \@unknown);
+       } else {
+               [ sort(map { $c2kw{$_} // () } split(//, $_[0])) ];
+       }
+}
+
 1;