There's nothing Maildir-specific about the function, so
`maildir_path_load' was a bad name. So give it a more
appropriate name and use it in our tests.
This save ourselves some code and inconsistency by reusing an
existing internal library routine in more places. We can drop
the "From_" line in some of our (formerly) mbox sample files.
t/indexlevels-mirror-v1.t
t/indexlevels-mirror.t
t/init.t
t/indexlevels-mirror-v1.t
t/indexlevels-mirror.t
t/init.t
t/linkify.t
t/main-bin/spamc
t/mda.t
t/linkify.t
t/main-bin/spamc
t/mda.t
t/spawn.t
t/thread-cycle.t
t/time.t
t/spawn.t
t/thread-cycle.t
t/time.t
t/v1-add-remove-add.t
t/v1reindex.t
t/v2-add-remove-add.t
t/v1-add-remove-add.t
t/v1reindex.t
t/v2-add-remove-add.t
(is_maildir_basename($p[-1]) && -f $path) ? 1 : 0;
}
(is_maildir_basename($p[-1]) && -f $path) ? 1 : 0;
}
-sub maildir_path_load ($) {
+sub mime_from_path ($) {
my ($path) = @_;
if (open my $fh, '<', $path) {
local $/;
my ($path) = @_;
if (open my $fh, '<', $path) {
local $/;
opendir my $dh, "$dir/$sub" or die "opendir $dir/$sub: $!\n";
while (defined(my $fn = readdir($dh))) {
next unless is_maildir_basename($fn);
opendir my $dh, "$dir/$sub" or die "opendir $dir/$sub: $!\n";
while (defined(my $fn = readdir($dh))) {
next unless is_maildir_basename($fn);
- my $mime = maildir_path_load("$dir/$fn") or next;
+ my $mime = mime_from_path("$dir/$fn") or next;
if (my $filter = $self->filter($im)) {
my $ret = $filter->scrub($mime) or return;
if (my $filter = $self->filter($im)) {
my $ret = $filter->scrub($mime) or return;
use File::Temp 0.19 (); # 0.19 for ->newdir
use PublicInbox::Filter::Base qw(REJECT);
use PublicInbox::Spamcheck;
use File::Temp 0.19 (); # 0.19 for ->newdir
use PublicInbox::Filter::Base qw(REJECT);
use PublicInbox::Spamcheck;
-*maildir_path_load = *PublicInbox::InboxWritable::maildir_path_load;
+*mime_from_path = \&PublicInbox::InboxWritable::mime_from_path;
sub new {
my ($class, $config) = @_;
sub new {
my ($class, $config) = @_;
my ($self, $path) = @_;
# path must be marked as (S)een
$path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
my ($self, $path) = @_;
# path must be marked as (S)een
$path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
- my $mime = maildir_path_load($path) or return;
+ my $mime = mime_from_path($path) or return;
$self->{config}->each_inbox(sub {
my ($ibx) = @_;
eval {
$self->{config}->each_inbox(sub {
my ($ibx) = @_;
eval {
$warn_cb->(@_);
};
foreach my $ibx (@$inboxes) {
$warn_cb->(@_);
};
foreach my $ibx (@$inboxes) {
- my $mime = maildir_path_load($path) or next;
+ my $mime = mime_from_path($path) or next;
my $im = _importer_for($self, $ibx);
# any header match means it's eligible for the inbox:
my $im = _importer_for($self, $ibx);
# any header match means it's eligible for the inbox:
warn "Will edit all of them\n";
}
} else {
warn "Will edit all of them\n";
}
} else {
- open my $fh, '<', $file or die "open($file) failed: $!";
- my $orig = do { local $/; <$fh> };
- my $mime = PublicInbox::MIME->new(\$orig);
+ my $mime = PublicInbox::InboxWritable::mime_from_path($file) or
+ die "open($file) failed: $!";
my $mids = mids($mime->header_obj);
find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
my $cid = content_id($mime);
my $mids = mids($mime->header_obj);
find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
my $cid = content_id($mime);
-From historical@ruby-dev Thu Jan 1 00:00:00 1970
Message-Id: <199707281508.AAA24167@hoyogw.example>
Date: Tue, 29 Jul 97 00:08:29 +0900
From: matz@example.com
Message-Id: <199707281508.AAA24167@hoyogw.example>
Date: Tue, 29 Jul 97 00:08:29 +0900
From: matz@example.com
use Cwd qw(getcwd);
use PublicInbox::MID qw(mid2path);
use PublicInbox::Git;
use Cwd qw(getcwd);
use PublicInbox::MID qw(mid2path);
use PublicInbox::Git;
+use PublicInbox::InboxWritable;
use PublicInbox::TestCommon;
my ($tmpdir, $for_destroy) = tmpdir();
my $home = "$tmpdir/pi-home";
use PublicInbox::TestCommon;
my ($tmpdir, $for_destroy) = tmpdir();
my $home = "$tmpdir/pi-home";
use PublicInbox::MDA;
use PublicInbox::Address;
use Encode qw/encode/;
use PublicInbox::MDA;
use PublicInbox::Address;
use Encode qw/encode/;
- my $mbox = 't/utf8.mbox';
- open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
- my $str = eval { local $/; <$fh> };
- close $fh;
- my $msg = Email::MIME->new($str);
-
+ my $eml = 't/utf8.eml';
+ my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or
+ die "failed to open $eml: $!";
my $from = $msg->header('From');
my ($author) = PublicInbox::Address::names($from);
my ($email) = PublicInbox::Address::emails($from);
my $from = $msg->header('From');
my ($author) = PublicInbox::Address::names($from);
my ($email) = PublicInbox::Address::emails($from);
use Test::More;
use Email::MIME;
use PublicInbox::Hval qw(ascii_html);
use Test::More;
use Email::MIME;
use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::InboxWritable;
use_ok('PublicInbox::MsgIter');
{
use_ok('PublicInbox::MsgIter');
{
- my $f = 't/iso-2202-jp.mbox';
- my $mime = Email::MIME->new(do {
- open my $fh, '<', $f or die "open($f): $!";
- local $/;
- <$fh>;
- });
+ my $f = 't/iso-2202-jp.eml';
+ my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
+ die "open $f: $!";
my $raw = '';
msg_iter($mime, sub {
my ($part, $level, @ex) = @{$_[0]};
my $raw = '';
msg_iter($mime, sub {
my ($part, $level, @ex) = @{$_[0]};
{
my $f = 't/x-unknown-alpine.eml';
{
my $f = 't/x-unknown-alpine.eml';
- my $mime = Email::MIME->new(do {
- open my $fh, '<', $f or die "open($f): $!";
- local $/;
- binmode $fh;
- <$fh>;
- });
+ my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
+ die "open $f: $!";
my $raw = '';
msg_iter($mime, sub {
my ($part, $level, @ex) = @{$_[0]};
my $raw = '';
msg_iter($mime, sub {
my ($part, $level, @ex) = @{$_[0]};
{
my $im = $ibx->importer(0);
{
my $im = $ibx->importer(0);
- my $mime = PublicInbox::MIME->new(do {
- open my $fh, '<', 't/data/0001.patch' or die;
- local $/;
- <$fh>
- });
+ my $eml = 't/data/0001.patch';
+ my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
+ die "open $eml: $!";
ok($im->add($mime), 'message added');
$im->done;
if ($version == 1) {
ok($im->add($mime), 'message added');
$im->done;
if ($version == 1) {
require_mods(qw(DBD::SQLite Search::Xapian));
require PublicInbox::SearchIdx;
require PublicInbox::Inbox;
require_mods(qw(DBD::SQLite Search::Xapian));
require PublicInbox::SearchIdx;
require PublicInbox::Inbox;
+require PublicInbox::InboxWritable;
use Email::MIME;
my ($tmpdir, $for_destroy) = tmpdir();
my $git_dir = "$tmpdir/a.git";
use Email::MIME;
my ($tmpdir, $for_destroy) = tmpdir();
my $git_dir = "$tmpdir/a.git";
});
$ibx->with_umask(sub {
});
$ibx->with_umask(sub {
- my $str = eval {
- my $mbox = 't/utf8.mbox';
- open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
- local $/;
- <$fh>
- };
- $str =~ s/\AFrom [^\n]+\n//s;
- my $mime = Email::MIME->new($str);
+ my $eml = 't/utf8.eml';
+ my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
+ die "open $eml: $!";
my $doc_id = $rw->add_message($mime);
ok($doc_id > 0, 'message indexed doc_id with UTF-8');
my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
my $doc_id = $rw->add_message($mime);
ok($doc_id > 0, 'message indexed doc_id with UTF-8');
my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
$im->{parallel} = 0;
my $deliver_patch = sub ($) {
$im->{parallel} = 0;
my $deliver_patch = sub ($) {
- open my $fh, '<', $_[0] or die "open: $!";
- my $mime = PublicInbox::MIME->new(do { local $/; <$fh> });
+ my $mime = PublicInbox::InboxWritable::mime_from_path($_[0]) or
+ die "open $_[0]: $!";
$im->add($mime);
$im->done;
};
$im->add($mime);
$im->done;
};
-From e@yhbt.net Thu Jan 01 00:00:00 1970
Date: Thu, 01 Jan 1970 00:00:00 +0000
To: =?utf-8?Q?El=C3=A9anor?= <e@example.com>
From: =?utf-8?Q?El=C3=A9anor?= <e@example.com>
Date: Thu, 01 Jan 1970 00:00:00 +0000
To: =?utf-8?Q?El=C3=A9anor?= <e@example.com>
From: =?utf-8?Q?El=C3=A9anor?= <e@example.com>