Create localization fallback (#17)

* Fix function call

get_email_from is a class function and should therefore be called like one.

* Create default localization

This will use en_US as a default fallback for localization in case the user has configured a language in roundcube where localization is missing.
This lead to empty emails without any confirmation code being sent.
This commit is contained in:
andreaskurz 2023-04-13 04:56:23 +02:00 committed by GitHub
parent 0d1b340499
commit 8fdf751d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -101,7 +101,7 @@ class password_recovery_send {
// Send message to administrator
function send_alert_to_admin($user_requesting_new_password) {
$file = dirname(__FILE__) . "/../localization/" . $this->rc->user->language . "/alert_for_admin_to_reset_pw.html";
$file = $this->get_localization_dir($this->rc->user->language) . "/alert_for_admin_to_reset_pw.html";
$body = strtr(file_get_contents($file), array('[USER]' => $user_requesting_new_password));
$subject = $this->pr->gettext('email_subject_admin');
return $this->send_email(
@ -121,14 +121,14 @@ class password_recovery_send {
if ($confirm_code && $this->pr->set_user_props(['token'=>$confirm_code])) {
// send EMail
if ($this->user['have_altemail']) {
$file = dirname(__FILE__) . "/../localization/" . $this->rc->user->language . "/reset_pw_body.html";
$file = $this->get_localization_dir($this->rc->user->language) . "/reset_pw_body.html";
$link = "http://{$_SERVER['SERVER_NAME']}/?_task=login&_action=plugin.password_recovery&_username=". $this->user['username'];
$body = strtr(file_get_contents($file), ['[LINK]' => $link, '[CODE]' => $confirm_code]);
$subject = $this->pr->gettext('email_subject');
$from = $this->rc->config->get('pr_replyto_email');
if(!$from){
$from = get_email_from($this->rc->config->get('pr_admin_email'));
$from = $this->get_email_from($this->rc->config->get('pr_admin_email'));
}
$send_email = $this->send_email(
@ -195,6 +195,14 @@ class password_recovery_send {
$parts = explode('@',$email);
return 'no-reply@'.$parts[1];
}
function get_localization_dir($language) {
$file = dirname(__FILE__) . "/../localization/" . $language;
if (!file_exists($file)) {
$file = dirname(__FILE__) . "/../localization/en_US";
}
return $file;
}
}
?>