user/dev discussion of public-inbox itself
 help / color / Atom feed
ef7d6958aaa9f0c27e9d2125df0278c0b7b8d7b3 blob 4732 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 
# Copyright (C) 2013-2018 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
use Email::MIME;
use Plack::Util;
use_ok 'PublicInbox::View';
use_ok 'PublicInbox::Config';

# FIXME: make this test less fragile
my $ctx = {
	env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'http' },
	-inbox => Plack::Util::inline_object(
		name => 'test',
		search => sub { undef },
		base_url => sub { 'http://example.com/' },
		cloneurl => sub {[]},
		nntp_url => sub {[]},
		max_git_part => sub { undef },
		description => sub { '' }),
	www => Plack::Util::inline_object(style => sub { '' }),
};
$ctx->{-inbox}->{-primary_address} = 'test@example.com';

sub msg_html ($) {
	my ($mime) = @_;

	my $s = '';
	my $r = PublicInbox::View::msg_html($ctx, $mime);
	my $body = $r->[2];
	while (defined(my $buf = $body->getline)) {
		$s .= $buf;
	}
	$body->close;
	$s;
}

# plain text
{
	my $body = <<EOF;
So and so wrote:
> keep this inline

OK

> Long and wordy reply goes here and it is split across multiple lines.
> We generate links to a separate full page where quoted-text is inline.
> This is
>
> Currently 12 lines
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED
> See MAX_INLINE_QUOTED

hello world
EOF
	my $s = Email::Simple->create(
		header => [
			From => 'a@example.com',
			To => 'b@example.com',
			'Content-Type' => 'text/plain',
			'Message-ID' => '<hello@example.com>',
			Subject => 'this is a subject',
		],
		body => $body,
	)->as_string;
	my $mime = Email::MIME->new($s);
	my $html = msg_html($mime);

	# ghetto tests
	like($html, qr!<a\nhref="raw"!s, "raw link present");
	like($html, qr/hello world\b/, "body present");
	like($html, qr/&gt; keep this inline/, "short quoted text is inline");
}

# multipart crap
{
	my $parts = [
		Email::MIME->create(
			attributes => { content_type => 'text/plain', },
			body => 'hi',
		),
		Email::MIME->create(
			attributes => { content_type => 'text/plain', },
			body => 'bye',
		)
	];
	my $mime = Email::MIME->create(
		header_str => [
			From => 'a@example.com',
			Subject => 'blargh',
			'Message-ID' => '<blah@example.com>',
			'In-Reply-To' => '<irp@example.com>',
			],
		parts => $parts,
	);

	my $html = msg_html($mime);
	like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split");
}

# multipart email with attached patch
{
	my $parts = [
		Email::MIME->create(
			attributes => { content_type => 'text/plain', },
			body => 'hi, see attached patch',
		),
		Email::MIME->create(
			attributes => {
				content_type => 'text/plain',
				filename => "foo&.patch",
			},
			body => "--- a/file\n+++ b/file\n" .
			        "@@ -49, 7 +49,34 @@\n",
		),
	];
	my $mime = Email::MIME->create(
		header_str => [
			From => 'a@example.com',
			Subject => '[PATCH] asdf',
			'Message-ID' => '<patch@example.com>',
			],
		parts => $parts,
	);

	my $html = msg_html($mime);
	like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!,
		"parts split with filename");
}

# multipart collapsed to single quoted-printable text/plain
{
	my $parts = [
		Email::MIME->create(
			attributes => {
				content_type => 'text/plain',
				encoding => 'quoted-printable',
			},
			body => 'hi = bye',
		)
	];
	my $mime = Email::MIME->create(
		header_str => [
			From => 'qp@example.com',
			Subject => 'QP',
			'Message-ID' => '<qp@example.com>',
			],
		parts => $parts,
	);

	my $orig = $mime->body_raw;
	my $html = msg_html($mime);
	like($orig, qr/hi =3D bye=/, "our test used QP correctly");
	like($html, qr/\bhi = bye\b/, "HTML output decoded QP");
}

{
	use PublicInbox::MID qw/id_compress/;

	# n.b: this is probably invalid since we dropped CGI for PSGI:
	like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
		"percent always converted to sha1 to workaround buggy httpds");

	is(id_compress('foobar-wtf'), 'foobar-wtf',
		'regular ID not compressed');
}

{
	my $cols = PublicInbox::View::COLS();
	my @addr;
	until (length(join(', ', @addr)) > ($cols * 2)) {
		push @addr, '"l, f" <a@a>';
		my $n = int(rand(20)) + 1;
		push @addr, ('x'x$n).'@x';
	}
	my $orig = join(', ', @addr);
	my $res = PublicInbox::View::fold_addresses($orig.'');
	isnt($res, $orig, 'folded result');
	unlike($res, qr/l,\n\tf/s, '"last, first" no broken');
	my @nospc = ($res, $orig);
	s/\s+//g for @nospc;
	is($nospc[0], $nospc[1], 'no addresses lost in translation');
	my $tws = PublicInbox::View::fold_addresses($orig.' ');
	# (Email::Simple drops leading whitespace, but not trailing)
	$tws =~ s/ \z//;
	is($tws, $res, 'not thrown off by trailing whitespace');
}

done_testing();
debug log:

solving ef7d695 ...
found ef7d695 in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://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

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

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