Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MHonArc resource file #1095

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ nobase_default_DATA = \
create_list.conf \
edit_list.conf \
ldap_alias_entry.tt2 \
mhonarc-ressources.tt2 \
mhonarc_rc.tt2 \
mime.types \
nrcpt_by_domain.conf \
sympa.wsdl \
Expand Down
364 changes: 150 additions & 214 deletions default/mhonarc-ressources.tt2 → default/mhonarc_rc.tt2

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions default/web_tt2/css.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ div.admin_cmd a {
}
[%~ END # IF 0 ~%]

/* Calendar in mhonarc-ressources.tt2 */
/* Calendar in mhonarc_rc.tt2 */
ul.calendar {
margin-left:0!important;
padding-left:0!important;
Expand Down Expand Up @@ -1919,7 +1919,7 @@ ul li.calendarLinksInactive {
ul li.calendarYear {
border: 1px solid;
}
/* end calendar in mhonarc-ressources.tt2 */
/* end calendar in mhonarc_rc.tt2 */

abbr,
acronym,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/tpl2tt2.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ foreach my $tpl (@templates) {
if ($tpl =~ /mhonarc\-ressources$/) {
rename $tpl, "$tpl.incompatible";
printf STDERR
"File $tpl could not be translated to TT2 ; it has been renamed $tpl.incompatible. You should customize a standard mhonarc-ressourses.tt2 file\n";
"File $tpl could not be translated to TT2 ; it has been renamed $tpl.incompatible. You should customize a standard mhonarc_rc.tt2 file\n";
next;
}

Expand Down
59 changes: 17 additions & 42 deletions src/lib/Sympa/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ package Sympa::Archive;
use strict;
use warnings;
use Cwd qw();
use Digest::MD5 qw();
use Encode qw();
use English qw(-no_match_vars);
use File::Path qw();
Expand Down Expand Up @@ -490,27 +489,24 @@ sub html_store {
return undef;
}

my $mhonarc_ressources =
Sympa::search_fullpath($list, 'mhonarc-ressources.tt2');
my $mhonarc_rc = Sympa::search_fullpath($list, 'mhonarc_rc.tt2');

$log->syslog(
'debug',
'Calling %s for list %s',
Conf::get_robot_conf($list->{'domain'}, 'mhonarc'), $list
);

my $tag = _get_tag($list);

# Call mhonarc on cleaned message source to make clean htlm view of
# message.
my @cmd = (
Conf::get_robot_conf($list->{'domain'}, 'mhonarc'),
'-add',
'-addressmodifycode' => '1', # w/a: Clear old cache in .mhonarc.db.
'-rcfile' => $mhonarc_ressources,
'-rcfile' => $mhonarc_rc,
'-outdir' => $self->{arc_directory},
'-definevars' => sprintf(
"listname='%s' hostname=%s yyyy=%s mois=%s yyyymm=%s-%s wdir=%s base=%s/arc tag=%s with_tslice=1 with_powered_by=1",
"listname='%s' hostname=%s yyyy=%s mois=%s yyyymm=%s-%s wdir=%s base=%s/arc with_tslice=1 with_powered_by=1",
$list->{'name'},
$list->{'domain'},
$yyyy,
Expand All @@ -519,7 +515,6 @@ sub html_store {
$mm,
Conf::get_robot_conf($list->{'domain'}, 'arc_path'),
(Conf::get_robot_conf($list->{'domain'}, 'wwsympa_url') || ''),
$tag
),
'-umask' => $Conf::Conf{'umask'}
);
Expand Down Expand Up @@ -645,9 +640,7 @@ sub html_rebuild {
my $robot_id = $list->{'domain'};
my $arc_directory = $self->{arc_directory};

my $tag = _get_tag($list);
my $mhonarc_ressources =
Sympa::search_fullpath($list, 'mhonarc-ressources.tt2');
my $mhonarc_rc = Sympa::search_fullpath($list, 'mhonarc_rc.tt2');

# Remove existing HTML files and .mhonarc.db.
my $dh;
Expand Down Expand Up @@ -675,10 +668,10 @@ sub html_rebuild {
my @cmd = (
Conf::get_robot_conf($robot_id, 'mhonarc'),
'-addressmodifycode' => '1', # w/a: Clear old cache in .mhonarc.db.
'-rcfile' => $mhonarc_ressources,
'-rcfile' => $mhonarc_rc,
'-outdir' => $arc_directory,
'-definevars' => sprintf(
"listname='%s' hostname=%s yyyy=%s mois=%s yyyymm=%s-%s wdir=%s base=%s/arc tag=%s with_tslice=1 with_powered_by=1",
"listname='%s' hostname=%s yyyy=%s mois=%s yyyymm=%s-%s wdir=%s base=%s/arc with_tslice=1 with_powered_by=1",
$listname,
$robot_id,
$yyyy,
Expand All @@ -687,7 +680,6 @@ sub html_rebuild {
$mm,
Conf::get_robot_conf($robot_id, 'arc_path'),
(Conf::get_robot_conf($robot_id, 'wwsympa_url') || ''),
$tag
),
'-umask' => $Conf::Conf{'umask'},
$dir_to_rebuild
Expand Down Expand Up @@ -890,10 +882,9 @@ sub html_format {
map { Sympa::Tools::Text::encode_uri($_) } @$attachment_url;
}

my $mhonarc_ressources =
Sympa::search_fullpath($that, 'mhonarc-ressources.tt2');
unless ($mhonarc_ressources) {
$log->syslog('notice', 'Cannot find any MhOnArc ressource file');
my $mhonarc_rc = Sympa::search_fullpath($that, 'mhonarc_rc.tt2');
unless ($mhonarc_rc) {
$log->syslog('notice', 'Cannot find any MHonArc resource file');
return undef;
}

Expand Down Expand Up @@ -923,21 +914,19 @@ sub html_format {
return undef;
}

my $tag = _get_tag($that);
my $exitcode = system(
Conf::get_robot_conf($robot, 'mhonarc'),
'-single',
'-rcfile' => $mhonarc_ressources,
'-rcfile' => $mhonarc_rc,
'-definevars' => sprintf(
"listname='%s' hostname=%s yyyy='' mois='' tag=%s with_tslice='' with_powered_by=''",
$listname, $domain, $tag
"listname='%s' hostname=%s yyyy='' mois='' with_tslice='' with_powered_by=''",
$listname, $domain
),
'-outdir' => $destination_dir,
'-attachmentdir' => $destination_dir,
'-attachmenturl' =>
sprintf('(%s%% path_cgi %%%s)/%s', $tag, $tag, $attachment_url),
'-umask' => $Conf::Conf{'umask'},
'-stdout' => "$destination_dir/msg00000.html",
'-attachmenturl' => sprintf('<%% path_cgi %%>/%s', $attachment_url),
'-umask' => $Conf::Conf{'umask'},
'-stdout' => "$destination_dir/msg00000.html",
'--',
$msg_file
) >> 8;
Expand All @@ -957,22 +946,8 @@ sub html_format {
}

# Old name: Sympa::Archive::get_tag(), get_tag() in archived.pl.
sub _get_tag {
my $that = shift;

my $name;
if (ref $that eq 'Sympa::List') {
$name = $that->{'name'};
} elsif (!ref($that) and $that and $that ne '*') {
$name = $that;
} elsif (!ref($that)) {
$name = '*';
}

my $cookie = $Conf::Conf{'cookie'};
$cookie = '' unless defined $cookie;
return substr(Digest::MD5::md5_hex(join '/', $cookie, $name), -10);
}
# No longer used.
#sub _get_tag;

sub get_id {
my $self = shift;
Expand Down
40 changes: 40 additions & 0 deletions src/lib/Sympa/Upgrade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,46 @@ sub upgrade {
}
}

# Variable tags "($tag$% ... %$tag$)" no longer used in
# mhonarc_rc.tt2 (ex. mhonarc-ressources.tt2) and were replaced with
# "<% ... %>".
if (lower_version($previous_version, '6.2.61b.1')) {
$log->syslog('notice', 'Converting mhonarc-ressources.tt2...');

my $oldfile = 'mhonarc-ressources.tt2';
my $newfile = 'mhonarc_rc.tt2';
my @dirs;

push @dirs, $Conf::Conf{'etc'}
if -f $Conf::Conf{'etc'} . '/' . $oldfile;
foreach my $robot (Sympa::List::get_robots()) {
my $dir = sprintf '%s/%s', $Conf::Conf{'etc'}, $robot;
push @dirs, $dir
if -f $dir . '/' . $oldfile;
foreach my $list (@{Sympa::List::get_lists($robot) || []}) {
push @dirs, $list->{'dir'}
if -f $list->{'dir'} . '/' . $oldfile;
}
}

foreach my $dir (@dirs) {
open my $ifh, '<', $dir . '/' . $oldfile
or die sprintf '%s: %s', $oldfile, $ERRNO;
my $text = do { local $RS; <$ifh> };
close $ifh;

$text =~ s{[(]\$tag\$%}{<%}g;
$text =~ s{%\$tag\$[)]}{%>}g;

open my $ofh, '>', $dir . '/' . $newfile
or die sprintf '%s: %s', $newfile, $ERRNO;
print $ofh $text;
close $ofh;
}

$log->syslog('notice', '...Done. Use new file(s) mhonarc_rc.tt2.');
}

return 1;
}

Expand Down
11 changes: 10 additions & 1 deletion src/sbin/archived.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,16 @@ Print this help message.

F<$SPOOLDIR/outgoing/> outgoing Sympa directory.

F<$DEFAULTDIR/mhonarc-ressources.tt2> template of MHonArc resource file.
F<$DEFAULTDIR/mhonarc_rc.tt2> template of MHonArc resource file.

=over

=item *

F<mhonarc-ressources.tt2> was replaced with F<mhonarc_rc.tt2>
on Sympa 6.2.61b.1.

=back

F<--CONFIG--> Sympa configuration file.

Expand Down
2 changes: 1 addition & 1 deletion t/parse_templates.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sub _do_test {
close $fh;
$tpl = "[% TAGS $tags %]$tpl";
$tpl = [split /(?<=\n)/, $tpl];
} elsif ($tpl eq 'mhonarc-ressources.tt2') {
} elsif ($tpl eq 'mhonarc_rc.tt2') {
open my $fh, '<', $dir . '/' . $tpl;
$tpl = do { local $RS; <$fh> };
close $fh;
Expand Down