From 8fdf751d37be3f0e29167e08acd9b8a9f06245d4 Mon Sep 17 00:00:00 2001 From: andreaskurz Date: Thu, 13 Apr 2023 04:56:23 +0200 Subject: [PATCH] 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. --- lib/send.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/send.php b/lib/send.php index a3b93da..852470a 100644 --- a/lib/send.php +++ b/lib/send.php @@ -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; + } } ?>