t/epoll.t
t/fail-bin/spamc
t/feed.t
+t/filter_base-junk.eml
+t/filter_base-xhtml.eml
t/filter_base.t
t/filter_mirror.t
t/filter_rubylang.t
t/iso-2202-jp.eml
t/linkify.t
t/main-bin/spamc
+t/mda-mime.eml
t/mda.t
t/mda_filter_rubylang.t
t/mid.t
t/mime.t
+t/msg_iter-nested.eml
+t/msg_iter-order.eml
t/msg_iter.t
t/msgmap.t
t/msgtime.t
t/nntpd.t
t/nulsubject.t
t/over.t
+t/plack-2-txt-bodies.eml
+t/plack-attached-patch.eml
+t/plack-qp.eml
t/plack.t
t/precheck.t
+t/psgi_attach.eml
t/psgi_attach.t
t/psgi_bad_mids.t
t/psgi_mount.t
t/psgi_scan_all.t
t/psgi_search.t
t/psgi_text.t
+t/psgi_v2-new.eml
+t/psgi_v2-old.eml
t/psgi_v2.t
t/purge.t
t/qspawn.t
t/replace.t
t/reply.t
t/run.perl
+t/search-amsg.eml
t/search-thr-index.t
t/search.t
t/sigfd.t
our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
run_script start_script key2sub xsys xqx mime_load);
-sub mime_load ($;&) {
+sub mime_load ($) {
my ($path, $cb) = @_;
- if (open(my $fh, '<', $path)) {
- PublicInbox::MIME->new(\(do { local $/; <$fh> }));
- } elsif ($cb) {
- require File::Temp;
-
- my $mime = $cb->();
- my ($dir) = ($path =~ m!(.+)/(?:[^/]+)\z!);
- -d $dir or die "BUG: dir=$dir is not the dir of $path";
- my $fh = File::Temp->new(DIR => $dir);
- $fh->autoflush(1);
- print $fh $mime->as_string or die "print: $!";
- my $fn = $fh->filename;
- rename($fn, $path) or die "link $fn => $path: $!";
- $fh->unlink_on_destroy(0);
- pop @_; # retry via tail recursion
- goto &mime_load;
- } else {
- die "open $path: $!";
- }
+ open(my $fh, '<', $path) or die "open $path: $!";
+ PublicInbox::MIME->new(\(do { local $/; <$fh> }));
}
sub tmpdir (;$) {
--- /dev/null
+From: a@example.com
+Subject: blah
+Content-Type: multipart/mixed; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: application/vnd.ms-excel
+Content-Transfer-Encoding: base64
+
+anVuaw==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+junk=
+
+--b--
--- /dev/null
+From: a@example.com
+Subject: blah
+Content-Type: multipart/alternative; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: text/xhtml; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+PGh0bWw+PGJvZHk+aGk8L2JvZHk+PC9odG1sPg==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+hi =3D "bye"=
+
+--b--
{
my $f = PublicInbox::Filter::Base->new;
- my $email = mime_load 't/filter_base-xhtml.eml', sub {
- my $html_body = "<html><body>hi</body></html>";
- my $parts = [
- Email::MIME->create(
- attributes => {
- content_type => 'text/xhtml; charset=UTF-8',
- encoding => 'base64',
- },
- body => $html_body,
- ),
- Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- encoding => 'quoted-printable',
- },
- body => 'hi = "bye"',
- )
- ];
- Email::MIME->create(
- header_str => [
- From => 'a@example.com',
- Subject => 'blah',
- 'Content-Type' => 'multipart/alternative'
- ],
- parts => $parts,
- )}; # mime_load sub
+ my $email = mime_load 't/filter_base-xhtml.eml';
is($f->delivery($email), 100, "xhtml rejected");
}
{
my $f = PublicInbox::Filter::Base->new;
- my $email = mime_load 't/filter_base-junk.eml', sub {
- my $parts = [
- Email::MIME->create(
- attributes => {
- content_type => 'application/vnd.ms-excel',
- encoding => 'base64',
- },
- body => 'junk',
- ),
- Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- encoding => 'quoted-printable',
- },
- body => 'junk',
- )
- ];
- Email::MIME->create(
- header_str => [
- From => 'a@example.com',
- Subject => 'blah',
- 'Content-Type' => 'multipart/mixed'
- ],
- parts => $parts,
- )}; # mime_load sub
+ my $email = mime_load 't/filter_base-junk.eml';
is($f->delivery($email), 100, 'proprietary format rejected on glob');
}
my $f = PublicInbox::Filter::Mirror->new;
ok($f, 'created PublicInbox::Filter::Mirror object');
{
- my $email = mime_load 't/filter_mirror.eml', sub {
- my $html_body = "<html><body>hi</body></html>";
- my $parts = [
- Email::MIME->create(
- attributes => {
- content_type => 'text/html; charset=UTF-8',
- encoding => 'base64',
- },
- body => $html_body,
- ),
- Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- encoding => 'quoted-printable',
- },
- body => 'hi = "bye"',
- )
- ];
- Email::MIME->create(
- header_str => [
- From => 'a@example.com',
- Subject => 'blah',
- 'Content-Type' => 'multipart/alternative'
- ],
- parts => $parts,
- )}; # mime_laod sub
+ my $email = mime_load 't/mda-mime.eml';
is($f->ACCEPT, $f->delivery($email), 'accept any trash that comes');
}
--- /dev/null
+From: a@example.com
+Subject: blah
+Cc: test-public@example.com
+Message-ID: <multipart-html-sucks@11>
+Content-Type: multipart/alternative; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+PGh0bWw+PGJvZHk+aGk8L2JvZHk+PC9odG1sPg==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+hi =3D "bye"=
+
+--b--
use strict;
use warnings;
use Test::More;
-use Email::MIME;
use Cwd qw(getcwd);
use PublicInbox::MID qw(mid2path);
use PublicInbox::Git;
my $addr = 'test-public@example.com';
my $cfgpfx = "publicinbox.test";
my $faildir = "$home/faildir/";
-my $mime;
my $git = PublicInbox::Git->new($maindir);
my $fail_bad_header = sub ($$$) {
"learned ham idempotently ");
# ensure trained email is filtered, too
- $mime = mime_load 't/mda-mime.eml', sub {
- my $html_body = "<html><body>hi</body></html>";
- my $parts = [
- Email::MIME->create(
- attributes => {
- content_type => 'text/html; charset=UTF-8',
- encoding => 'base64',
- },
- body => $html_body,
- ),
- Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- encoding => 'quoted-printable',
- },
- body => 'hi = "bye"',
- )
- ];
- $mid = 'multipart-html-sucks@11';
- Email::MIME->create(
- header_str => [
- From => 'a@example.com',
- Subject => 'blah',
- Cc => $addr,
- 'Message-ID' => "<$mid>",
- 'Content-Type' => 'multipart/alternative',
- ],
- parts => $parts,
- )}; # mime_load sub
-
+ my $mime = mime_load 't/mda-mime.eml';
+ ($mid) = ($mime->header_raw('message-id') =~ /<([^>]+)>/);
{
$in = $mime->as_string;
ok(run_script(['-learn', 'ham'], undef, { 0 => \$in }),
--- /dev/null
+From: root@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="outer"
+
+--outer
+From: sub@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="inner"
+
+--inner
+MIME-Version: 1.0
+
+a
+--inner
+MIME-Version: 1.0
+
+b
+--inner--
+
+--outer
+MIME-Version: 1.0
+
+sig
+--outer--
--- /dev/null
+From: root@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+MIME-Version: 1.0
+
+a
+
+--b
+MIME-Version: 1.0
+
+b
+
+--b--
use_ok('PublicInbox::MsgIter');
{
- my $mime = mime_load 't/msg_iter-order.eml', sub {
- my $parts = [ Email::MIME->create(body => "a\n"),
- Email::MIME->create(body => "b\n") ];
- Email::MIME->create(parts => $parts,
- header_str => [ From => 'root@localhost' ]);
- }; # mime_load sub
+ my $mime = mime_load 't/msg_iter-order.eml';
my @parts;
msg_iter($mime, sub {
my ($part, $level, @ex) = @{$_[0]};
}
{
- my $mime = mime_load 't/msg_iter-nested.eml', sub {
- my $parts = [ Email::MIME->create(body => 'a'),
- Email::MIME->create(body => 'b') ];
- $parts = [ Email::MIME->create(parts => $parts,
- header_str => [ From => 'sub@localhost' ]),
- Email::MIME->create(body => 'sig') ];
- Email::MIME->create(parts => $parts,
- header_str => [ From => 'root@localhost' ]);
- }; # mime_load sub
+ my $mime = mime_load 't/msg_iter-nested.eml';
my @parts;
msg_iter($mime, sub {
my ($part, $level, @ex) = @{$_[0]};
--- /dev/null
+From: a@example.com
+Subject: blargh
+Message-ID: <multipart@example.com>
+In-Reply-To: <irp@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+hi
+--b
+Content-Type: text/plain
+
+bye
+--b--
--- /dev/null
+From: a@example.com
+Subject: [PATCH] asdf
+Message-ID: <patch@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+hi, see attached
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="foo&.patch"
+
+--- a/file
++++ b/file
+@@ -49, 7 +49,34 @@
+
+--b--
--- /dev/null
+From: qp@example.com
+Subject: QP
+Message-ID: <qp@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/plain
+
+hi =3D bye=
use strict;
use warnings;
use Test::More;
-use Email::MIME;
use PublicInbox::TestCommon;
my $psgi = "./examples/public-inbox.psgi";
my ($tmpdir, $for_destroy) = tmpdir();
chomp @ls;
# multipart with two text bodies
- my %attr_text = (attributes => { content_type => 'text/plain' });
- $mime = mime_load 't/plack-2-txt-bodies.eml', sub {
- my $parts = [
- Email::MIME->create(%attr_text, body => 'hi'),
- Email::MIME->create(%attr_text, body => 'bye')
- ];
- Email::MIME->create(
- header_str => [
- From => 'a@example.com',
- Subject => 'blargh',
- 'Message-ID' => '<multipart@example.com>',
- 'In-Reply-To' => '<irp@example.com>'
- ],
- parts => $parts,
- )}; # mime_load sub
+ $mime = mime_load 't/plack-2-txt-bodies.eml';
$im->add($mime);
# multipart with attached patch + filename
- $mime = mime_load 't/plack-attached-patch.eml', sub {
- my $parts = [
- Email::MIME->create(%attr_text, body => 'hi, see attached'),
- Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- filename => "foo&.patch",
- },
- body => "--- a/file\n+++ b/file\n" .
- "@@ -49, 7 +49,34 @@\n"
- )
- ];
- Email::MIME->create(
- header_str => [
- From => 'a@example.com',
- Subject => '[PATCH] asdf',
- 'Message-ID' => '<patch@example.com>'
- ],
- parts => $parts
- )}; # mime_load sub
+ $mime = mime_load 't/plack-attached-patch.eml';
$im->add($mime);
# multipart collapsed to single quoted-printable text/plain
- $mime = mime_load 't/plack-qp.eml', sub {
- my $parts = [
- Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- encoding => 'quoted-printable'
- },
- body => 'hi = bye',
- )
- ];
- Email::MIME->create(
- header_str => [
- From => 'qp@example.com',
- Subject => 'QP',
- 'Message-ID' => '<qp@example.com>',
- ],
- parts => $parts,
- )};
+ $mime = mime_load 't/plack-qp.eml';
like($mime->body_raw, qr/hi =3D bye=/, 'our test used QP correctly');
$im->add($mime);
--- /dev/null
+From: root@z
+Message-Id: <Z@B>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: inline; filename="queue-pee"
+
+abcdef=3Dg
+=3D=3Dblah
+
+--b
+Content-Type: appication/octet-stream
+Content-Transfer-Encoding: base64
+Content-Disposition: inline; filename="bayce-sixty-four"
+
+YjY03q2+7wo=
+
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="noop.txt"
+
+plain
+text
+pass
+through
+
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename=".dotfile"
+
+dotfile
+
+--b--
use strict;
use warnings;
use Test::More;
-use Email::MIME;
use PublicInbox::TestCommon;
my ($tmpdir, $for_destroy) = tmpdir();
my $maindir = "$tmpdir/main.git";
my $b64 = "b64\xde\xad\xbe\xef\n";
my $txt = "plain\ntext\npass\nthrough\n";
my $dot = "dotfile\n";
- my $mime = mime_load 't/psgi_attach.eml', sub {
- my $parts = [
- Email::MIME->create(
- attributes => {
- filename => 'queue-pee',
- content_type => 'text/plain',
- encoding => 'quoted-printable'
- },
- body => $qp),
- Email::MIME->create(
- attributes => {
- filename => 'bayce-sixty-four',
- content_type => 'appication/octet-stream',
- encoding => 'base64',
- },
- body => $b64),
- Email::MIME->create(
- attributes => {
- filename => 'noop.txt',
- content_type => 'text/plain',
- },
- body => $txt),
- Email::MIME->create(
- attributes => {
- filename => '.dotfile',
- content_type => 'text/plain',
- },
- body => $dot),
- ];
- Email::MIME->create(
- parts => $parts,
- header_str => [ From => 'root@z', 'Message-Id' => '<Z@B>',
- Subject => 'hi']
- )}; # mime_load sub
- $im->add($mime);
+ $im->add(mime_load('t/psgi_attach.eml'));
$im->done;
my $www = PublicInbox::WWW->new($config);
--- /dev/null
+From: root@z
+Message-ID: <a@dup>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+blah
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="attach.txt"
+
+new
+--b--
--- /dev/null
+From: root@z
+Message-ID: <a@dup>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+blah
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="attach.txt"
+
+old
+--b--
use PublicInbox::Config;
use PublicInbox::MID qw(mids);
require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
- URI::Escape Plack::Builder Email::MIME));
+ URI::Escape Plack::Builder));
use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
use_ok 'PublicInbox::WWW';
use_ok 'PublicInbox::V2Writable';
# ensure conflicted attachments can be resolved
foreach my $body (qw(old new)) {
- $mime = mime_load "t/psgi_v2-$body.eml", sub {
- my $parts = [
- Email::MIME->create(
- attributes => { content_type => 'text/plain' },
- body => 'blah',
- ),
- Email::MIME->create(
- attributes => {
- filename => 'attach.txt',
- content_type => 'text/plain',
- },
- body => $body
- )
- ];
- Email::MIME->create(
- parts => $parts,
- header_str => [ From => 'root@z',
- 'Message-ID' => '<a@dup>',
- Subject => 'hi']
- )}; # mime_load sub
+ $mime = mime_load "t/psgi_v2-$body.eml";
ok($im->add($mime), "added attachment $body");
}
$im->done;
--- /dev/null
+Subject: see attachment
+Message-ID: <file@attached>
+From: "John Smith" <js@example.com>
+To: list@example.com
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain; charset="US-ASCII"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment; filename="attached_fart.txt"
+
+inside the attachment=
+
+--b
+Content-Type: text/plain; charset="US-ASCII"
+Content-Disposition: attachment; filename="part_deux.txt"
+Content-Transfer-Encoding: quoted-printable
+
+inside another=
+
+--b--
use warnings;
use Test::More;
use PublicInbox::TestCommon;
-require_mods(qw(DBD::SQLite Search::Xapian Email::MIME));
+require_mods(qw(DBD::SQLite Search::Xapian));
require PublicInbox::SearchIdx;
require PublicInbox::Inbox;
require PublicInbox::InboxWritable;
}
$ibx->with_umask(sub {
- my $amsg = mime_load 't/search-amsg.eml', sub {
- my $part1 = Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- disposition => 'attachment',
- charset => 'US-ASCII',
- encoding => 'quoted-printable',
- filename => 'attached_fart.txt',
- },
- body_str => 'inside the attachment',
- );
- my $part2 = Email::MIME->create(
- attributes => {
- content_type => 'text/plain',
- disposition => 'attachment',
- charset => 'US-ASCII',
- encoding => 'quoted-printable',
- filename => 'part_deux.txt',
- },
- body_str => 'inside another',
- );
- Email::MIME->create(
- header_str => [
- Subject => 'see attachment',
- 'Message-ID' => '<file@attached>',
- From => 'John Smith <js@example.com>',
- To => 'list@example.com',
- ],
- parts => [ $part1, $part2 ],
- )}; # mime_load sub
-
+ my $amsg = mime_load 't/search-amsg.eml';
ok($rw->add_message($amsg), 'added attachment');
$rw_commit->();
$ro->reopen;