Browse Source

Fixing platform sender see BT#8960

Julio Montoya 10 years ago
parent
commit
02481572e9
2 changed files with 50 additions and 48 deletions
  1. 6 3
      main/inc/lib/mail.lib.inc.php
  2. 44 45
      main/inc/lib/notification.lib.php

+ 6 - 3
main/inc/lib/mail.lib.inc.php

@@ -107,9 +107,12 @@ function api_mail_html(
     $mail->SMTPKeepAlive = true;
 
     // Default values:
-    $mail->From = api_get_setting('emailAdministrator');
-    $mail->Sender = api_get_setting('emailAdministrator');
-    $mail->FromName = api_get_setting('administratorName').' '.api_get_setting('administratorSurname');
+
+    $notification = new Notification();
+
+    $mail->From = $notification->getDefaultPlatformSenderEmail();
+    $mail->Sender = $notification->getDefaultPlatformSenderEmail();
+    $mail->FromName = $notification->getDefaultPlatformSenderName();
 
     // Error to admin.
     $mail->AddCustomHeader('Errors-To: '.$mail->From);

+ 44 - 45
main/inc/lib/notification.lib.php

@@ -72,6 +72,22 @@ class Notification extends Model
         }
     }
 
+    /**
+     * @return string
+     */
+    public function getDefaultPlatformSenderEmail()
+    {
+        return $this->admin_email;
+    }
+
+    /**
+     * @return string
+     */
+    public function getDefaultPlatformSenderName()
+    {
+        return $this->admin_name;
+    }
+
     /**
      *  Send the notifications
      *  @param int notification frequency
@@ -110,7 +126,7 @@ class Notification extends Model
 
     /**
      * Save message notification
-     * @param	array	$type message type
+     * @param	int	$type message type
      * NOTIFICATION_TYPE_MESSAGE,
      * NOTIFICATION_TYPE_INVITATION,
      * NOTIFICATION_TYPE_GROUP
@@ -168,46 +184,26 @@ class Notification extends Model
                     $user_setting = $extra_data[$setting_to_check];
                 }
 
-                $params = array();
+                $sendDate = null;
                 switch ($user_setting) {
-                    //No notifications
+                    // No notifications
                     case self::NOTIFY_MESSAGE_NO:
                     case self::NOTIFY_INVITATION_NO:
                     case self::NOTIFY_GROUP_NO:
                         break;
-                    //Send notification right now!
+                    // Send notification right now!
                     case self::NOTIFY_MESSAGE_AT_ONCE:
                     case self::NOTIFY_INVITATION_AT_ONCE:
                     case self::NOTIFY_GROUP_AT_ONCE:
-                        $mail = api_get_setting('noreply_email_address');
-                        if ($user_setting == self::NOTIFY_INVITATION_AT_ONCE) {
-                            $sender_info['complete_name'] = $this->admin_name;
-                            $extra_headers = array();
-                            $extra_headers['reply_to']['name'] = $this->admin_name;
-                            if (!empty($mail)) {
-                                $sender_info['email'] = $mail;
-                                $extra_headers['reply_to']['mail'] = $mail;
+                        $extra_headers = array();
+                        $sender_info['complete_name'] = $this->admin_name;
+                        $sender_info['email'] = $this->admin_email;
+                        $extra_headers['reply_to']['name'] = $user_info['complete_name'];
+                        $extra_headers['reply_to']['mail'] = $user_info['email'];
 
-                            } else {
-                                $sender_info['email'] = $this->admin_email;
-                                $extra_headers['reply_to']['mail'] = $this->admin_email;
-                            }
-                        }
-                        if (!empty($user_info['mail']) || !empty($mail)) {
-                            $name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
-                            if (!empty($sender_info['complete_name']) && !empty($sender_info['email'])) {
-                                if ($user_setting != self::NOTIFY_INVITATION_AT_ONCE) {
-                                    $extra_headers = array();
-                                    $extra_headers['reply_to']['mail'] = $sender_info['email'];
-                                    $extra_headers['reply_to']['name'] = $sender_info['complete_name'];
-                                }
-                            } else {
-                                $extra_headers = array();
-                                $sender_info['complete_name'] = $this->admin_name;
-                                $sender_info['email'] = $this->admin_email;
-                            }
+                        if (!empty($user_info['email'])) {
                             api_mail_html(
-                                $name,
+                                $user_info['complete_name'],
                                 $user_info['mail'],
                                 Security::filter_terms($title),
                                 Security::filter_terms($content),
@@ -215,27 +211,29 @@ class Notification extends Model
                                 $sender_info['email'],
                                 $extra_headers
                             );
-
                         }
-                        $params['sent_at'] = api_get_utc_datetime();
-                        // Saving the notification to be sent some day.
-                    default:
-                        $params['dest_user_id'] = $user_id;
-                        $params['dest_mail'] = $user_info['mail'];
-                        $params['title'] = $title;
-                        $params['content'] = cut($content, $this->max_content_length);
-                        $params['send_freq'] = $user_setting;
-                        $this->save($params);
-                        break;
+                        $sendDate = api_get_utc_datetime();
                 }
+
+                // Saving the notification to be sent some day.
+                $params = array();
+                $params['sent_at'] = $sendDate;
+                $params['dest_user_id'] = $user_id;
+                $params['dest_mail'] = $user_info['email'];
+                $params['title'] = $title;
+                $params['content'] = cut($content, $this->max_content_length);
+                $params['send_freq'] = $user_setting;
+                $this->save($params);
             }
         }
     }
 
     /**
-     * Formats the content in order to add the welcome message, the notification preference, etc
-     * @param   string 	the content
-     * @param   array	result of api_get_user_info() or GroupPortalManager:get_group_data()
+     * Formats the content in order to add the welcome message,
+     * the notification preference, etc
+     * @param   string 	$content
+     * @param   array	$sender_info result of api_get_user_info() or
+     * GroupPortalManager:get_group_data()
      * @return string
      * */
     public function format_content($content, $sender_info)
@@ -312,6 +310,7 @@ class Notification extends Model
                 get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'),
                 Display::url($preference_url, $preference_url)
             ).'</i>';
+
         return $content;
     }
 }