fix: ora per l'invio delle mail considera le eventuali persone in copia nella comunicazione selezionata
This commit is contained in:
@@ -756,18 +756,46 @@ const TicketDetailView = {
|
||||
<p><br></p>
|
||||
`;
|
||||
|
||||
// Extract sender email if possible for CC/To
|
||||
let customerEmail = ticket.customer_email || '';
|
||||
const matchEmail = (article.a_from || '').match(/<([^>]+)>/) || (article.a_from || '').match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/);
|
||||
if (matchEmail) {
|
||||
customerEmail = matchEmail[1];
|
||||
// Helper to extract email addresses from headers
|
||||
const parseEmails = (str) => {
|
||||
if (!str) return [];
|
||||
return (str.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [])
|
||||
.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({
|
||||
ticketId: ticket.id,
|
||||
ticketTn: ticket.tn,
|
||||
ticketTitle: ticket.title,
|
||||
customerEmail: customerEmail,
|
||||
initialTo: Array.from(initialToSet),
|
||||
initialCc: Array.from(initialCcSet),
|
||||
initialBodyHtml: initialBodyHtml,
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user