From 1a2053b0a007da804f491bf19ce64544f2ef3f00 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Wed, 19 Jun 2019 09:30:34 +0100
Subject: [PATCH] FIX #10950 TIME 0:15 set phpmailer From in all cases to send
 email + rm disabled attributes + wording

---
 modules/sendmail/sendmail_ajax_content.php    |  2 +-
 src/app/email/controllers/EmailController.php | 23 +++++++++----------
 .../sendmail-administration.component.html    |  2 +-
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/modules/sendmail/sendmail_ajax_content.php b/modules/sendmail/sendmail_ajax_content.php
index db07fd31b86..d98163b8c7a 100755
--- a/modules/sendmail/sendmail_ajax_content.php
+++ b/modules/sendmail/sendmail_ajax_content.php
@@ -301,7 +301,7 @@ switch ($mode) {
                                     $userInfo = \User\models\UserModel::getByLogin(['login' => $_SESSION['user']['UserId'], 'select' => ['id', 'mail']]);
                                     
                                     $aSenderInfo = explode(",", $_REQUEST['sender_email']);
-                                    if (!empty($aSenderInfo[1])) {
+                                    if (!empty($aSenderInfo[1]) && !empty($aSenderInfo[0])) {
                                         $entityInfo = \Entity\models\EntityModel::getByEntityId(['entityId' => $aSenderInfo[0], 'select' => ['id']]);
                                     }
                                     $isSent = \Email\controllers\EmailController::createEmail([
diff --git a/src/app/email/controllers/EmailController.php b/src/app/email/controllers/EmailController.php
index 3731e83854a..567d55a21f8 100644
--- a/src/app/email/controllers/EmailController.php
+++ b/src/app/email/controllers/EmailController.php
@@ -247,6 +247,17 @@ class EmailController
 
         $phpmailer = new PHPMailer();
 
+        $emailFrom = empty($configuration['from']) ? $email['sender']['email'] : $configuration['from'];
+        if (empty($email['sender']['entityId'])) {
+            // Usefull for old sendmail server which doesn't support accent encoding
+            $setFrom = TextFormatModel::normalize(['string' => "{$user['firstname']} {$user['lastname']}"]);
+            $phpmailer->setFrom($emailFrom, ucwords($setFrom));
+        } else {
+            $entity = EntityModel::getById(['id' => $email['sender']['entityId'], 'select' => ['short_label']]);
+            // Usefull for old sendmail server which doesn't support accent encoding
+            $setFrom = TextFormatModel::normalize(['string' => $entity['short_label']]);
+            $phpmailer->setFrom($emailFrom, ucwords($setFrom));
+        }
         if (in_array($configuration['type'], ['smtp', 'mail'])) {
             if ($configuration['type'] == 'smtp') {
                 $phpmailer->isSMTP();
@@ -267,18 +278,6 @@ class EmailController
                     $phpmailer->Password = PasswordModel::decrypt(['cryptedPassword' => $configuration['password']]);
                 }
             }
-
-            $emailFrom = empty($configuration['from']) ? $email['sender']['email'] : $configuration['from'];
-            if (empty($email['sender']['entityId'])) {
-                // Usefull for old sendmail server which doesn't support accent encoding
-                $setFrom = TextFormatModel::normalize(['string' => "{$user['firstname']} {$user['lastname']}"]);
-                $phpmailer->setFrom($emailFrom, ucwords($setFrom));
-            } else {
-                $entity = EntityModel::getById(['id' => $email['sender']['entityId'], 'select' => ['short_label']]);
-                // Usefull for old sendmail server which doesn't support accent encoding
-                $setFrom = TextFormatModel::normalize(['string' => $entity['short_label']]);
-                $phpmailer->setFrom($emailFrom, ucwords($setFrom));
-            }
         } elseif ($configuration['type'] == 'sendmail') {
             $phpmailer->isSendmail();
         } elseif ($configuration['type'] == 'qmail') {
diff --git a/src/frontend/app/administration/sendmail/sendmail-administration.component.html b/src/frontend/app/administration/sendmail/sendmail-administration.component.html
index 62f4f84a4d6..bfabe46173d 100644
--- a/src/frontend/app/administration/sendmail/sendmail-administration.component.html
+++ b/src/frontend/app/administration/sendmail/sendmail-administration.component.html
@@ -103,7 +103,7 @@
             (opened)="onSubmit();initEmailSend()">
             <mat-nav-list disableRipple="true" style="display: flex;flex-direction: column;">
                 <h3 mat-subheader>{{lang.emailSendTest}}</h3>
-                <div class="form-group" [style.opacity]="['smtp', 'mail'].indexOf(sendmail.type) > -1 ? '1' : '0.5'">
+                <div class="form-group">
                     <div class="col-md-12">
                         <form #testSendmailForm="ngForm">
                             <mat-form-field>
-- 
GitLab