new optional parameter $attachments for toIndividual()

This commit is contained in:
Uwe Steinmann 2019-07-01 09:56:19 +02:00
parent 1a5a1f3ecb
commit 3d9e752694

View File

@ -76,9 +76,10 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify {
* @param string $message key of string containing the body of the mail
* @param array $params list of parameters which replaces placeholder in
* the subject and body
* @param array $attachments list of attachments
* @return false or -1 in case of error, otherwise true
*/
function toIndividual($sender, $recipient, $subject, $message, $params=array()) { /* {{{ */
function toIndividual($sender, $recipient, $subject, $message, $params=array(), $attachments=array()) { /* {{{ */
if(is_object($recipient) && !strcasecmp(get_class($recipient), $this->_dms->getClassname('user')) && !$recipient->isDisabled() && $recipient->getEmail()!="") {
$to = $recipient->getEmail();
$lang = $recipient->getLanguage();
@ -109,6 +110,32 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify {
$message = getMLText("email_header", $params, "", $lang)."\r\n\r\n".getMLText($message, $params, "", $lang);
$message .= "\r\n\r\n".getMLText("email_footer", $params, "", $lang);
$mime = new Mail_mime(array('eol' => "\n"));
$mime->setTXTBody($message);
// $mime->setHTMLBody($bodyhtml);
if($attachments) {
foreach($attachments as $attachment) {
if(!$mime->addAttachment(
$attachment['file'],
$attachment['mimetype'],
isset($attachment['name']) ? $attachment['name'] : '',
isset($attachment['isfile']) ? $attachment['isfile'] : true
)) {
return false;
}
}
}
$message = $mime->get(array(
'text_encoding'=>'8bit',
'html_encoding'=>'8bit',
'head_charset'=>'utf-8',
'text_charset'=>'utf-8',
'html_charset'=>'utf-8'
));
$headers = array ();
$headers['From'] = $from;
if($returnpath)
@ -119,7 +146,9 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify {
$headers['Subject'] = substr($encoded_subject, strlen('Subject: '));
$headers['Date'] = date('r', time());
$headers['MIME-Version'] = "1.0";
$headers['Content-type'] = "text/plain; charset=utf-8";
// $headers['Content-type'] = "text/plain; charset=utf-8";
$hdrs = $mime->headers($headers);
$mail_params = array();
if($this->smtp_server) {
@ -146,13 +175,13 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify {
if (isset($GLOBALS['SEEDDMS_HOOKS']['mailqueue'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['mailqueue'] as $queueService) {
if(method_exists($queueService, 'queueMailJob')) {
$ret = $queueService->queueMailJob($mail_params, $to, $headers, getMLText($subject, $params, "", $lang), $message);
$ret = $queueService->queueMailJob($mail_params, $to, $hdrs, getMLText($subject, $params, "", $lang), $message);
if($ret !== null)
return $ret;
}
}
}
$result = $mail->send($to, $headers, $message);
$result = $mail->send($to, $hdrs, $message);
if (PEAR::isError($result)) {
return false;
} else {