user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
8b82579c167eda4168bd28939e10e8f025c48afc blob 3697 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
 
#!perl -w
# Copyright (C) 2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
require_git 2.6;
require_mods(qw(json DBD::SQLite Search::Xapian));
use PublicInbox::MboxReader;
use PublicInbox::InboxWritable;
my ($ro_home, $cfg_path) = setup_public_inboxes;
my $sock = tcp_server;
my ($tmpdir, $for_destroy) = tmpdir;
my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
my $env = { PI_CONFIG => $cfg_path };
my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-httpd: $?");
my $host_port = tcp_host_port($sock);
my $url = "http://$host_port/t2/";
my $exp1 = [ eml_load('t/plack-qp.eml') ];
my $exp2 = [ eml_load('t/iso-2202-jp.eml') ];
my $slurp_emls = sub {
	open my $fh, '<', $_[0] or BAIL_OUT "open: $!";
	my @eml;
	PublicInbox::MboxReader->mboxrd($fh, sub {
		my $eml = shift;
		$eml->header_set('Status');
		push @eml, $eml;
	});
	\@eml;
};

test_lei({ tmpdir => $tmpdir }, sub {
	my $o = "$ENV{HOME}/o.mboxrd";
	my @cmd = ('q', '-o', "mboxrd:$o", 'm:qp@example.com');
	lei_ok(@cmd);
	ok(-f $o && !-s _, 'output exists but is empty');
	unlink $o or BAIL_OUT $!;
	lei_ok(@cmd, '-I', $url);
	is_deeply($slurp_emls->($o), $exp1, 'got results after remote search');
	unlink $o or BAIL_OUT $!;
	lei_ok(@cmd);
	ok(-f $o && -s _, 'output exists after import but is not empty') or
		diag $lei_err;
	is_deeply($slurp_emls->($o), $exp1, 'got results w/o remote search');
	unlink $o or BAIL_OUT $!;

	$cmd[-1] = 'm:199707281508.AAA24167@hoyogw.example';
	lei_ok(@cmd, '-I', $url, '--no-import-remote');
	is_deeply($slurp_emls->($o), $exp2, 'got another after remote search');
	unlink $o or BAIL_OUT $!;
	lei_ok(@cmd);
	ok(-f $o && !-s _, '--no-import-remote did not memoize');

	open my $fh, '>', "$o.lock";
	$cmd[-1] = 'm:qp@example.com';
	unlink $o or BAIL_OUT $!;
	lei_ok(@cmd, '--lock=none');
	ok(-f $o && -s _, '--lock=none respected');
	unlink $o or BAIL_OUT $!;
	ok(!lei(@cmd, '--lock=dotlock,timeout=0.000001'), 'dotlock fails');
	ok(-f $o && !-s _, 'nothing output on lock failure');
	unlink "$o.lock" or BAIL_OUT $!;
	lei_ok(@cmd, '--lock=dotlock,timeout=0.000001',
		\'succeeds after lock removal');

	# XXX memoize this external creation
	my $inboxdir = "$ENV{HOME}/tmp_git";
	my $ibx = PublicInbox::InboxWritable->new({
		name => 'tmp',
		-primary_address => 'lei@example.com',
		inboxdir => $inboxdir,
		indexlevel => 'medium',
	}, { nproc => 1 });
	my $im = $ibx->importer(0);
	$im->add(eml_load('t/utf8.eml')) or BAIL_OUT '->add';
	$im->done;

	run_script(['-index', $inboxdir], undef) or BAIL_OUT '-init';
	lei_ok(qw(add-external -q), $inboxdir);
	lei_ok(qw(q -o), "mboxrd:$o", '--only', $url,
		'm:testmessage@example.com');
	ok(-s $o, 'got result from remote external');
	my $exp = eml_load('t/utf8.eml');
	is_deeply($slurp_emls->($o), [$exp], 'got expected result');
	lei_ok(qw(q --no-external -o), "mboxrd:/dev/stdout",
			'm:testmessage@example.com');
	is($lei_out, '', 'message not imported when in local external');

	open $fh, '>', $o or BAIL_OUT;
	print $fh <<'EOF' or BAIL_OUT;
From a@z Mon Sep 17 00:00:00 2001
From: nobody@localhost
Date: Sat, 13 Mar 2021 18:23:01 +0600
Message-ID: <never-before-seen@example.com>
Status: RO

whatever
EOF
	close $fh or BAIL_OUT;
	lei_ok(qw(q -o), "mboxrd:$o", 'm:testmessage@example.com');
	is_deeply($slurp_emls->($o), [$exp],
		'got expected result after clobber') or diag $lei_err;
	lei_ok(qw(q -o mboxrd:/dev/stdout m:never-before-seen@example.com));
	like($lei_out, qr/seen\@example\.com>\nStatus: OR\n\nwhatever/sm,
		'--import-before imported totally unseen message');
});
done_testing;
debug log:

solving 8b82579c ...
found 8b82579c in public-inbox.git

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