Skip to content

Commit

Permalink
Merge pull request #1167 from ikedas/obsolete-escape_chars by ikedas
Browse files Browse the repository at this point in the history
Obsolete escape_chars() / unescape_chars()
  • Loading branch information
ikedas authored May 21, 2021
2 parents a5808af + 3399416 commit 3264df0
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 115 deletions.
10 changes: 5 additions & 5 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -8948,7 +8948,6 @@ sub do_remove_arc {
wwslog('info', 'List %s, yyyy %s, mm %s, #message %s',
$in{'list'}, $in{'yyyy'}, $in{'month'});

# $in{'msgid'} = Sympa::Tools::Text::unescape_chars($in{'msgid'});
my @msgids = split /\0/, $in{'msgid'};
my @msg_subjects = split /\0/, $in{'msg_subject'};

Expand Down Expand Up @@ -9467,7 +9466,6 @@ sub do_arcsearch_id {
return undef;
}

#$in{'msgid'} = Sympa::Tools::Text::unescape_chars($in{'msgid'});
$param->{'msgid'} = $in{'msgid'};

$search->limit(1);
Expand Down Expand Up @@ -10073,10 +10071,11 @@ sub do_viewbounce {

my $html_relpath;
if ($in{'email'}) {
my $escaped_email = Sympa::Tools::Text::escape_chars($in{'email'});
my $escaped_email =
Sympa::Tools::Text::encode_filesystem_safe($in{'email'});
$html_relpath =
$in{'envid'}
? sprintf('%s_%08s', $escaped_email, $in{'envid'})
? sprintf('%s__%08s', $escaped_email, $in{'envid'})
: $escaped_email;
} elsif ($in{'dir'} and $in{'file'}) {
$html_relpath = $in{'dir'};
Expand Down Expand Up @@ -10310,7 +10309,8 @@ sub do_resetbounce {

foreach my $email (@emails) {

my $escaped_email = Sympa::Tools::Text::escape_chars($email);
my $escaped_email =
Sympa::Tools::Text::encode_filesystem_safe($email);

unless ($list->is_list_member($email)) {
Sympa::WWW::Report::reject_report_web('user',
Expand Down
8 changes: 0 additions & 8 deletions src/lib/Sympa/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,6 @@ sub html_remove {
'-rmm' => $msgid
);

# Remomve urlized message.
my $url_dir =
$list->{'dir'}
. '/urlized/'
. Sympa::Tools::Text::escape_chars($msgid);
my $error;
File::Path::remove_tree($url_dir, {error => \$error});

return 1;
}

Expand Down
31 changes: 0 additions & 31 deletions src/lib/Sympa/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1208,37 +1208,6 @@ sub get_recipients_per_mode {
next;
}

#XXX Following will be done by ProcessOutgoing spindle.
# # Message should be re-encrypted, however, user certificate is
# # missing.
# if ($message->{'smime_crypted'}
# and not -r $Conf::Conf{'ssl_cert_dir'} . '/'
# . Sympa::Tools::Text::escape_chars($user->{'email'})
# and not -r $Conf::Conf{'ssl_cert_dir'} . '/'
# . Sympa::Tools::Text::escape_chars($user->{'email'} . '@enc')) {
# my $subject = $message->{'decoded_subject'};
# my $sender = $message->{'sender'};
# unless (
# Sympa::send_file(
# $self,
# 'x509-user-cert-missing',
# $user->{'email'},
# { 'mail' =>
# {'subject' => $subject, 'sender' => $sender},
# 'auto_submitted' => 'auto-generated'
# }
# )
# ) {
# $log->syslog(
# 'notice',
# 'Unable to send template "x509-user-cert-missing" to %s',
# $user->{'email'}
# );
# }
# next;
# }
# # Otherwise it may be shelved encryption.

if ($user->{'reception'} eq 'txt') {
if ($user->{'bounce_address'}) {
push @tabrcpt_txt_verp, $user->{'email'};
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Sympa/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1117,9 +1117,9 @@ sub smime_encrypt {
my $certfile;
my $entity;

my $base =
$Conf::Conf{'ssl_cert_dir'} . '/'
. Sympa::Tools::Text::escape_chars($email);
my $base = sprintf '%s/%s',
$Conf::Conf{'ssl_cert_dir'},
Sympa::Tools::Text::encode_filesystem_safe($email);
if (-f $base . '@enc') {
$certfile = $base . '@enc';
} else {
Expand Down Expand Up @@ -1353,8 +1353,8 @@ sub check_smime_signature {
# or a pair of single-purpose. save them, as email@addr if combined,
# or as email@addr@sign / email@addr@enc for split certs.
foreach my $c (keys %certs) {
my $filename = "$Conf::Conf{ssl_cert_dir}/"
. Sympa::Tools::Text::escape_chars(lc($sender));
my $filename = sprintf '%s/%s', $Conf::Conf{ssl_cert_dir},
Sympa::Tools::Text::encode_filesystem_safe(lc $sender);
if ($c ne 'both') {
unlink $filename; # just in case there's an old cert left...
$filename .= "\@$c";
Expand Down
14 changes: 9 additions & 5 deletions src/lib/Sympa/Spindle/ProcessTask.pm
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,11 @@ sub do_purge_orphan_bounces {
$user_ref;
$user_ref = $list->get_next_bouncing_list_member()
) {
my $user_id = $user_ref->{'email'};
$bounced_users{Sympa::Tools::Text::escape_chars($user_id)} = 1;
$bounced_users{
Sympa::Tools::Text::encode_filesystem_safe(
$user_ref->{email}
)
} = 1;
}

my $bounce_dir = $list->get_bounce_dir();
Expand All @@ -935,10 +938,10 @@ sub do_purge_orphan_bounces {
while ($marshalled = readdir $dh) {
my $metadata =
Sympa::Spool::unmarshal_metadata($bounce_dir, $marshalled,
qr/\A([^\s\@]+\@[\w\.\-*]+?)(?:_(\w+))?\z/,
qr/\A([^\s\@]+\@[\w\.\-*]+?)(?:__(\w+))?\z/,
[qw(recipient envid)]);
next unless $metadata;
# Skip <email>_<envid> which is used by tracking feature.
# Skip <email>__<envid> which is used by tracking feature.
next if defined $metadata->{envid};

unless ($bounced_users{$marshalled}) {
Expand Down Expand Up @@ -1014,7 +1017,8 @@ sub do_expire_bounce {
$email);
next;
}
my $escaped_email = Sympa::Tools::Text::escape_chars($email);
my $escaped_email =
Sympa::Tools::Text::encode_filesystem_safe($email);

my $bounce_dir = $list->get_bounce_dir();

Expand Down
55 changes: 10 additions & 45 deletions src/lib/Sympa/Tools/Text.pm
Original file line number Diff line number Diff line change
Expand Up @@ -249,32 +249,8 @@ sub encode_uri {
}

# Old name: tools::escape_chars().
sub escape_chars {
my $s = shift;
my $except = shift; ## Exceptions
my $ord_except = ord $except if defined $except;

## Escape chars
## !"#$%&'()+,:;<=>?[] AND accented chars
## escape % first
foreach my $i (
0x25,
0x20 .. 0x24,
0x26 .. 0x2c,
0x3a .. 0x3f,
0x5b, 0x5d,
0x80 .. 0x9f,
0xa0 .. 0xff
) {
next if defined $ord_except and $i == $ord_except;
my $hex_i = sprintf "%lx", $i;
$s =~ s/\x$hex_i/%$hex_i/g;
}
## Special traetment for '/'
$s =~ s/\//%a5/g unless defined $except and $except eq '/';

return $s;
}
# Moved to: Sympa::Upgrade::_escape_chars()
#sub escape_chars;

# Old name: tt2::escape_url().
# DEPRECATED. Use Sympa::Tools::Text::escape_uri() or
Expand Down Expand Up @@ -539,19 +515,8 @@ sub _gc_length {
}

# Old name: tools::unescape_chars().
sub unescape_chars {
my $s = shift;

$s =~ s/%a5/\//g; ## Special traetment for '/'
foreach my $i (0x20 .. 0x2c, 0x3a .. 0x3f, 0x5b, 0x5d, 0x80 .. 0x9f,
0xa0 .. 0xff) {
my $hex_i = sprintf "%lx", $i;
my $hex_s = sprintf "%c", $i;
$s =~ s/%$hex_i/$hex_s/g;
}

return $s;
}
# Moved to: Sympa::Upgrade::_unescape_chars().
#sub unescape_chars;

# Old name: tools::valid_email().
sub valid_email {
Expand Down Expand Up @@ -770,10 +735,10 @@ Encoded string, stripped C<utf8> flag if any.

=item escape_chars ( $str )

Escape weird characters.
B<Deprecated>.
Use L</encode_filesystem_safe>.

ToDo: This should be obsoleted in the future release: Would be better to use
L</encode_filesystem_safe>.
Escape weird characters.

=item escape_url ( $str )

Expand Down Expand Up @@ -906,10 +871,10 @@ C<$file> is the path to text file.

=item unescape_chars ( $str )

Unescape weird characters.
B<Deprecated>.
Use L</decode_filesystem_safe>.

ToDo: This should be obsoleted in the future release: Would be better to use
L</decode_filesystem_safe>.
Unescape weird characters.

=item valid_email ( $string )

Expand Down
16 changes: 8 additions & 8 deletions src/lib/Sympa/Tracking.pm
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ sub store {
unless (_db_insert_notification($rcpt, %options)) {
return undef;
}
$filename = sprintf '%s_%08s',
Sympa::Tools::Text::escape_chars($rcpt),
$filename = sprintf '%s__%08s',
Sympa::Tools::Text::encode_filesystem_safe($rcpt),
$options{envid};
} else {
unless (
Expand All @@ -275,7 +275,7 @@ sub store {
$rcpt, $self->{context});
return undef;
}
$filename = Sympa::Tools::Text::escape_chars($rcpt);
$filename = Sympa::Tools::Text::encode_filesystem_safe($rcpt);
}
unless (open $ofh, '>', $bounce_dir . '/' . $filename) {
$log->syslog('err', 'Unable to write %s/%s', $bounce_dir, $filename);
Expand Down Expand Up @@ -479,7 +479,7 @@ sub remove_message_by_email {
return undef unless $email;

my $bounce_dir = $self->{directory};
my $escaped_email = Sympa::Tools::Text::escape_chars($email);
my $escaped_email = Sympa::Tools::Text::encode_filesystem_safe($email);
my $ret = unlink sprintf('%s/%s', $bounce_dir, $escaped_email);

# Remove HTML view.
Expand Down Expand Up @@ -540,9 +540,9 @@ sub remove_message_by_id {
while (my $info = $sth->fetchrow_hashref('NAME_lc')) {
my $bounce_dir = $self->{directory};
my $escaped_email =
Sympa::Tools::Text::escape_chars($info->{'recipient'});
Sympa::Tools::Text::encode_filesystem_safe($info->{'recipient'});
my $envid = $info->{'envid'};
unlink sprintf('%s/%s_%08s', $bounce_dir, $escaped_email, $envid);
unlink sprintf('%s/%s__%08s', $bounce_dir, $escaped_email, $envid);
}
$sth->finish;

Expand Down Expand Up @@ -619,9 +619,9 @@ sub remove_message_by_period {
while (my $info = $sth->fetchrow_hashref('NAME_lc')) {
my $bounce_dir = $self->{directory};
my $escaped_email =
Sympa::Tools::Text::escape_chars($info->{'recipient'});
Sympa::Tools::Text::encode_filesystem_safe($info->{'recipient'});
my $envid = $info->{'envid'};
unlink sprintf('%s/%s_%08s', $bounce_dir, $escaped_email, $envid);
unlink sprintf('%s/%s__%08s', $bounce_dir, $escaped_email, $envid);
}
$sth->finish;

Expand Down
Loading

0 comments on commit 3264df0

Please sign in to comment.