fix: visualizzazione delle immagini nelle note e mail inviate. fix: corretto veramente problema del fusorario delle mail. feat: tooltip fullscreen per le immagini.
This commit is contained in:
+27
-9
@@ -6,6 +6,13 @@ const pool = require('../db');
|
||||
const { db } = require('../activityDb');
|
||||
const { sendMail } = require('../utils/mailer');
|
||||
|
||||
// Helper to get local timestamp in YYYY-MM-DD HH:mm:ss format
|
||||
function getLocalTimestamp() {
|
||||
const d = new Date();
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
||||
}
|
||||
|
||||
// ─── SIGNATURES ────────────────────────────────────────────────────────────────
|
||||
|
||||
// GET /api/email/signatures — list signatures for a given agent
|
||||
@@ -233,7 +240,15 @@ router.post('/send', async (req, res) => {
|
||||
let processedBodyHtml = bodyHtml;
|
||||
let cidCounter = 1;
|
||||
processedBodyHtml = bodyHtml.replace(/src="data:([^;]+);base64,([^"]+)"/g, (match, contentType, base64Data) => {
|
||||
const cid = `inline-image-${Date.now()}-${cidCounter++}`;
|
||||
let ext = 'png'; // default fallback
|
||||
if (contentType) {
|
||||
const parts = contentType.split('/');
|
||||
if (parts.length === 2) {
|
||||
ext = parts[1];
|
||||
if (ext === 'jpeg') ext = 'jpg';
|
||||
}
|
||||
}
|
||||
const cid = `inline-image-${Date.now()}-${cidCounter++}.${ext}`;
|
||||
extractedInlineImages.push({
|
||||
cid,
|
||||
content: base64Data,
|
||||
@@ -273,15 +288,17 @@ router.post('/send', async (req, res) => {
|
||||
|
||||
const toList = to.join(', ');
|
||||
|
||||
const localNow = getLocalTimestamp();
|
||||
|
||||
// Insert article via DB metadata (Email channel=1, Visible to customer=1)
|
||||
const artInsert = await pool.query(`
|
||||
INSERT INTO article (
|
||||
ticket_id, article_sender_type_id, communication_channel_id,
|
||||
is_visible_for_customer, create_time, create_by, change_time, change_by
|
||||
) VALUES (
|
||||
$1, 1, 1, 1, NOW(), $2, NOW(), $2
|
||||
$1, 1, 1, 1, $3, $2, $3, $2
|
||||
) RETURNING id`,
|
||||
[ticketId, agentId || 1]
|
||||
[ticketId, agentId || 1, localNow]
|
||||
);
|
||||
|
||||
const articleId = artInsert.rows[0]?.id;
|
||||
@@ -290,8 +307,8 @@ router.post('/send', async (req, res) => {
|
||||
// Write standard HTML MIME data
|
||||
await pool.query(`
|
||||
INSERT INTO article_data_mime (article_id, a_from, a_to, a_cc, a_bcc, a_subject, a_body, a_content_type, a_message_id, incoming_time, create_time, create_by, change_time, change_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, 'text/html; charset=utf-8', $8, $9, NOW(), $10, NOW(), $10)`,
|
||||
[articleId, aFrom, toList, cc.join(', '), bccList.join(', '), subject, processedBodyHtml, messageId, now, agentId || 1]
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, 'text/html; charset=utf-8', $8, $9, $11, $10, $11, $10)`,
|
||||
[articleId, aFrom, toList, cc.join(', '), bccList.join(', '), subject, processedBodyHtml, messageId, now, agentId || 1, localNow]
|
||||
);
|
||||
|
||||
// Helper to strip HTML tags
|
||||
@@ -314,8 +331,8 @@ router.post('/send', async (req, res) => {
|
||||
// 1. Write standard plain text version for client fallbacks
|
||||
await pool.query(`
|
||||
INSERT INTO article_data_mime_plain (article_id, body, create_time, create_by, change_time, change_by)
|
||||
VALUES ($1, $2, NOW(), $3, NOW(), $3)`,
|
||||
[articleId, plainBody, agentId || 1]
|
||||
VALUES ($1, $2, $3, $4, $3, $4)`,
|
||||
[articleId, plainBody, localNow, agentId || 1]
|
||||
);
|
||||
|
||||
// 2. Populate OTRS fulltext search index (article_search_index)
|
||||
@@ -372,7 +389,7 @@ router.post('/send', async (req, res) => {
|
||||
article_id, filename, content_size, content_type,
|
||||
content_id, disposition, content,
|
||||
create_time, create_by, change_time, change_by
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, NOW(), $8, NOW(), $8)`,
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $9, $8, $9, $8)`,
|
||||
[
|
||||
articleId,
|
||||
att.filename,
|
||||
@@ -381,7 +398,8 @@ router.post('/send', async (req, res) => {
|
||||
att.contentId,
|
||||
att.disposition,
|
||||
att.content, // base64 text directly
|
||||
agentId || 1
|
||||
agentId || 1,
|
||||
localNow
|
||||
]
|
||||
);
|
||||
} catch (attErr) {
|
||||
|
||||
Reference in New Issue
Block a user