Created
March 4, 2024 15:19
-
-
Save LaurentiuGabriel/eb2be57043defb60beadf18735786a25 to your computer and use it in GitHub Desktop.
Email Phishing Detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Office.onReady((info) => { | |
if (info.host === Office.HostType.Outlook) { | |
document.getElementById("checkEmailButton").onclick = () => analyzeEmail(); | |
} | |
}); | |
function analyzeEmail() { | |
Office.context.mailbox.item.body.getAsync("text", function (result) { | |
if (result.status === Office.AsyncResultStatus.Succeeded) { | |
checkEmailWithGPT4(result.value); | |
} else { | |
displayResult("Error: Unable to access email content."); | |
} | |
}); | |
} | |
async function checkEmailWithGPT4(emailContent) { | |
const response = await fetch('https://api.openai.com/v1/engines/gpt-4/completions', { | |
method: 'POST', | |
headers: { | |
'Authorization': `Bearer YOUR_OPENAI_API_KEY`, | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
prompt: `Is the following email content potentially phishing? \n\n${emailContent}`, | |
max_tokens: 100 | |
}) | |
}); | |
if (!response.ok) { | |
displayResult("Error: Problem analyzing email."); | |
return; | |
} | |
const data = await response.json(); | |
displayResult(data.choices[0].text); | |
} | |
function displayResult(result) { | |
const resultElement = document.getElementById('analysisResult'); | |
if (result.trim().toLowerCase().includes("phishing")) { | |
resultElement.innerText = "Warning: This email may be a phishing attempt."; | |
resultElement.style.color = "red"; | |
} else { | |
resultElement.innerText = "This email appears to be safe."; | |
resultElement.style.color = "green"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment