Acme-Archive-Mbox
view release on metacpan or search on metacpan
MANIFEST
README
TODO
t/00-load.t
t/archive.t
t/file.t
t/pod-coverage.t
t/pod.t
bin/mboxify
bin/mboxextract
META.yml Module meta-data (added by MakeMaker)
Acme-Archive-Mbox
Store and retrieve files to/from an mbox (suitable for viewing with a
mail client, eg mutt).
Mbox format is one message per file, with metadata in the headers and
file contents in an attachment. Included script[s] create and extract
mbox archives, like tar.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
lib/Acme/Archive/Mbox.pm view on Meta::CPAN
=cut
our $VERSION = '0.01';
=head1 SYNOPSIS
Uses Mbox as an archive format, like tar or zip but silly. Creates an mbox
with one message per file or directory. File contents are stored as an
attachment, metadata goes in mail headers.
use Acme::Archive::Mbox;
my $archive = Acme::Archive::Mbox->new();
$archive->add_file('filename');
$archive->add_data('file/name', $contents);
$archive->write('foo.mbox');
...
$archive->read('foo.mbox');
$archive->extract();
=head1 FUNCTIONS
=head2 new ()
lib/Acme/Archive/Mbox.pm view on Meta::CPAN
Create an Acme::Archive::Mbox object.
=cut
sub new {
my $class = shift;
my $self = { files => [] };
return bless $self,$class;
}
=head2 add_data ($name, $contents, %attr)
Add a file given a filename and contents. (File need not exist on disk)
=cut
sub add_data {
my $self = shift;
my $name = shift;
my $contents = shift;
my %attr = @_;
my $file = Acme::Archive::Mbox::File->new($name, $contents, %attr);
push @{$self->{files}}, $file if $file;
return $file;
}
lib/Acme/Archive/Mbox.pm view on Meta::CPAN
sub write {
my $self = shift;
my $mboxname = shift;
my $mgr = Mail::Box::Manager->new;
my $folder = $mgr->open($mboxname, type => 'mbox', create => 1, access => 'rw') or die "Could not create $mboxname";
for my $file (@{$self->{files}}) {
my $attach = Mail::Message::Body->new( mime_type => 'application/octet-stream',
data => $file->contents,
);
my $message = Mail::Message->build( From => '"Acme::Archive::Mbox" <AAM@example.com>',
To => '"Anyone, really" <anyone@example.com>',
Subject => $file->name,
'X-AAM-uid' => $file->uid,
'X-AAM-gid' => $file->gid,
'X-AAM-mode' => $file->mode,
'X-AAM-mtime' => $file->mtime,
data => 'attached',
attach => $attach, );
$folder->addMessage($message);
}
$folder->write();
$mgr->close($folder);
}
=head2 read (filename)
Read archive from a file.
lib/Acme/Archive/Mbox.pm view on Meta::CPAN
my $folder = $mgr->open($mboxname, type => 'mbox') or die "Could not open $mboxname";
my @messages = $folder->messages;
for my $message (@messages) {
my %attr;
my $name = $message->get('Subject');
for (qw/uid gid mode mtime/) {
$attr{$_} = $message->get("X-AAM-$_");
}
my $contents = ($message->parts())[1]->decoded();
$self->add_data($name, $contents, %attr);
}
$mgr->close($folder);
}
=head1 AUTHOR
Ian Kilgore, C<< <iank at cpan.org> >>
=head1 BUGS
t/archive.t view on Meta::CPAN
use Test::More tests => 15;
use strict;
use Acme::Archive::Mbox;
use File::Temp qw/ :POSIX /;
# new
my $archive = Acme::Archive::Mbox->new();
isa_ok($archive, 'Acme::Archive::Mbox', 'Object created');
# add_data and add_file
my ($file,$contents) = ('test/file', 'aoeuidhtns'x10);
my ($file2) = 't/archive.t';
isa_ok($archive->add_data($file,$contents, uid => 1337), 'Acme::Archive::Mbox::File', 'add data');
isa_ok($archive->add_file($file2), 'Acme::Archive::Mbox::File', 'add file');
isa_ok($archive->add_file($file2, 'optional/filename'), 'Acme::Archive::Mbox::File', 'add file');
# get_files, check files
my @files = $archive->get_files();
isa_ok($files[0], 'Acme::Archive::Mbox::File', 'add_data AAM::File object');
is($files[0]->name, $file, 'add_data filename');
is($files[0]->contents, $contents, 'add_data filename');
isa_ok($files[1], 'Acme::Archive::Mbox::File', 'add_file AAM::File object');
is($files[1]->name, $file2, 'add_file filename');
isa_ok($files[2], 'Acme::Archive::Mbox::File', 'add_file AAM::File object');
is($files[2]->name, 'optional/filename', 'add_file filename');
# TODO: These tests are weak
SKIP: {
# write
( run in 1.221 second using v1.01-cache-2.11-cpan-4d50c553e7e )