chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.type === 'phishing-detected') { const emails = message.emails; let notificationTitle = 'You are safe!'; let notificationMessage = 'No phishing emails detected.'; const phishingEmails = emails.filter(email => email.is_phishing); if (phishingEmails.length > 0) { notificationTitle = 'You are in danger!'; notificationMessage = `Email from ${phishingEmails[0].from} titled "${phishingEmails[0].subject}" has been identified as phishing.`; chrome.windows.create({ url: 'notification.html', type: 'popup', width: 300, height: 200 }, function(window) { chrome.storage.local.set({ notificationTitle: notificationTitle, notificationMessage: notificationMessage, emailId: phishingEmails[0].id }); }); } else { chrome.windows.create({ url: 'notification.html', type: 'popup', width: 300, height: 200 }, function(window) { chrome.storage.local.set({ notificationTitle: notificationTitle, notificationMessage: notificationMessage, emailId: null }); }); } } else if (message.type === 'mark-safe') { fetch(`http://localhost:5000/mark_safe/${message.emailId}`, { method: 'POST' }).then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); } else if (message.type === 'move-trash') { fetch(`http://localhost:5000/move_trash/${message.emailId}`, { method: 'POST' }).then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); } });