mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Keep a ticket's emails in one conversation: every client email about a ticket has the subject [TCK-123] and its subject and carries Message-ID, In-Reply-To and References, kept per ticket in ticket_mail_threads, and the email parser finds a reply's ticket by those headers first, then by the number in brackets with the prefix that ticket was given; one email goes to the contact with the watchers and colleagues copied in, switchable in Admin, Settings, Tickets; a client's reply by email, text or portal is passed on to the people following the ticket who weren't on it, by email only when it answers one of the ticket's emails; others in To and Cc on a client's or watcher's email become watchers, never your own domain or agents; the same email twice makes one ticket and a merged ticket's replies go to the ticket it went into; database 4.2.6; 26.12.3 changelog entries
This commit is contained in:
@@ -220,13 +220,20 @@ function sendQueueEmail(
|
||||
string $oauth_tenant_id,
|
||||
string $oauth_refresh_token,
|
||||
string $oauth_access_token,
|
||||
string $oauth_access_token_expires_at
|
||||
string $oauth_access_token_expires_at,
|
||||
string $cc_json = '',
|
||||
string $headers_json = ''
|
||||
) {
|
||||
// Development mode: to the test inbox instead, its real recipient at the front of the subject (functions/dev_mode.php)
|
||||
// The people copied in, and the headers that keep a ticket's conversation together (functions/mail_queue.php)
|
||||
$cc = mailQueueCc($cc_json);
|
||||
$headers = mailQueueHeaders($headers_json);
|
||||
|
||||
// Development mode: to the test inbox instead, its real recipients at the front of the subject (functions/dev_mode.php)
|
||||
if (devModeOn()) {
|
||||
$subject = '[DEV to ' . $to_email . '] ' . $subject;
|
||||
$subject = '[DEV to ' . $to_email . ($cc ? ', cc ' . implode(', ', array_column($cc, 'email')) : '') . '] ' . $subject;
|
||||
$to_email = devModeMailTo();
|
||||
$to_name = '';
|
||||
$cc = [];
|
||||
}
|
||||
|
||||
// Google and Microsoft each expose exactly one XOAUTH2 SMTP endpoint, so the
|
||||
@@ -305,10 +312,24 @@ function sendQueueEmail(
|
||||
// Recipients & content
|
||||
$mail->setFrom($from_email, $from_name);
|
||||
$mail->addAddress($to_email, $to_name);
|
||||
foreach ($cc as $person) {
|
||||
$mail->addCC($person['email'], $person['name']);
|
||||
}
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $html_body;
|
||||
|
||||
// Its own Message-ID, and the emails it answers - a mail program keeps a ticket's emails together by them, and a
|
||||
// reply names them back, so the email parser finds its ticket whatever its subject says. A big email sent through
|
||||
// Microsoft Graph as a draft goes without the last two (mailGraphSendLarge()) - its subject still finds the ticket
|
||||
foreach ($headers as $name => $value) {
|
||||
if ($name === 'Message-ID') {
|
||||
$mail->MessageID = $value;
|
||||
} else {
|
||||
$mail->addCustomHeader($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// A meeting invitation or cancellation goes in as its own text/calendar part
|
||||
// beside the HTML - the way calendar apps send them, and the only way Outlook
|
||||
// shows one as a meeting rather than a file. Only a meeting does: one with an
|
||||
@@ -404,8 +425,11 @@ if ($orphaned_emails > 0) {
|
||||
/** =======================================================================
|
||||
* SEND: status = 0 (Queued)
|
||||
* ======================================================================= */
|
||||
// The copied in and the headers - once the 4.2.6 update has made their columns
|
||||
$thread_columns = ticketMailThreadReady() ? 'email_cc, email_headers' : "'' AS email_cc, '' AS email_headers";
|
||||
|
||||
$sql_queue = mysqli_query($mysqli, "SELECT email_attachments, email_cal_str, email_content, email_from, email_from_name, email_id,
|
||||
email_recipient, email_recipient_name, email_subject FROM email_queue WHERE email_status = 0 AND email_queued_at <= NOW()");
|
||||
email_recipient, email_recipient_name, email_subject, $thread_columns FROM email_queue WHERE email_status = 0 AND email_queued_at <= NOW()");
|
||||
|
||||
if (mysqli_num_rows($sql_queue) > 0) {
|
||||
while ($rowq = mysqli_fetch_assoc($sql_queue)) {
|
||||
@@ -480,7 +504,9 @@ if (mysqli_num_rows($sql_queue) > 0) {
|
||||
(string)$config_mail_oauth_tenant_id,
|
||||
(string)$config_mail_oauth_refresh_token,
|
||||
(string)$config_mail_oauth_access_token,
|
||||
(string)$config_mail_oauth_access_token_expires_at
|
||||
(string)$config_mail_oauth_access_token_expires_at,
|
||||
(string)$rowq['email_cc'],
|
||||
(string)$rowq['email_headers']
|
||||
);
|
||||
|
||||
// Sent - one with a link or code that opens something is cleared now (mailQueueSentSql())
|
||||
@@ -511,7 +537,7 @@ if (mysqli_num_rows($sql_queue) > 0) {
|
||||
$sql_failed_queue = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT email_attachments, email_attempts, email_cal_str, email_content, email_from,
|
||||
email_from_name, email_id, email_recipient, email_recipient_name, email_subject FROM email_queue
|
||||
email_from_name, email_id, email_recipient, email_recipient_name, email_subject, $thread_columns FROM email_queue
|
||||
WHERE email_status = 2
|
||||
AND email_attempts < " . MAIL_QUEUE_TRIES . "
|
||||
AND email_failed_at <= NOW() - INTERVAL " . MAIL_QUEUE_RETRY_MINUTES . " MINUTE"
|
||||
@@ -567,7 +593,9 @@ if (mysqli_num_rows($sql_failed_queue) > 0) {
|
||||
(string)$config_mail_oauth_tenant_id,
|
||||
(string)$config_mail_oauth_refresh_token,
|
||||
(string)$config_mail_oauth_access_token,
|
||||
(string)$config_mail_oauth_access_token_expires_at
|
||||
(string)$config_mail_oauth_access_token_expires_at,
|
||||
(string)$rowf['email_cc'],
|
||||
(string)$rowf['email_headers']
|
||||
);
|
||||
|
||||
// Sent - one with a link or code that opens something is cleared now (mailQueueSentSql())
|
||||
|
||||
Reference in New Issue
Block a user