Unverified Commit 4975105e authored by Luc Didry's avatar Luc Didry
Browse files

Add « report as spam » option when deleting archives

Fix #634
parent c6bde60d
......@@ -246,10 +246,17 @@ IDXPGEND
</ul>
<br />
($tag$% IF is_owner %$tag$)
<input type="hidden" name="yyyy" value="$yyyy$" />
<input type="hidden" name="month" value="$mois$" />
<input type="hidden" name="yyyy" value="$yyyy$" />
<input type="hidden" name="month" value="$mois$" />
<input type="hidden" name="action" value="remove_arc" />
<input type="hidden" name="list" value ="($tag$% list %$tag$)" />
<input type="hidden" name="list" value ="($tag$% list %$tag$)" />
($tag$% IF conf.reporting_spam_script_path %$tag$)
<input type="checkbox" id="signal_as_spam" name="signal_as_spam">
<label for="signal_as_spam">
($tag$%|loc%$tag$)Report messages as undetected spam($tag$%END%$tag$)
</label>
($tag$%END%$tag$)
<br />
<input type="button" class="MainMenuLinks"
value="($tag$%|loc%$tag$)Toggle Selection($tag$%END%$tag$)" />
<input type="submit" class="MainMenuLinks" name="action_remove_arc"
......
......@@ -478,6 +478,13 @@
[% FOREACH m = msgid ~%]
<input type="hidden" name="msgid" value="[% m %]" />
[%~ END %]
[% IF is_listmaster || is_owner %]
<input type="checkbox" name="signal_as_spam"
[% IF signal_as_spam %]checked[% END %] />
<label for="signal_as_spam">
[%|loc%]Report messages as undetected spam[%END%]
</label>
[%~ END %]
[%~ ELSIF confirm_action == 'remove_template' ~%]
<input type="hidden" name="webormail" value="[% webormail %]" />
<input type="hidden" name="scope" value="[% scope %]" />
......
......@@ -8972,14 +8972,18 @@ sub do_remove_arc {
$param->{'status'} = 'no_msgid';
return undef;
}
$param->{'yyyy'} = $in{'yyyy'};
$param->{'month'} = $in{'month'};
$param->{'msgid'} = [@msgids];
$param->{'yyyy'} = $in{'yyyy'};
$param->{'month'} = $in{'month'};
$param->{'signal_as_spam'} = $in{'signal_as_spam'};
$param->{'msgid'} = [@msgids];
 
# Action confirmed?
my $next_action = $session->confirm_action(
$in{'action'}, $in{'response_action'},
arg => join(',', $in{'yyyy'}, $in{'month'}, @msgids),
$in{'action'},
$in{'response_action'},
arg => join(
',', $in{'yyyy'}, $in{'month'}, $in{signal_as_spam}, @msgids
),
previous_action => 'arc'
);
unless ($next_action eq '1') {
......@@ -8992,6 +8996,12 @@ sub do_remove_arc {
my $tracking = Sympa::Tracking->new(context => $list);
foreach my $msgid (@msgids) {
chomp $msgid;
if (defined($in{signal_as_spam})
&& $Conf::Conf{'reporting_spam_script_path'} ne '') {
$msg_string .= sprintf "signal_spam %s %s-%s %s\n",
$list->{'name'},
$in{'yyyy'}, $in{'month'}, $msgid;
}
$msg_string .= sprintf "remove_arc %s %s-%s %s\n", $list->{'name'},
$in{'yyyy'}, $in{'month'}, $msgid;
 
......
......@@ -179,6 +179,22 @@ sub _do_command {
}
_do_remove_arc($context, $arc, $msgid, $message->{sender});
} elsif ($order eq 'signal_spam') {
my ($arc, $msgid) = split /\s+/, $args, 2;
unless (ref $context eq 'Sympa::List') {
$log->syslog('err', 'Unknown list %s', $listname);
next;
}
unless ($arc =~ /\A\d{4}-\d{2}\z/) {
$log->syslog('err', 'Illegal archive path "%s"', $arc);
next;
}
unless ($msgid and $msgid !~ /NO-ID-FOUND\.mhonarc\.org/) {
$log->syslog('err', 'No message id found');
next;
}
_do_signal_as_spam($context, $arc, $msgid, $message->{sender});
} elsif ($order eq 'rebuildarc') {
my $arc = (defined $args and length $args) ? $args : '*';
unless ($arc =~ /\A\d{4}-\d{2}\z/ or $arc eq '*') {
......@@ -268,6 +284,93 @@ sub _do_remove_arc {
return 1;
}
sub _do_signal_as_spam {
$log->syslog('debug2', '(%s, %s, %s, %s)', @_);
my $list = shift;
my $arc = shift;
my $msgid = shift;
my $sender = shift;
my $archive = Sympa::Archive->new(context => $list);
unless ($archive->select_archive($arc)) {
$log->syslog('err', 'No archive %s of %s', $arc, $archive);
return undef;
}
my ($arc_message, $arc_handle) = $archive->fetch(message_id => $msgid);
unless ($arc_message) {
$log->syslog('err',
'Unable to load message with message ID %s found in %s of %s',
$msgid, $arc, $archive);
return undef;
}
# If not list owner nor listmaster, check if
# sender of remove order is sender of the message to be
# removed.
unless ($list->is_admin('owner', $sender)
or Sympa::is_listmaster($list, $sender)) {
unless (lc $sender eq lc($arc_message->{sender} || '')) {
$log->syslog('err',
'Signal as spam command for %s by unauthorized sender: %s',
$arc_message, $sender);
return undef;
}
}
# At this point, requested command is from an authorized person
# (message sender or list admin or listmaster).
$log->syslog('notice', 'Signaling %s in %s of archive %s as spam',
$msgid, $arc, $archive);
if ($Conf::Conf{'reporting_spam_script_path'} ne '') {
if (-x $Conf::Conf{'reporting_spam_script_path'}) {
my $script;
unless (
open($script, "|$Conf::Conf{'reporting_spam_script_path'}")) {
$log->syslog('err',
"could not execute $Conf::Conf{'reporting_spam_script_path'}"
);
return undef;
}
# Sending encrypted form in case a crypted message would be
# sent by error.
print $script $arc_message->as_string;
if (close($script)) {
$log->syslog('info',
"message $msgid reported as spam by $sender");
} else {
$log->syslog('err',
"could not report message $msgid as spam (close failed)");
return undef;
}
} else {
$log->syslog('err',
"ignoring parameter reporting_spam_script_path, value $Conf::Conf{'reporting_spam_script_path'} because not an executable script"
);
return undef;
}
}
$log->db_log(
'robot' => $list->{'domain'},
'list' => $list->{'name'},
'action' => 'signal_spam',
'parameters' => $msgid,
'msg_id' => $msgid,
'status' => 'success',
'user_email' => $sender
);
$log->add_stat(
'robot' => $list->{'domain'},
'list' => $list->{'name'},
'operation' => 'signal_spam',
'mail' => $sender
);
return 1;
}
# Old name: do_rebuildarc() in archived.pl.
sub _do_rebuildarc {
$log->syslog('debug2', '(%s, %s)', @_);
......
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