aboutsummaryrefslogtreecommitdiff
path: root/lib/Sietima/MailStore/FS.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sietima/MailStore/FS.pm')
-rw-r--r--lib/Sietima/MailStore/FS.pm211
1 files changed, 117 insertions, 94 deletions
diff --git a/lib/Sietima/MailStore/FS.pm b/lib/Sietima/MailStore/FS.pm
index 060e321..4f43d26 100644
--- a/lib/Sietima/MailStore/FS.pm
+++ b/lib/Sietima/MailStore/FS.pm
@@ -8,40 +8,12 @@ use Sietima::Types qw(EmailMIME TagName);
use Digest::SHA qw(sha1_hex);
use namespace::clean;
-# VERSION
+our $VERSION = '1.1.2'; # VERSION
# ABSTRACT: filesystem-backed email store
-=head1 SYNOPSIS
-
- my $store = Sietima::MailStore::FS->new({ root => '/tmp/my-store' });
-
-=head1 DESCRIPTION
-
-This class implements the L<< C<Sietima::MailStore> >> interface,
-storing emails as files on disk.
-
-=cut
with 'Sietima::MailStore';
-=attr C<root>
-
-Required, a L<< C<Path::Tiny> >> object that points to an existing
-directory. Coercible from a string.
-
-It's a good idea for the directory to be readable and writable by the
-user who will run the mailing list, and also by all users who will run
-administrative commands (like those provided by L<<
-C<Sietima::Role::SubscriberOnly::Moderate> >>). A way to achieve that
-is to have a group dedicated to list owners, and set the directory
-group-writable and group-sticky, and owned by that group:
-
- # chgrp -R mailinglists /tmp/my-store
- # chmod -R g+rwXs /tmp/my-store
-
-=for Pod::Coverage BUILD
-
-=cut
has root => (
is => 'ro',
@@ -59,18 +31,6 @@ sub BUILD($self,@) {
return;
}
-=method C<store>
-
- my $id = $store->store($email_mime_object,@tags);
-
-Stores the given email message inside the L<store root|/root>, and
-associates it with the given tags.
-
-Returns a unique identifier for the stored message. If you store twice
-the same message (or two messages that stringify identically), you'll
-get the same identifier.
-
-=cut
signature_for store => (
method => Object,
@@ -91,18 +51,6 @@ sub store($self,$mail,$tags) {
return $id;
}
-=method C<retrieve_by_id>
-
- my $email_mime_object = $store->retrieve_by_id($id);
-
-Given an identifier returned by L<< /C<store> >>, this method returns
-the email message.
-
-If the message has been deleted, or the identifier is not recognised,
-this method returns C<undef> in scalar context, or an empty list in
-list context.
-
-=cut
signature_for retrieve_by_id => (
method => Object,
@@ -114,19 +62,6 @@ sub retrieve_by_id($self,$id) {
return Email::MIME->new($msg_path->slurp_raw);
}
-=method C<retrieve_ids_by_tags>
-
- my @ids = $store->retrieve_ids_by_tags(@tags)->@*;
-
-Given a list of tags, this method returns an arrayref containing the
-identifiers of all (and only) the messages that were stored associated
-with (at least) all those tags. The order of the returned identifiers
-is essentially random.
-
-If there are no messages associated with the given tags, this method
-returns an empty arrayref.
-
-=cut
sub _tagged_by($self,$tag) {
my $tag_file = $self->_tagdir->child($tag);
@@ -162,19 +97,6 @@ sub retrieve_ids_by_tags($self,$tags) {
return \@ret;
}
-=method C<retrieve_by_tags>
-
- my @email_mime_objects = $store->retrieve_by_tags(@tags)->@*;
-
-This method is similar to L<< /C<retrieve_ids_by_tags> >>, but it
-returns an arrayref of hashrefs like:
-
- $store->retrieve_by_tags('t1') ==> [
- { id => $id1, mail => $msg1 },
- { id => $id2, mail => $msg2 },
- ]
-
-=cut
signature_for retrieve_by_tags => (
method => Object,
@@ -194,14 +116,6 @@ sub retrieve_by_tags($self,$tags) {
return \@ret;
}
-=method C<remove>
-
- $store->remove($id);
-
-This method removes the message corresponding to the given identifier
-from disk. Removing a non-existent message does nothing.
-
-=cut
signature_for remove => (
method => Object,
@@ -216,18 +130,127 @@ sub remove($self,$id) {
return;
}
-=method C<clear>
+
+sub clear($self) {
+ do { $self->$_->remove_tree;$self->$_->mkpath } for qw(_tagdir _msgdir);
+ return;
+}
+
+1;
+
+__END__
+
+=pod
+
+=encoding UTF-8
+
+=head1 NAME
+
+Sietima::MailStore::FS - filesystem-backed email store
+
+=head1 VERSION
+
+version 1.1.2
+
+=head1 SYNOPSIS
+
+ my $store = Sietima::MailStore::FS->new({ root => '/tmp/my-store' });
+
+=head1 DESCRIPTION
+
+This class implements the L<< C<Sietima::MailStore> >> interface,
+storing emails as files on disk.
+
+=head1 ATTRIBUTES
+
+=head2 C<root>
+
+Required, a L<< C<Path::Tiny> >> object that points to an existing
+directory. Coercible from a string.
+
+It's a good idea for the directory to be readable and writable by the
+user who will run the mailing list, and also by all users who will run
+administrative commands (like those provided by L<<
+C<Sietima::Role::SubscriberOnly::Moderate> >>). A way to achieve that
+is to have a group dedicated to list owners, and set the directory
+group-writable and group-sticky, and owned by that group:
+
+ # chgrp -R mailinglists /tmp/my-store
+ # chmod -R g+rwXs /tmp/my-store
+
+=head1 METHODS
+
+=head2 C<store>
+
+ my $id = $store->store($email_mime_object,@tags);
+
+Stores the given email message inside the L<store root|/root>, and
+associates it with the given tags.
+
+Returns a unique identifier for the stored message. If you store twice
+the same message (or two messages that stringify identically), you'll
+get the same identifier.
+
+=head2 C<retrieve_by_id>
+
+ my $email_mime_object = $store->retrieve_by_id($id);
+
+Given an identifier returned by L<< /C<store> >>, this method returns
+the email message.
+
+If the message has been deleted, or the identifier is not recognised,
+this method returns C<undef> in scalar context, or an empty list in
+list context.
+
+=head2 C<retrieve_ids_by_tags>
+
+ my @ids = $store->retrieve_ids_by_tags(@tags)->@*;
+
+Given a list of tags, this method returns an arrayref containing the
+identifiers of all (and only) the messages that were stored associated
+with (at least) all those tags. The order of the returned identifiers
+is essentially random.
+
+If there are no messages associated with the given tags, this method
+returns an empty arrayref.
+
+=head2 C<retrieve_by_tags>
+
+ my @email_mime_objects = $store->retrieve_by_tags(@tags)->@*;
+
+This method is similar to L<< /C<retrieve_ids_by_tags> >>, but it
+returns an arrayref of hashrefs like:
+
+ $store->retrieve_by_tags('t1') ==> [
+ { id => $id1, mail => $msg1 },
+ { id => $id2, mail => $msg2 },
+ ]
+
+=head2 C<remove>
+
+ $store->remove($id);
+
+This method removes the message corresponding to the given identifier
+from disk. Removing a non-existent message does nothing.
+
+=head2 C<clear>
$store->clear();
This method removes all messages from disk. Clearing as empty store
does nothing.
-=cut
+=for Pod::Coverage BUILD
-sub clear($self) {
- do { $self->$_->remove_tree;$self->$_->mkpath } for qw(_tagdir _msgdir);
- return;
-}
+=head1 AUTHOR
-1;
+Gianni Ceccarelli <dakkar@thenautilus.net>
+
+=head1 COPYRIGHT AND LICENSE
+
+This software is copyright (c) 2023 by Gianni Ceccarelli <dakkar@thenautilus.net>.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut