Mail-Box
view release on metacpan or search on metacpan
lib/Mail/Box.pm view on Meta::CPAN
$self->{MB_body_delayed_type} = $args->{body_delayed_type} || 'Mail::Message::Body::Delayed';
$self->{MB_head_delayed_type} = $args->{head_delayed_type} || 'Mail::Message::Head::Delayed';
$self->{MB_multipart_type} = $args->{multipart_type} || 'Mail::Message::Body::Multipart';
$self->{MB_field_type} = $args->{field_type};
my $extract = $args->{extract} || 'extractDefault';
$self->{MB_extract}
= ref $extract eq 'CODE' ? $extract
: $extract eq 'ALWAYS' ? sub { 1 }
: $extract eq 'LAZY' ? sub { 0 }
: $extract eq 'NEVER' ? sub { 1 } # compatibility
: $extract =~ m/\D/ ? sub { no strict 'refs'; shift->$extract(@_) }
: sub { my $size = $_[1]->guessBodySize; defined $size && $size < $extract };
#
# Create a locker.
#
$self->{MB_locker} = $args->{locker} || Mail::Box::Locker->new(
folder => $self,
method => $args->{lock_type},
timeout => $args->{lock_timeout},
expires => $args->{lock_wait},
file => ($args->{lockfile} || $args->{lock_file}),
);
$self;
}
#--------------------
sub removeEmpty() { $_[0]->{MB_remove_empty} }
sub folderdir(;$) { my $self = shift; @_ ? $self->{MB_folderdir} = shift : $self->{MB_folderdir} }
sub type() { $_[0]->notImplemented }
sub name() { $_[0]->{MB_foldername} }
sub isTrusted() { $_[0]->{MB_trusted} }
sub fixHeaders() { $_[0]->{MB_fix_headers} }
#--------------------
sub foundIn($@) { $_[0]->notImplemented }
sub url()
{ my $self = shift;
$self->type . ':' . $self->name;
}
sub size() { sum 0, map $_->size, $_[0]->messages('ACTIVE') }
sub update(@)
{ my $self = shift;
$self->updateMessages(
trusted => $self->isTrusted,
head_type => $self->{MB_head_type},
field_type => $self->{MB_field_type},
message_type => $self->{MB_message_type},
body_delayed_type => $self->{MB_body_delayed_type},
head_delayed_type => $self->{MB_head_delayed_type},
@_,
);
$self;
}
sub organization() { $_[0]->notImplemented }
sub addMessage($@)
{ my $self = shift;
my $message = shift or return $self;
my %args = @_;
$message->can('folder') && defined $message->folder
and error __x"you cannot add a message which is already part of a folder to a new one. Please use moveTo or copyTo.";
# Force the message into the right folder-type.
my $coerced = $self->coerce($message);
$coerced->folder($self);
unless($coerced->head->isDelayed)
{ # Do not add the same message twice, unless keep_dups.
my $msgid = $coerced->messageId;
unless($self->{MB_keep_dups})
{ if(my $found = $self->messageId($msgid))
{ $coerced->label(deleted => 1);
return $found;
}
}
$self->messageId($msgid, $coerced);
$self->toBeThreaded($coerced);
}
$self->storeMessage($coerced);
$coerced;
}
sub addMessages(@)
{ my $self = shift;
map $self->addMessage($_), @_;
}
sub copyTo($@)
{ my ($self, $to, %args) = @_;
lib/Mail/Box.pm view on Meta::CPAN
return $self->{MB_body_delayed_type}
if $self->{MB_lazy_permitted}
&& ! $message->isPart
&& ! $self->{MB_extract}->($self, $head);
my $bodytype = $self->{MB_body_type};
ref $bodytype ? $bodytype->($head) : $bodytype;
}
sub extractDefault($)
{ my ($self, $head) = @_;
my $size = $head->guessBodySize;
defined $size ? $size < 10000 : 0 # immediately extract < 10kb
}
sub lazyPermitted($)
{ my $self = shift;
$self->{MB_lazy_permitted} = shift;
}
sub storeMessage($)
{ my ($self, $message) = @_;
push @{$self->{MB_messages}}, $message;
$message->seqnr( @{$self->{MB_messages}} -1);
$message;
}
my %seps = (CR => "\015", LF => "\012", CRLF => "\015\012");
sub lineSeparator(;$)
{ my $self = shift;
@_ or return $self->{MB_linesep};
my $sep = shift;
$sep = $seps{$sep} if exists $seps{$sep};
$self->{MB_linesep} = $sep;
$_->lineSeparator($sep) for $self->messages;
$sep;
}
sub create($@) { $_[0]->notImplemented }
sub coerce($@)
{ my ($self, $message) = (shift, shift);
my $mmtype = $self->{MB_message_type};
$message->isa($mmtype) ? $message : $mmtype->coerce($message, @_);
}
sub readMessages(@) { $_[0]->notImplemented }
sub updateMessages(@) { $_[0] }
sub writeMessages(@) { $_[0]->notImplemented }
sub locker() { $_[0]->{MB_locker} }
sub toBeThreaded(@)
{ my $self = shift;
my $manager = $self->{MB_manager} or return $self;
$manager->toBeThreaded($self, @_);
$self;
}
sub toBeUnthreaded(@)
{ my $self = shift;
my $manager = $self->{MB_manager} or return $self;
$manager->toBeThreaded($self, @_);
$self;
}
#--------------------
sub timespan2seconds($)
{
$_[1] =~ /^\s*(\d+\.?\d*|\.\d+)\s*(hour|day|week)s?\s*$/
or error(__x"invalid timespan '{span}'.", span => $_[1]), return undef;
$2 eq 'hour' ? $1 * 3600
: $2 eq 'day' ? $1 * 86400
: $1 * 604800; # week
}
#--------------------
sub DESTROY
{ my $self = shift;
in_global_destruction || $self->{MB_is_closed}
or $self->close;
}
#--------------------
1;
( run in 2.910 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )