fix: ora per l'invio delle mail considera le eventuali persone in copia nella comunicazione selezionata

This commit is contained in:
Gabriele Cimaschi
2026-07-09 13:02:04 +02:00
parent a89605b888
commit 725bdaeae4
3 changed files with 53 additions and 10 deletions
+3 -2
View File
@@ -324,9 +324,10 @@ const EmailCompose = (() => {
document.body.appendChild(overlay); document.body.appendChild(overlay);
// Init tag inputs // Init tag inputs
const initialTo = options.customerEmail ? [options.customerEmail] : []; const initialTo = options.initialTo || (options.customerEmail ? [options.customerEmail] : []);
const initialCc = options.initialCc || [];
const toTagsCtrl = makeTagInput('ec-to-container', initialTo); const toTagsCtrl = makeTagInput('ec-to-container', initialTo);
const ccTagsCtrl = makeTagInput('ec-cc-container', []); const ccTagsCtrl = makeTagInput('ec-cc-container', initialCc);
// Subject // Subject
const subjectEl = document.getElementById('ec-subject'); const subjectEl = document.getElementById('ec-subject');
+34 -6
View File
@@ -756,18 +756,46 @@ const TicketDetailView = {
<p><br></p> <p><br></p>
`; `;
// Extract sender email if possible for CC/To // Helper to extract email addresses from headers
let customerEmail = ticket.customer_email || ''; const parseEmails = (str) => {
const matchEmail = (article.a_from || '').match(/<([^>]+)>/) || (article.a_from || '').match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/); if (!str) return [];
if (matchEmail) { return (str.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [])
customerEmail = matchEmail[1]; .map(email => email.toLowerCase().trim());
};
const fromEmails = parseEmails(article.a_from);
const toEmails = parseEmails(article.a_to);
const ccEmails = parseEmails(article.a_cc);
// Exclude list (helpdesk and active agent)
const config = App.lookups.config || {};
const helpdeskEmail = (config.helpdeskEmail || 'helpdesk@pharmaidea.com').toLowerCase();
const agentEmail = (config.agentEmail || '').toLowerCase();
const excludeEmails = [helpdeskEmail, agentEmail].filter(Boolean);
const initialToSet = new Set();
fromEmails.forEach(e => {
if (!excludeEmails.includes(e) && !e.includes('helpdesk')) {
initialToSet.add(e);
} }
});
if (initialToSet.size === 0 && ticket.customer_email) {
initialToSet.add(ticket.customer_email.toLowerCase());
}
const initialCcSet = new Set();
[...toEmails, ...ccEmails].forEach(e => {
if (!excludeEmails.includes(e) && !e.includes('helpdesk') && !initialToSet.has(e)) {
initialCcSet.add(e);
}
});
EmailCompose.open({ EmailCompose.open({
ticketId: ticket.id, ticketId: ticket.id,
ticketTn: ticket.tn, ticketTn: ticket.tn,
ticketTitle: ticket.title, ticketTitle: ticket.title,
customerEmail: customerEmail, initialTo: Array.from(initialToSet),
initialCc: Array.from(initialCcSet),
initialBodyHtml: initialBodyHtml, initialBodyHtml: initialBodyHtml,
}); });
} else { } else {
+16 -2
View File
@@ -132,12 +132,26 @@ router.get('/users', async (req, res) => {
}); });
// GET /api/config — Application config // GET /api/config — Application config
router.get('/config', (req, res) => { router.get('/config', async (req, res) => {
const agentId = parseInt(req.headers['x-agent-id'], 10) || 1;
let agentEmail = '';
try {
const prefRes = await pool.query(
`SELECT preferences_value FROM user_preferences WHERE user_id = $1 AND preferences_key = 'UserEmail'`,
[agentId]
);
if (prefRes.rows.length > 0) {
agentEmail = prefRes.rows[0].preferences_value || '';
}
} catch (_) {}
res.json({ res.json({
defaultAgentLogin: process.env.OTRS_API_USER || '', defaultAgentLogin: process.env.OTRS_API_USER || '',
dailyTargetTime: parseInt(process.env.DAILY_TARGET_TIME, 10) || 480, dailyTargetTime: parseInt(process.env.DAILY_TARGET_TIME, 10) || 480,
phraseThreshold: parseInt(process.env.PHRASE_THRESHOLD, 10) || 70, phraseThreshold: parseInt(process.env.PHRASE_THRESHOLD, 10) || 70,
autoTimeMinHour: process.env.AUTO_TIME_MIN_HOUR || '18:00' autoTimeMinHour: process.env.AUTO_TIME_MIN_HOUR || '18:00',
helpdeskEmail: process.env.OTRS_MAIL_BCC || '',
agentEmail: agentEmail
}); });
}); });