about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-05-19 08:54:13 +0000
committerEric Wong <e@80x24.org>2021-05-19 17:55:47 +0000
commit2f720902ed702b64d918165ba21a96dabbeeca26 (patch)
treecd1097510c7c635d58c21c79afd024f0837f35e5 /lib
parent94be0536ce5eaf1d5a67f217dce112607624389c (diff)
downloadpublic-inbox-2f720902ed702b64d918165ba21a96dabbeeca26.tar.gz
mbsync and offlineimap both use ":2," suffixes for filenames in
"new/", however my interpretation of the Maildir spec at
<https://cr.yp.to/proto/maildir.html> is that ":2," is only for
files in "cur/".  My interpretation also matches that of
doveecot, but we'll allow what mbsync and offlineimap do given
their popularity.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LeiMailSync.pm13
-rw-r--r--lib/PublicInbox/MdirReader.pm5
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index 803de48c..3bada42d 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -233,9 +233,16 @@ WHERE b.oidbin = ?
         $b2n->execute(pack('H*', $oidhex));
         while (my ($d, $n) = $b2n->fetchrow_array) {
                 substr($d, 0, length('maildir:')) = '';
-                my $f = "$d/" . ($n =~ /:2,[a-zA-Z]*\z/ ? "cur/$n" : "new/$n");
-                open my $fh, '<', $f or next;
-                if (-s $fh) {
+                # n.b. both mbsync and offlineimap use ":2," as a suffix
+                # in "new/", despite (from what I understand of reading
+                # <https://cr.yp.to/proto/maildir.html>), the ":2," only
+                # applies to files in "cur/".
+                my @try = $n =~ /:2,[a-zA-Z]+\z/ ? qw(cur new) : qw(new cur);
+                for my $x (@try) {
+                        my $f = "$d/$x/$n";
+                        open my $fh, '<', $f or next;
+                        # some (buggy) Maildir writers are non-atomic:
+                        next unless -s $fh;
                         local $/;
                         my $raw = <$fh>;
                         if ($vrfy && git_sha(1, \$raw)->hexdigest ne $oidhex) {
diff --git a/lib/PublicInbox/MdirReader.pm b/lib/PublicInbox/MdirReader.pm
index b49c8ceb..7a0641fb 100644
--- a/lib/PublicInbox/MdirReader.pm
+++ b/lib/PublicInbox/MdirReader.pm
@@ -61,7 +61,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;