Commit 6a6a41b0 authored by Clément OUDOT's avatar Clément OUDOT
Browse files

Use regexp to replace values in email only for text body (#2495)

parent 32d561e4
......@@ -94,6 +94,11 @@ sub run {
# We use a specific text message, no html
$body = $self->conf->{mail2fBody};
# Replace variables in body
$body =~ s/\$code/$code/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
}
else {
......@@ -109,12 +114,6 @@ sub run {
$html = 1;
}
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$code/$code/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
# Send mail
unless ( $self->send_mail( $dest, $subject, $body, $html ) ) {
$self->logger->error( 'Unable to send 2F code mail to ' . $dest );
......
......@@ -371,6 +371,13 @@ sub _certificateReset {
# We use a specific text message, no html
$body = $self->conf->{certificateResetByMailStep1Body};
# Replace variables in body
$body =~ s/\$expMailDate/$req->data->{expMailDate}/ge;
$body =~ s/\$expMailTime/$req->data->{expMailTime}/ge;
$body =~ s/\$url/$url/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
}
else {
......@@ -388,14 +395,6 @@ sub _certificateReset {
$html = 1;
}
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$expMailDate/$req->data->{expMailDate}/ge;
$body =~ s/\$expMailTime/$req->data->{expMailTime}/ge;
$body =~ s/\$url/$url/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
# Send mail
unless (
$self->send_mail(
......@@ -555,6 +554,10 @@ sub modifyCertificate {
# We use a specific text message, no html
$body = $self->conf->{certificateResetByMailStep2Body};
# Replace variables in body
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
}
else {
......@@ -568,11 +571,6 @@ sub modifyCertificate {
$html = 1;
}
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
# Send mail
return PE_MAILERROR
unless $self->send_mail( $req->data->{mailAddress}, $subject, $body,
......
......@@ -335,6 +335,13 @@ sub _reset {
# We use a specific text message, no html
$body = $self->conf->{mailConfirmBody};
# Replace variables in body
$body =~ s/\$expMailDate/$req->data->{expMailDate}/ge;
$body =~ s/\$expMailTime/$req->data->{expMailTime}/ge;
$body =~ s/\$url/$url/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
}
else {
......@@ -352,14 +359,6 @@ sub _reset {
$html = 1;
}
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$expMailDate/$req->data->{expMailDate}/ge;
$body =~ s/\$expMailTime/$req->data->{expMailTime}/ge;
$body =~ s/\$url/$url/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
$self->logger->info( "User "
. $req->data->{mailAddress}
. " is trying to reset his/her password" );
......@@ -515,6 +514,11 @@ sub changePwd {
# We use a specific text message, no html
$body = $self->conf->{mailBody};
# Replace variables in body
$body =~ s/\$password/$password/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
}
else {
......@@ -530,12 +534,6 @@ sub changePwd {
$html = 1;
}
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$password/$password/g;
$body =~ s/\$(\w+)/$req->{sessionInfo}->{$1} || ''/ge;
# Send mail
return PE_MAILERROR
unless $self->send_mail( $req->data->{mailAddress}, $subject, $body,
......
......@@ -322,14 +322,6 @@ sub _register {
},
);
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$expMailDate/$req->data->{expMailDate}/g;
$body =~ s/\$expMailTime/$req->data->{expMailTime}/g;
$body =~ s/\$url/$url/g;
$body =~ s/\$(\w+)/$req->data->{registerInfo}->{$1}/eg;
# Send mail
return PE_MAILERROR
unless $self->send_mail( $req->data->{registerInfo}->{mail},
......@@ -397,12 +389,6 @@ sub _register {
},
);
# Replace variables in body
# FIXME: kept for compatibility with 2.0.0 mail templates
# in future versions this should only happen for plaintext emails
$body =~ s/\$url/$url/g;
$body =~ s/\$(\w+)/$req->data->{registerInfo}->{$1}/ge;
# Send mail
return PE_MAILERROR
unless $self->send_mail( $req->data->{registerInfo}->{mail},
......
Markdown is supported
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