Acme-Archive-Mbox

 view release on metacpan or  search on metacpan

lib/Acme/Archive/Mbox.pm  view on Meta::CPAN

=cut

sub get_files {
    my $self = shift;
    return @{$self->{files}};
}

=head2 write (filename)

Write archive to a file

=cut

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.

=cut

sub read {
    my $self = shift;
    my $mboxname = shift;

    my $mgr = Mail::Box::Manager->new;
    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

=over 4

=item Undefined behavior in spades.  Anyone using this probably deserves it.

=item Fails to overwrite or truncate when creating archives

=item As Acme::Archive::Mbox does not store directories, directory
mode and ownership will not be preserved.

=back

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Acme::Archive::Mbox


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Acme-Archive-Mbox>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Acme-Archive-Mbox>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Acme-Archive-Mbox>

=item * Search CPAN

L<http://search.cpan.org/dist/Acme-Archive-Mbox/>

=back


=head1 ACKNOWLEDGEMENTS


=head1 COPYRIGHT & LICENSE

Copyright 2008 Ian Kilgore, all rights reserved.



( run in 2.566 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )