user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] lei: relax rules for "new" in Maildir
@ 2021-05-19  8:54 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-05-19  8:54 UTC (permalink / raw)
  To: meta

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.
---
 lib/PublicInbox/LeiMailSync.pm | 13 ++++++++++---
 lib/PublicInbox/MdirReader.pm  |  5 ++++-
 t/lei-index.t                  | 10 +++++++++-
 3 files changed, 23 insertions(+), 5 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;
diff --git a/t/lei-index.t b/t/lei-index.t
index 3382d42b..b7dafb71 100644
--- a/t/lei-index.t
+++ b/t/lei-index.t
@@ -27,6 +27,11 @@ my $expect = do {
 	local $/;
 	<$fh>;
 };
+
+# mbsync and offlineimap both put ":2," in "new/" files:
+symlink(File::Spec->rel2abs('t/utf8.eml'), "$tmpdir/md/new/u:2,") or
+	xbail "symlink $!";
+
 test_lei({ tmpdir => $tmpdir }, sub {
 	my $store_path = "$ENV{HOME}/.local/share/lei/store/";
 
@@ -40,13 +45,16 @@ test_lei({ tmpdir => $tmpdir }, sub {
 	lei_ok(qw(q mid:qp@example.com -f text));
 	like($lei_out, qr/^hi = bye/sm, 'lei2mail fallback');
 
+	lei_ok(qw(q mid:testmessage@example.com -f text));
+	lei_ok(qw(-C / blob --mail 9bf1002c49eb075df47247b74d69bcd555e23422));
+
 	my $all_obj = ['git', "--git-dir=$store_path/ALL.git",
 			qw(cat-file --batch-check --batch-all-objects)];
 	is_deeply([xqx($all_obj)], [], 'no git objects');
 	lei_ok('import', 't/plack-qp.eml');
 	ok(grep(/\A$blob blob /, my @objs = xqx($all_obj)),
 		'imported blob');
-	lei_ok(qw(q z:0.. --dedupe=none));
+	lei_ok(qw(q m:qp@example.com --dedupe=none));
 	my $res_b = json_utf8->decode($lei_out);
 	is_deeply($res_b, $res_a, 'no extra DB entries');
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-19  8:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19  8:54 [PATCH] lei: relax rules for "new" in Maildir Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git