Replies: 5 comments 6 replies
-
Please change the tag to |
Beta Was this translation helpful? Give feedback.
-
Hi. I will convert this to discuss because there are few points we need to discuss |
Beta Was this translation helpful? Give feedback.
-
So, may I ask what is the extension and what are you trying to achieve with it? Maybe it's something worth implementing directly? |
Beta Was this translation helpful? Give feedback.
-
The first partconst SpamRuleFieldType = {
FROM: "0",
TO: "1",
CC: "2",
BCC: "3"
}
const MailReportType = {
PHISHING: "0",
SPAM: "1"
}
const SpamRuleType = {
WHITELIST: "1",
BLACKLIST: "2",
DISCARD: "3"
}
// must vet list of emails in the spam folder first
// move any false negatives over to the inbox
await(async () => {
const currentList = tutao.currentView.mailList.mailView.mailList.list;
const showingTrashOrSpamFolder = () => {
return tutao.currentView.mailList.mailView.selectedFolder.folderType === "5";
}
const recursivelyLoadSpamEntities = async () => {
await currentList._loadMore()
currentList._domList.style.height = currentList._calculateListHeight();
if (currentList._loadedCompletely) {
console.log("Done loading all spam!");
return;
} else {
recursivelyLoadSpamEntities();
}
}
const getSubdomains = (subdomain, extractedSubdomains = []) => {
let domainSegmentsArray = [];
do {
extractedSubdomains.push(subdomain);
domainSegmentsArray = subdomain.split('.');
domainSegmentsArray.shift();
subdomain = domainSegmentsArray.join('.');
} while (domainSegmentsArray.length >= 2)
return extractedSubdomains;
}
if (showingTrashOrSpamFolder()) {
// use a set to store emails and domains to report and add to spam filter, this ensures we have unique values.
let emailsNDomainsList = new Set();
// load all spam emails
await recursivelyLoadSpamEntities();
// get loaded spam emails
const loadedSpamEntities = currentList.getLoadedEntities();
// report phishing to tutanota
tutao.locator.mailModel.reportMails(MailReportType.PHISHING, loadedSpamEntities);
// parse emails to domains
loadedSpamEntities.forEach(entity => {
// add From email
emailsNDomainsList.add(entity.sender.address);
// add From domain
emailsNDomainsList.add(entity.sender.address.split('@')[1]);
// check for an alt sender email
const differentEnvelopeSenderEmail = entity.differentEnvelopeSender;
if (differentEnvelopeSenderEmail) {
// add alt email to the set
emailsNDomainsList.add(differentEnvelopeSenderEmail);
// check if the alt domain is a subdomain, usually mail.shittydomain.poop
const segments = differentEnvelopeSenderEmail.split('@')[1].split('.');
for (let i = 0; i < segments.length - 1; i++) {
emailsNDomainsList.add(segments.slice(i).join('.'))
}
}
})
// get existing spam rules
tutao.locator.customerFacade.loadCustomerServerProperties().then(csp => {
csp.emailSenderList.forEach(r => {
if (r.type === SpamRuleType.BLACKLIST || r.type === SpamRuleType.DISCARD) {
// filter out emails and domains already added to spam rule
// could use .has to check first, but using delete is safe
if (emailsNDomainsList.has(r.value)) console.log(r.value)
emailsNDomainsList.delete(r.value);
}
})
console.log([...emailsNDomainsList]);
})
}
})(); The second part// Must vet the list generated above in case of false negatives. Wo you don't block domains such as gmail, yahoo, amazonses or any other trusted domains that spammers abuse.
let manuallyVettedList = [];
await(async () => {
const customerFacade = tutao.locator.customerFacade;
// loops through list of manually vetted emails and domains
const spamRulesList = [];
manuallyVettedList.forEach(emailOrDomain => {
// add spam rule to list
spamRulesList.push({value: emailOrDomain, field: SpamRuleFieldType.FROM, type: SpamRuleType.DISCARD});
});
// this is where my PR helps.
customerFacade.addSpamRules(spamRulesList)
}) (); |
Beta Was this translation helpful? Give feedback.
-
PR closed, since I am able to create identical hashed values using the Web Crypto API. Thanks @charlag for the tip const _buffer = new TextEncoder("utf-8").encode("testdomainnameofspammer.com");
const _uint8Array = crypto.subtle.digest("SHA-256", buffer).then(s => s);
const base64_arraybuffer = async (data) => {
const _base64url = await new Promise((r) => {
const _reader = new FileReader()
_reader.onload = () => r(_reader.result)
_reader.readAsDataURL(new Blob([data]))
});
return _base64url.split(",", 2)[1];
}
const hashedValue = await base64_arraybuffer(_uint8Array); |
Beta Was this translation helpful? Give feedback.
-
I am working on a browser extension to help me bulk manage spam emails. I plan to open source it and share it with the community.
I need a way to bulk add spam rules.
This should not break any existing API, the purpose of this is to add a new method in the CustomerFacade that I can interact with through the extension's contentscript.
I could just call entityClient.update directly, but I did not want to handle generating the hashedValue myself.
PS: I'd be happy to polish my implementation of the bulk spam management and create a PR to integrate it into the product if I get some feedback from the community and Tutanota's devs. I'll post in Reddit once ready.
Beta Was this translation helpful? Give feedback.
All reactions