Commit 6fa31801 authored by sikeda's avatar sikeda
Browse files

[-change] Now LAST email command retrieves most recent message in archive and...

[-change] Now LAST email command retrieves most recent message in archive and sympa.pl no longer stores $listdir/archives/last_message file.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12079 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 0a320c97
From: [% from %]
To: [% to %]
Subject: [% FILTER qencode %][%|loc(list.name)%]Archive of %1, file %2[%END%][%END%]
Subject: [% FILTER qencode %][%subject%][%END%]
Content-Type: multipart/mixed; boundary="[% boundary1 %]"
--[% boundary1 %]
......
......@@ -192,7 +192,8 @@ sub fetch {
}
sub next {
my $self = shift;
my $self = shift;
my %options = @_;
return unless $self->{directory};
......@@ -209,6 +210,10 @@ sub next {
} readdir $dh
];
closedir $dh;
# The "reverse" option specific to this class is set.
$self->{_metadatas} = [reverse @{$self->{_metadatas}}]
if $options{reverse};
}
unless (@{$self->{_metadatas}}) {
undef $self->{_metadatas};
......@@ -462,26 +467,8 @@ sub store_html {
return 1;
}
sub store_last {
$log->syslog('debug2', '(%s, %s)', @_);
my $self = shift;
my $message = shift;
my %options = @_;
my $list = $self->{context};
return unless $list->is_archived();
my $dir = $list->{'dir'} . '/archives';
# Create the archive directory if needed
mkdir $dir, 0774 unless -d $dir;
chmod 0774, $dir;
# erase the last message and replace it by the current one
open my $fh, '>', $dir . '/last_message';
print $fh $message->to_string(%options);
close $fh;
}
# DEPRECATED. No longer used.
#sub store_last;
# DEPRECATED. Use get_archives() and select_archive().
#sub list;
......@@ -528,17 +515,8 @@ sub exist {
}
# return path for latest message distributed in the list
sub last_path {
$log->syslog('debug', '(%s)', @_);
my $list = shift;
return undef unless $list->is_archived();
my $file = $list->{'dir'} . '/archives/last_message';
return $file if -f $file;
return undef;
}
# DEPRECATED. No longer used.
#sub last_path;
## Load an archived message, returns the mhonarc metadata
## IN : file_path
......@@ -1047,7 +1025,7 @@ Returns:
Two-elements list of L<Sympa::Message> instance and filehandle locking
a message.
=item next ( )
=item next ( [ reverse =E<gt> 1 ] )
I<Instance method>.
Gets next message in archive.
......@@ -1124,20 +1102,12 @@ Otherwise C<undef>.
I<Instance method>.
TBD.
=item store_last
TBD.
=item get_archives ( )
I<Instance method>.
Gets a list of archive directories this archive contains.
Items of returned value may be fed to select_archive() and so on.
=item last_path
TBD.
=item load_html_message
TBD.
......
......@@ -557,15 +557,6 @@ sub last {
$which, $sender);
return 'no_archive';
}
my $file;
unless ($file = Sympa::Archive::last_path($list)) {
Sympa::Report::reject_report_cmd('user', 'no_required_file', {},
$cmd_line);
$log->syslog('info',
'LAST %s from %s refused, archive file %s not found',
$which, $sender, $file);
return 'no_archive';
}
my $auth_method = get_auth_method(
'last', $sender,
......
......@@ -263,6 +263,7 @@ Returns the list of available files, if any.
=item archive_msg ( MSG )
DEPRECATED.
Archives the Mail::Internet message given as argument.
=item is_archived ()
......@@ -1752,9 +1753,32 @@ sub distribute_msg {
}
}
## Archives
if ($self->is_archiving_enabled) {
$self->archive_msg($message);
# Archives
unless ($self->is_archiving_enabled) {
# Archiving is disabled.
} elsif (
!Sympa::Tools::Data::smart_eq(
$Conf::Conf{'ignore_x_no_archive_header_feature'}, 'on')
and (
grep {
/yes/i
} $message->get_header('X-no-archive')
or grep {
/no\-external\-archive/i
} $message->get_header('Restrict')
)
) {
# Ignoring message with a no-archive flag.
$log->syslog('info',
"Do not archive message with no-archive flag for list %s", $self);
} else {
my $spool = Sympa::Spool::Archive->new;
return $spool->store(
$message,
original => Sympa::Tools::Data::smart_eq(
$self->{admin}{archive_crypted_msg}, 'original'
)
);
}
# Transformation of message after archiving.
......@@ -2816,10 +2840,10 @@ sub send_confirm_to_sender {
#
######################################################
sub archive_send {
$log->syslog('debug2', '(%s, %s, %s)', @_);
my ($self, $who, $arc) = @_;
$log->syslog('debug', '(%s, %s)', $who, $arc);
return unless $self->is_archived();
return undef unless $self->is_archived;
my $archive = Sympa::Archive->new($self);
my @msg_list;
......@@ -2845,24 +2869,26 @@ sub archive_send {
}
}
my $subject = 'File ' . $self->{'name'} . ' ' . $arc;
my $param = {
'to' => $who,
'subject' => $subject,
'msg_list' => [@msg_list]
my $param = {
to => $who,
subject => $language->gettext_sprintf(
'Archive of %s, file %s',
$self->{'name'}, $arc
),
msg_list => [@msg_list],
boundary1 => tools::get_message_id($self->{'domain'}),
boundary2 => tools::get_message_id($self->{'domain'}),
from => Conf::get_robot_conf($self->{'domain'}, 'sympa'),
auto_submitted => 'auto-replied'
};
$param->{'boundary1'} = tools::get_message_id($self->{'domain'});
$param->{'boundary2'} = tools::get_message_id($self->{'domain'});
$param->{'from'} = Conf::get_robot_conf($self->{'domain'}, 'sympa');
$param->{'auto_submitted'} = 'auto-replied';
unless (Sympa::send_file($self, 'get_archive', $who, $param)) {
$log->syslog('notice', 'Unable to send template "archive_send" to %s',
$who);
return undef;
}
return 1;
}
####################################################
......@@ -2876,55 +2902,52 @@ sub archive_send {
#
######################################################
sub archive_send_last {
$log->syslog('debug2', '(%s, %s)', @_);
my ($self, $who) = @_;
$log->syslog('debug', '(%s, %s)', $self->{'listname'}, $who);
return unless ($self->is_archived());
my $dir = $self->{'dir'} . '/archives';
return undef unless $self->is_archived;
my $message = Sympa::Message->new_from_file($dir . '/last_message',
context => $self);
unless (defined $message) {
$log->syslog('err', 'Unable to create Message object %s',
"$dir/last_message");
return undef;
my ($message, $handle);
my $archive = Sympa::Archive->new($self);
foreach my $arc (reverse $archive->get_archives) {
next unless $archive->select_archive($arc);
($message, $handle) = $archive->next(reverse => 1);
last if $message;
}
# Decrypt message if possible
$message->smime_decrypt;
return undef unless $message;
my @msglist;
my $msg = {};
$msg->{'id'} = 1;
$msg->{'subject'} = $message->{'decoded_subject'};
$msg->{'from'} = $message->get_decoded_header('From');
$msg->{'date'} = $message->get_decoded_header('Date');
$msg->{'full_msg'} = $message->as_string;
# Decrypt message if possible.
$message->smime_decrypt;
push @msglist, $msg;
my @msglist = (
{ id => 1,
subject => $message->{'decoded_subject'},
from => $message->get_decoded_header('From'),
date => $message->get_decoded_header('Date'),
full_msg => $message->as_string
}
);
my $subject = 'File ' . $self->{'name'} . '.last_message';
my $param = {
'to' => $who,
'subject' => $subject,
'msg_list' => \@msglist
my $param = {
to => $who,
subject => $language->gettext_sprintf(
'Archive of %s, last message',
$self->{'name'}
),
msg_list => [@msglist],
boundary1 => tools::get_message_id($self->{'domain'}),
boundary2 => tools::get_message_id($self->{'domain'}),
from => Conf::get_robot_conf($self->{'domain'}, 'sympa'),
auto_submitted => 'auto-replied'
};
$param->{'boundary1'} = tools::get_message_id($self->{'domain'});
$param->{'boundary2'} = tools::get_message_id($self->{'domain'});
$param->{'from'} = Conf::get_robot_conf($self->{'domain'}, 'sympa');
$param->{'auto_submitted'} = 'auto-replied';
# open TMP2, ">/tmp/digdump";
# Sympa::Tools::Data::dump_var($param, 0, \*TMP2);
# close TMP2;
unless (Sympa::send_file($self, 'get_archive', $who, $param)) {
$log->syslog('notice', 'Unable to send template "archive_send" to %s',
$who);
return undef;
}
return 1;
}
### NOTIFICATION SENDING ###
......@@ -5799,40 +5822,8 @@ sub is_digest {
# DEPRECATED. Use Sympa::Archive::get_archives().
#sub archive_ls;
sub archive_msg {
$log->syslog('debug2', '(%s, %s)', @_);
my ($self, $message) = @_;
if ($self->is_archiving_enabled) {
Sympa::Archive->new($self)->store_last(
$message,
original => Sympa::Tools::Data::smart_eq(
$self->{admin}{archive_crypted_msg}, 'original'
)
);
# Ignoring message with a no-archive flag
if (!Sympa::Tools::Data::smart_eq(
$Conf::Conf{'ignore_x_no_archive_header_feature'}, 'on')
and ( grep {/yes/i} $message->get_header('X-no-archive')
or grep {/no\-external\-archive/i}
$message->get_header('Restrict'))
) {
$log->syslog('info',
"Do not archive message with no-archive flag for list %s",
$self);
return 1;
}
my $spool = Sympa::Spool::Archive->new;
return $spool->store(
$message,
original => Sympa::Tools::Data::smart_eq(
$self->{admin}{archive_crypted_msg}, 'original'
)
);
}
}
# Merged into distribute_msg().
#sub archive_msg;
## Is the list moderated?
sub is_moderated {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment