Skip to content

Commit

Permalink
Fix attached files in mail - Refs # 8154
Browse files Browse the repository at this point in the history
  • Loading branch information
jloguercio committed Mar 29, 2016
1 parent 94b0148 commit 4292a69
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
19 changes: 17 additions & 2 deletions main/inc/lib/api.lib.php
Expand Up @@ -7846,8 +7846,8 @@ function api_create_protected_dir($name, $parentDirectory)
* @param string sender e-mail
* @param array extra headers in form $headers = array($name => $value) to allow parsing
* @param array data file (path and filename)
* @param array data to attach a file (optional)
* @param bool True for attaching a embedded file inside content html (optional)
* @param array Additional parameters
* @return returns true if mail was sent
* @see class.phpmailer.php
*/
Expand Down Expand Up @@ -7968,7 +7968,22 @@ function api_mail_html(

// Attachment ...
if (!empty($data_file)) {
$mail->AddAttachment($data_file['path'], $data_file['filename']);
$o = 0;
foreach ($data_file as $file_attach) {
if (!empty($file_attach['path']) && !empty($file_attach['filename'])) {
$mail->AddAttachment($file_attach['path'], $file_attach['filename']);
}
$o++;
}
} elseif (is_array($_FILES)) {
$data_file = $_FILES;
$o = 0;
foreach ($data_file as $file_attach) {
if (!empty($file_attach['tmp_name']) && !empty($file_attach['name'])) {
$mail->AddAttachment($file_attach['tmp_name'], $file_attach['name']);
}
$o++;
}
}

// Only valid addresses are accepted.
Expand Down
9 changes: 8 additions & 1 deletion main/inc/lib/message.lib.php
Expand Up @@ -362,6 +362,12 @@ public static function send_message(
// Load user settings.
$notification = new Notification();
$sender_info = api_get_user_info($user_sender_id);

// add file attachment additional attributes
foreach ($file_attachments as $file_attach) {
$file_attachments['path'] = $file_attach['tmp_name'];
$file_attachments['filename'] = $file_attach['name'];
}

if (empty($group_id)) {
$type = Notification::NOTIFICATION_TYPE_MESSAGE;
Expand All @@ -373,7 +379,8 @@ public static function send_message(
array($receiver_user_id),
$subject,
$content,
$sender_info
$sender_info,
$file_attachments
);
} else {
$usergroup = new UserGroup();
Expand Down
6 changes: 4 additions & 2 deletions main/inc/lib/notification.lib.php
Expand Up @@ -227,7 +227,8 @@ public function save_notification(
$user_list,
$title,
$content,
$senderInfo = array()
$senderInfo = array(),
$attachments = array()
) {
$this->type = intval($type);
$content = $this->formatContent($content, $senderInfo);
Expand Down Expand Up @@ -307,7 +308,8 @@ public function save_notification(
Security::filter_terms($content),
$this->adminName,
$this->adminEmail,
$extraHeaders
$extraHeaders,
$attachments
);
}
$sendDate = api_get_utc_datetime();
Expand Down

0 comments on commit 4292a69

Please sign in to comment.