Skip to content

Commit

Permalink
Use hooks to declare another type of CMailFile.
Browse files Browse the repository at this point in the history
  • Loading branch information
msoula committed Sep 4, 2024
1 parent e5f4486 commit 5d475b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 17 additions & 2 deletions htdocs/core/actions_massactions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,15 @@

// Send mail (substitutionarray must be done just before this)
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, '', $upload_dir_tmp);

$classname = 'CMailFile';
$reshook = $hookmanager->executeHooks('doCreateCMailFileInstance', $parameters, $object, $action);
if (!empty($reshook)) {
require_once $hookmanager->resArray['script_path'];
$classname = $hookmanager->resArray['classname'];
}
$mailfile = new $classname($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, '', $upload_dir_tmp);

if ($mailfile->error) {
$resaction .= '<div class="error">'.$mailfile->error.'</div>';
} else {
Expand Down Expand Up @@ -1643,7 +1651,14 @@
$trackid = 'leav'.$objecttmp->id;

require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);

$classname = 'CMailFile';
$reshook = $hookmanager->executeHooks('doCreateCMailFileInstance', $parameters, $object, $action);
if (!empty($reshook)) {
require_once $hookmanager->resArray['script_path'];
$classname = $hookmanager->resArray['classname'];
}
$mail = new $classname($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);

// Sending email
$result = $mail->sendfile();
Expand Down
9 changes: 8 additions & 1 deletion htdocs/core/actions_sendmails.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,14 @@
if (empty($sendcontext)) {
$sendcontext = 'standard';
}
$mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, '', $upload_dir_tmp);

$classname = 'CMailFile';
$reshook = $hookmanager->executeHooks('doCreateCMailFileInstance', $parameters, $object, $action);
if (!empty($reshook)) {
require_once $hookmanager->resArray['script_path'];
$classname = $hookmanager->resArray['classname'];
}
$mailfile = new $classname($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, '', $upload_dir_tmp);

if (!empty($mailfile->error) || !empty($mailfile->errors)) {
setEventMessages($mailfile->error, $mailfile->errors, 'errors');
Expand Down

0 comments on commit 5d475b4

Please sign in to comment.