about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-15 09:21:43 +0000
committerEric Wong <e@80x24.org>2023-11-16 10:56:52 +0000
commit2c472f1f571ae55155c78bcbc4d420d06266ba63 (patch)
treee123822123dada4eb5c39822480e483c1ac2e0c4 /t
parent95de492d3ca723fe81ec3bd23d89b643ce98823e (diff)
downloadpublic-inbox-2c472f1f571ae55155c78bcbc4d420d06266ba63.tar.gz
We should be able to treat v2 outputs just like any other mail
format, with the exception that content dedupe is always
enforced by the v2 format.

This allows users hosting v2 public-inboxes to catch up broken
synchronization from alternate archives such as the mbox
archives hosted by https://lists.gnu.org/

Link: https://public-inbox.org/meta/20231114-hypersonic-papaya-starling-e1cfc8@nitro/
Diffstat (limited to 't')
-rw-r--r--t/lei-convert.t31
1 files changed, 30 insertions, 1 deletions
diff --git a/t/lei-convert.t b/t/lei-convert.t
index 84b57f81..6aff80bb 100644
--- a/t/lei-convert.t
+++ b/t/lei-convert.t
@@ -8,7 +8,8 @@ use PublicInbox::NetReader;
 use PublicInbox::Eml;
 use IO::Uncompress::Gunzip;
 use File::Path qw(remove_tree);
-use PublicInbox::Spawn qw(which);
+use PublicInbox::Spawn qw(which run_qx);
+use File::Compare;
 use autodie qw(open);
 require_mods(qw(lei -imapd -nntpd Mail::IMAPClient Net::NNTP));
 my ($tmpdir, $for_destroy) = tmpdir;
@@ -28,8 +29,36 @@ test_lei({ tmpdir => $tmpdir }, sub {
         my $d = $ENV{HOME};
         lei_ok('convert', '-o', "mboxrd:$d/foo.mboxrd",
                 "imap://$imap_host_port/t.v2.0");
+        my ($nc0) = ($lei_err =~ /converted (\d+) messages/);
         ok(-f "$d/foo.mboxrd", 'mboxrd created from imap://');
 
+        lei_ok qw(convert -o), "v2:$d/v2-test", "mboxrd:$d/foo.mboxrd";
+        my ($nc) = ($lei_err =~ /converted (\d+) messages/);
+        is $nc, $nc0, 'converted all messages messages';
+        lei_ok qw(q z:0.. -f jsonl --only), "$d/v2-test";
+        is(scalar(split(/^/sm, $lei_out)), $nc, 'got all messages in v2-test');
+
+        lei_ok qw(convert -o), "mboxrd:$d/from-v2.mboxrd", "$d/v2-test";
+        like $lei_err, qr/converted $nc messages/;
+        is(compare("$d/foo.mboxrd", "$d/from-v2.mboxrd"), 0,
+                'convert mboxrd -> v2 ->mboxrd roundtrip') or
+                        diag run_qx([qw(git diff --no-index),
+                                        "$d/foo.mboxrd", "$d/from-v2.mboxrd"]);
+
+        lei_ok [qw(convert -F eml -o), "$d/v2-test"], undef,
+                { 0 => \<<'EOM', %$lei_opt };
+From: f@example.com
+To: t@example.com
+Subject: append-to-v2-on-convert
+Message-ID: <append-to-v2-on-convert@example>
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+EOM
+        like $lei_err, qr/converted 1 messages/, 'only one message added';
+        lei_ok qw(q z:0.. -f jsonl --only), "$d/v2-test";
+        is(scalar(split(/^/sm, $lei_out)), $nc + 1,
+                'got expected number of messages after append convert');
+        like $lei_out, qr/append-to-v2-on-convert/;
+
         lei_ok('convert', '-o', "mboxrd:$d/nntp.mboxrd",
                 "nntp://$nntp_host_port/t.v2");
         ok(-f "$d/nntp.mboxrd", 'mboxrd created from nntp://');