]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MdirReader.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / MdirReader.pm
index b49c8ceb86eec87d1f56da3e20b5fe3f858d34c2..db5f4545125f051510ae3b6df2a0db923b014602 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Maildirs for now, MH eventually
@@ -8,7 +8,7 @@ package PublicInbox::MdirReader;
 use strict;
 use v5.10.1;
 use PublicInbox::InboxWritable qw(eml_from_path);
-use Digest::SHA qw(sha256_hex);
+use PublicInbox::SHA qw(sha256_hex);
 
 # returns Maildir flags from a basename ('' for no flags, undef for invalid)
 sub maildir_basename_flags {
@@ -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;