2024-06-09 17:14:27 +02:00
|
|
|
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.suspicious);
|
|
|
|
|
|
|
|
if (phishingEmails.length > 0) {
|
|
|
|
notificationTitle = "You are in danger!";
|
|
|
|
notificationMessage = `Detected ${phishingEmails.length} suspicious emails.`;
|
|
|
|
|
|
|
|
chrome.windows.create(
|
|
|
|
{
|
|
|
|
url: "notification.html",
|
|
|
|
type: "popup",
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
},
|
|
|
|
function (window) {
|
|
|
|
chrome.storage.local.set({
|
|
|
|
notificationTitle: notificationTitle,
|
|
|
|
notificationMessage: notificationMessage,
|
|
|
|
phishingEmails: phishingEmails,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
chrome.windows.create(
|
|
|
|
{
|
|
|
|
url: "notification.html",
|
|
|
|
type: "popup",
|
|
|
|
width: 300,
|
|
|
|
height: 200,
|
|
|
|
},
|
|
|
|
function (window) {
|
|
|
|
chrome.storage.local.set({
|
|
|
|
notificationTitle: notificationTitle,
|
|
|
|
notificationMessage: notificationMessage,
|
|
|
|
phishingEmails: [],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (message.type === "mark-safe") {
|
2024-06-10 19:36:35 +02:00
|
|
|
chrome.storage.local.get(
|
|
|
|
["email", "password", "emailService"],
|
|
|
|
function (result) {
|
|
|
|
const emailService = result.emailService;
|
|
|
|
const emailId = message.emailId;
|
|
|
|
fetch(`http://localhost:5000/mark_safe/${emailId}`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
username: result.email,
|
|
|
|
email: emailService,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => console.log(data))
|
|
|
|
.catch((error) => console.error("Error:", error));
|
|
|
|
}
|
|
|
|
);
|
2024-06-09 17:14:27 +02:00
|
|
|
} else if (message.type === "move-trash") {
|
|
|
|
chrome.storage.local.get(
|
|
|
|
["email", "password", "emailService"],
|
|
|
|
function (result) {
|
|
|
|
const emailService = result.emailService;
|
|
|
|
const emailId = message.emailId;
|
|
|
|
if (emailService === "outlook") {
|
|
|
|
fetch(`http://localhost:5000/delete-email`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
email_id: emailId,
|
|
|
|
username: result.email,
|
|
|
|
password: result.password,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => console.log(data))
|
|
|
|
.catch((error) => console.error("Error:", error));
|
|
|
|
} else {
|
|
|
|
fetch(`http://localhost:5000/move_trash/${emailId}`, {
|
|
|
|
method: "POST",
|
2024-06-10 19:36:35 +02:00
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
2024-06-09 17:14:27 +02:00
|
|
|
})
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => console.log(data))
|
|
|
|
.catch((error) => console.error("Error:", error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-05-31 22:49:37 +02:00
|
|
|
});
|