Created
November 9, 2023 21:39
-
-
Save stephanhuewe/311e14197df39d4935140c3b1c547ad5 to your computer and use it in GitHub Desktop.
A small javascript file to extract from, to and envelope-to from a mail header. Used at www.spambarrier.de
This file contains 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
<script type="text/javascript"> | |
function validate() | |
{ | |
const regexpEnvelope = /envelope-from.*/g; | |
const regexpFrom = /From:.*>/g; | |
const regexpTo = /\nTo: .*/g; | |
var headerText = document.getElementById("txt").value; | |
const matchesEnvelope = headerText.matchAll(regexpEnvelope); | |
const matchesFrom = headerText.matchAll(regexpFrom); | |
const matchesTo = headerText.matchAll(regexpTo); | |
var from = ""; | |
var to = ""; | |
var envelope = ""; | |
var my_html = ""; | |
for (const match of matchesEnvelope) | |
{ | |
var text = match.toString().replace('(envelope-from ','').replace(">)",""); | |
var lookingFor = '<'; | |
var replaced = text.substring(text.indexOf(lookingFor) + lookingFor.length); | |
my_html = my_html + "Envelope: " + replaced; | |
envelope = replaced; | |
} | |
my_html = my_html + "<br/>"; | |
for (const match of matchesFrom) | |
{ | |
var text = match.toString().replace('From: ','').replace(">",""); | |
var lookingFor = '<'; | |
var replaced = text.substring(text.indexOf(lookingFor) + lookingFor.length); | |
my_html = my_html + "From: " + replaced; | |
from = replaced; | |
} | |
my_html = my_html + "<br/>"; | |
for (const match of matchesTo) | |
{ | |
if (match.toString().includes("quarantine") == false) | |
{ | |
var text = match.toString().replace('To: ','').replace(">",""); | |
var lookingFor = '<'; | |
var replaced = text.substring(text.indexOf(lookingFor) + lookingFor.length); | |
my_html = my_html + "To: " + replaced + "<br/>" ; | |
to = replaced; | |
} | |
} | |
my_html = my_html + "<br/>"; | |
my_html = my_html + "Bitte legen Sie folgende Whitelist-Einträge an:<br/>"; | |
my_html = my_html + "Von: " + from + " - An: " + to + "<br/>"; | |
my_html = my_html + "Von: " + envelope + " - An: " + to + "<br/>"; | |
var container = document.getElementById('container'); | |
container.innerHTML = my_html; | |
return false; | |
} | |
function printDiv(divName) { | |
var printContents = document.getElementById(divName).innerHTML; | |
var originalContents = document.body.innerHTML; | |
document.body.innerHTML = printContents; | |
window.print(); | |
document.body.innerHTML = originalContents; | |
} | |
</script> | |
<form action="" method="post" onsubmit="return validate()"> | |
<textarea id="txt" name="txt" cols="100" rows="10">Bitte Header hier einfügen</textarea><br> | |
<input type="submit" value="Absender ermitteln"> | |
</form> | |
<div id="container"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment