Mail > Previews, as JSON - its subject, who it is * from, to and copied to, and its HTML - made on sample records that are thrown away * again (emailPreview(), functions/email_preview.php). */ require_once "../config.php"; require_once "../functions.php"; require_once "../includes/check_login.php"; enforceAdminPermission(); validateCSRFToken(); header('Content-Type: application/json'); header('Cache-Control: no-store'); $preview = emailPreview((string) ($_GET['email'] ?? '')); if ($preview === null) { http_response_code(404); exit(json_encode(['error' => 'There is no such email'])); } $email = $preview['email']; $person = function ($name, $address) { return trim($name) !== '' && strcasecmp(trim($name), trim($address)) !== 0 ? "$name <$address>" : $address; }; $others = []; foreach ($preview['emails'] as $other) { if ($email && $other['subject'] === $email['subject'] && strcasecmp($other['to'], $email['to']) !== 0) { $others[] = $person($other['to_name'], $other['to']); } } echo json_encode([ 'label' => $preview['label'], 'to_who' => $preview['to'], 'when' => $preview['when'], 'subject' => $email['subject'] ?? '', 'from' => $email ? ($email['from'] !== '' ? $person($email['from_name'], $email['from']) : 'No address yet - set it under From Addresses') : '', 'to' => $email ? $person($email['to_name'], $email['to']) : '', // Copied in on it - a ticket's CCs, on one email with its contact (emailQueue()'s together) 'cc' => $email ? array_map(function ($copied) use ($person) { return $person($copied['name'], $copied['email']); }, $email['cc'] ?? []) : [], 'also' => array_values(array_unique($others)), 'calendar' => !empty($email['cal_str']), 'html' => $email['html'] ?? '', // Its wording can be changed - one of the emails about a ticket to clients (functions/email_template.php) 'template' => isset(EMAIL_TEMPLATES[(string) ($_GET['email'] ?? '')]) && emailTemplateReady(), 'edited' => emailTemplateEdited((string) ($_GET['email'] ?? '')), 'error' => $email ? '' : ($preview['error'] !== '' ? 'It could not be made: ' . $preview['error'] : 'Nothing would be sent with the sample records.'), ]);