Mail merge - Accept false as folder to skip saving to mail folder

This commit is contained in:
nathangray 2018-10-01 11:15:31 -06:00
parent eb7ea6bfab
commit 20629e2a16

View File

@ -6863,8 +6863,8 @@ class Mail
* @param Storage\Merge Storage\Merge bo_merge object * @param Storage\Merge Storage\Merge bo_merge object
* @param string $document the full filename * @param string $document the full filename
* @param array $SendAndMergeTocontacts array of contact ids * @param array $SendAndMergeTocontacts array of contact ids
* @param string& $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if * @param string&|false $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
* folder is modified * folder is modified. Set to false to not keep the message.
* @param string& $importID ID for the imported message, used by attachments to identify them unambiguously * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
* @return mixed array of messages with success and failed messages or exception * @return mixed array of messages with success and failed messages or exception
*/ */
@ -6907,7 +6907,7 @@ class Mail
//_debug_array($Body); //_debug_array($Body);
$this->openConnection(); $this->openConnection();
if (empty($_folder)) if (empty($_folder) && $_folder !== FALSE)
{ {
$_folder = $this->getSentFolder(); $_folder = $this->getSentFolder();
} }
@ -6924,6 +6924,11 @@ class Mail
//error_log(__METHOD__.' ('.__LINE__.') '.' AltBody:'.$AltBody); //error_log(__METHOD__.' ('.__LINE__.') '.' AltBody:'.$AltBody);
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject->GetReplyTo())); //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject->GetReplyTo()));
if(!$Body && !$AltBody)
{
throw new Exception\NotFound('No mail body in template "'.$document.'"');
}
// Fetch ReplyTo - Address if existing to check if we are to replace it // Fetch ReplyTo - Address if existing to check if we are to replace it
$replyTo = $mailObject->getReplyTo(); $replyTo = $mailObject->getReplyTo();
if (isset($replyTo['replace@import.action'])) if (isset($replyTo['replace@import.action']))
@ -6949,7 +6954,7 @@ class Mail
$sendOK = $openComposeWindow = $openAsDraft = null; $sendOK = $openComposeWindow = $openAsDraft = null;
//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val); //error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/ if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
count($SendAndMergeTocontacts) > 1 && $val && (count($SendAndMergeTocontacts) > 1 || $_folder === FALSE) && $val &&
(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge (is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
{ {
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject)); //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
@ -7002,8 +7007,11 @@ class Mail
try { try {
$mailObject->send(); $mailObject->send();
$message_id = $mailObject->getHeader('Message-ID'); $message_id = $mailObject->getHeader('Message-ID');
$id = $this->appendMessage($_folder, $mailObject->getRaw(), ''); if($_folder)
$importID = $id->current(); {
$id = $this->appendMessage($_folder, $mailObject->getRaw(), '');
$importID = $id->current();
}
} }
catch(Exception $e) { catch(Exception $e) {
$sendOK = false; $sendOK = false;
@ -7048,7 +7056,10 @@ class Mail
if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e)); //error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
$_folder = $this->getDraftFolder(); if(!$_folder !== false)
{
$_folder = $this->getDraftFolder();
}
} }
if ($sendOK || $openAsDraft) if ($sendOK || $openAsDraft)
{ {
@ -7084,7 +7095,7 @@ class Mail
$openComposeWindow = true; $openComposeWindow = true;
} }
} }
else else if ($_folder !== FALSE)
{ {
$savefailed = true; $savefailed = true;
$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder); $alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);