Compare commits

...

8 Commits

Author SHA1 Message Date
ClaraCrazy 919c770fe3
last minor example update 2024-10-21 02:24:33 +02:00
ClaraCrazy 5040b06264
Add hideOther config option
Allows the User to hide the total amount of domains and their addresses, always only displaying the first one of the array
2024-10-21 02:21:03 +02:00
ClaraCrazy 2026a360bf
Update example file 2024-10-21 02:03:38 +02:00
ClaraCrazy d0acf32b7f
Fix naming 2024-10-21 02:01:18 +02:00
ClaraCrazy 74c13678a8
More advanced domain sorting 2024-10-21 01:52:33 +02:00
ClaraCrazy a11c41c954
Fix error page during login 2024-10-21 00:46:53 +02:00
ClaraCrazy 5690348137
Add shuffle algoritm for more diverse default email generation 2024-10-21 00:46:25 +02:00
ClaraCrazy e5d9a6cf8c
Consistency
I swear this is the last of those patches...
2024-10-21 00:22:06 +02:00
7 changed files with 94 additions and 18 deletions

View File

@ -8,7 +8,7 @@
"disposable-mail"
],
"env": {
"DOMAINS": {
"EMAIL_DOMAINS": {
"description": "Email domains"
},
"EMAIL_PURGE_TIME": {
@ -19,6 +19,13 @@
"convert": true
}
},
"EMAIL_EXAMPLES": {
"description": "Examples of the domains",
"value": {
"account": "example@48hr.email",
"uids": [1, 2, 3]
}
},
"IMAP_USER": {
"description": "Username to login to the imap server"
},
@ -52,12 +59,13 @@
"description": "The branding of the site",
"value": ["48hr.email", "Crazyco", "https://crazyco.xyz"]
},
"HTTP_EXAMPLES": {
"description": "Examples of the domains",
"value": {
"email": "example@48hr.email",
"ids": [1, 2, 3]
}
"HTTP_DISPLAY_SORT": {
"description": "Sort the emails for use",
"value": 0
},
"HTTP_HIDE_OTHER": {
"description": "Hide other emails from the list besides the first",
"value": false
}
}
}

View File

@ -5,7 +5,11 @@ const config = {
time: 48, // Time value for when to purge
unit: 'hours', // minutes, hours, days
convert: true, // Convert to highest sensible unit (and round)
}
},
examples: process.env.EMAIL_EXAMPLES || { // Examples to use to demonstrate the service
account: "example@48hr.email", // example email to keep clean, besides the UIDs specified below
uids: [1, 2, 3] // example uids to keep
},
},
imap: { // IMAP configuration
user: process.env.IMAP_USER, // imap user
@ -18,11 +22,13 @@ const config = {
},
http: { // HTTP configuration
port: normalizePort(process.env.HTTP_PORT || 3000), // http port to listen on
branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"], // branding
examples: process.env.HTTP_EXAMPLES || { // Examples to use to demonstrate the service
email: "example@48hr.email", // example email to keep clean, besides the IDs specified below
ids: [1, 2, 3] // example ids to keep
}
branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"], // branding [service_title, company_name, company_url]
displaySort: process.env.HTTP_DISPLAY_SORT || 0, // Sorting logic used for display:
// 0 does not modify,
// 1 sorts alphabetically,
// 2 sorts alphabetically and only shuffles the first item,
// 3 shuffles all
hideOther: process.env.HTTP_HIDE_OTHER || false, // Hide other emails in the list and only show first (true) or show all (false)
},
}

View File

@ -84,6 +84,67 @@ class Helper {
return footer
}
/**
* Shuffle an array using the Durstenfeld shuffle algorithm
* @param {Array} array
* @returns {Array}
*/
shuffleArray(array) {
for (let i = array.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
/**
* Shuffle first item of array, keeping original order afterwards
* @param {Array} array
* @returns {Array}
*/
shuffleFirstItem(array) {
let first = array[Math.floor(Math.random()*array.length)]
console.log(first)
array = array.filter((value)=>value!=first);
console.log(array)
array = [first].concat(array)
console.log(array)
return array
}
/**
* Hide other emails in the list and only show first (true) or show all (false)
* @param {Array} array
* @returns {Array}
*/
hideOther(array) {
if (config.http.hideOther) {
return array[0]
} else {
return array
}
}
/**
* Get a domain list from config for use
* @returns {Array}
*/
getDomains() {
switch (config.http.displaySort) {
case 0:
return this.hideOther(config.email.domains) // No modification
case 1:
return this.hideOther(config.email.domains.sort()) // Sort alphabetically
case 2:
return this.hideOther(this.shuffleFirstItem(config.email.domains.sort())) // Sort alphabetically and shuffle first item
case 3:
return this.hideOther(this.shuffleArray(config.email.domains)) // Shuffle all
}
}
}
module.exports = Helper

View File

@ -222,7 +222,7 @@ class ImapService extends EventEmitter {
const uidsWithHeaders = await this._getMailHeaders(uids)
uidsWithHeaders.forEach(mail => {
if (mail['attributes'].date > DeleteOlderThan || this.config.http.examples.uids.includes(parseInt(mail['attributes'].uid))) {
if (mail['attributes'].date > DeleteOlderThan || this.config.email.examples.uids.includes(parseInt(mail['attributes'].uid))) {
uids = uids.filter(uid => uid !== mail['attributes'].uid)
}
})

View File

@ -13,7 +13,7 @@ class MailRepository {
getForRecipient(address) {
let mails = this.mailSummaries.get(address) || []
mails.forEach(mail => {
if (mail.to == this.config.http.examples.email && !this.config.http.examples.uids.includes(parseInt(mail.uid))) {
if (mail.to == this.config.email.examples.account && !this.config.email.examples.uids.includes(parseInt(mail.uid))) {
mails = mails.filter(m => m.uid != mail.uid)
debug('prevented non-example email from being shown in example inbox', mail.uid)
}
@ -31,7 +31,7 @@ class MailRepository {
}
removeUid(uid, address) {
if (!this.config.http.examples.uids.includes(parseInt(uid))) {
if (!this.config.email.examples.uids.includes(parseInt(uid))) {
var deleted = false
// TODO: make this more efficient, looping through each email is not cool.
this.mailSummaries.forEachAssociation((mails, to) => {

View File

@ -14,7 +14,7 @@ router.get('/', (req, res, _next) => {
title: `${config.http.branding[0]} | Your temporary Inbox`,
username: randomWord(),
purgeTime: purgeTime,
domains: config.email.domains,
domains: helper.getDomains(),
branding: config.http.branding,
})
})
@ -46,6 +46,7 @@ router.post(
title: `${config.http.branding[0]} | Your temporary Inbox`,
purgeTime: purgeTime,
username: randomWord(),
domains: helper.getDomains(),
branding: config.http.branding,
})
}

View File

@ -1,6 +1,6 @@
{
"name": "48hr.email",
"version": "1.5.4",
"version": "1.6.1",
"private": false,
"scripts": {
"start": "node --trace-warnings ./app.js",