From ac06db6c5c6da80bb1c23355ccf745b99f75d6df Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 3 Jan 2025 16:07:03 +0100 Subject: [PATCH] * EPL Invoices: allow to select a mail template and directly mail invoice to buyer --- api/src/Country.php | 6 +++--- api/src/Mail.php | 8 +++++++- api/src/Mailer.php | 8 +++++++- api/src/Storage/Merge.php | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/api/src/Country.php b/api/src/Country.php index 9f9610d4dd..5fa2fe9188 100755 --- a/api/src/Country.php +++ b/api/src/Country.php @@ -751,9 +751,9 @@ class Country { if (!self::$countries_translated) self::_translate_countries(); - return self::$countries_translated[strtoupper($code)]; + return self::$countries_translated[strtoupper($code)] ?? null; } - return self::$country_array[strtoupper($code)]; + return self::$country_array[strtoupper($code)] ?? null; } /** @@ -856,4 +856,4 @@ class Country natcasesort(self::$countries_translated); } } -} +} \ No newline at end of file diff --git a/api/src/Mail.php b/api/src/Mail.php index 0b9ca0f3e8..480e18679c 100644 --- a/api/src/Mail.php +++ b/api/src/Mail.php @@ -7204,7 +7204,8 @@ class Mail $header = $mailObject->getHeader(Mailer::$type2header[$type]); if(is_array($header)) $header = implode(', ',$header); $mailObject->clearAddresses($type); - $merged = $bo_merge->merge_string($header,$val,$e,'text/plain',array(),self::$displayCharset); + $merged = empty($header) || strpos($header, '{{') === false ? $header : + $bo_merge->merge_string($header,$val,$e,'text/plain',array(),self::$displayCharset); //error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged); $mailObject->addAddress(trim($merged,'"'),'',$type); } @@ -7232,6 +7233,11 @@ class Mail { $_folder = $this->getDraftFolder(); } + // add attachments from app-specific merge-class + foreach($bo_merge->getAttachments($val) as $file) + { + $mailObject->addAttachment($file); + } } if ($sendOK || $openAsDraft) { diff --git a/api/src/Mailer.php b/api/src/Mailer.php index 4df11ab60c..593a96d622 100644 --- a/api/src/Mailer.php +++ b/api/src/Mailer.php @@ -328,7 +328,7 @@ class Mailer extends Horde_Mime_Mail * * "text/calendar; method=..." get automatic detected and added as highest priority alternative * - * @param string|resource $data Path to the attachment or open file-descriptor + * @param string|resource|array $data Path to the attachment or open file-descriptor or array with values for keys "data", "name" and "type" * @param string $name =null file name to use for the attachment * @param string $type =null content type of the file, incl. parameters eg. "text/plain; charset=utf-8" * @param string $old_type =null used to support phpMailer signature (deprecated) @@ -343,6 +343,12 @@ class Mailer extends Horde_Mime_Mail $type = $old_type; } + if (is_array($data)) + { + $name = $data['name'] ?? null; + $type = $data['type'] ?? null; + $data = $data['data'] ?? null; + } // pass file as resource to Horde_Mime_Part::setContent() if (is_resource($data)) { diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 0962784fc7..d499b29b51 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -3431,4 +3431,20 @@ abstract class Merge protected function show_replacements_hook(&$template_name, &$content, &$sel_options, &$readonlys) { } + + /** + * Allow to attach files to merged mails + * + * Called from mail.mail_compose.compose + * + * @param int|string $id + * @return array[] array of array with values for keys + * - "data": path or open file resource, + * - "name": filename to be used for attachment + * - "type": mime-type of attachment + */ + public function getAttachments($id) + { + return []; + } } \ No newline at end of file