Compare commits
No commits in common. "919c770fe37de319793f444f77c3756e6720108a" and "17cf534612946daa2682c0babeb8610d906e052a" have entirely different histories.
919c770fe3
...
17cf534612
22
app.json
22
app.json
|
@ -8,7 +8,7 @@
|
|||
"disposable-mail"
|
||||
],
|
||||
"env": {
|
||||
"EMAIL_DOMAINS": {
|
||||
"DOMAINS": {
|
||||
"description": "Email domains"
|
||||
},
|
||||
"EMAIL_PURGE_TIME": {
|
||||
|
@ -19,13 +19,6 @@
|
|||
"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"
|
||||
},
|
||||
|
@ -59,13 +52,12 @@
|
|||
"description": "The branding of the site",
|
||||
"value": ["48hr.email", "Crazyco", "https://crazyco.xyz"]
|
||||
},
|
||||
"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
|
||||
"HTTP_EXAMPLES": {
|
||||
"description": "Examples of the domains",
|
||||
"value": {
|
||||
"email": "example@48hr.email",
|
||||
"ids": [1, 2, 3]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,7 @@ 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
|
||||
|
@ -22,13 +18,11 @@ 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 [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)
|
||||
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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -84,67 +84,6 @@ 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
|
||||
|
|
|
@ -222,7 +222,7 @@ class ImapService extends EventEmitter {
|
|||
|
||||
const uidsWithHeaders = await this._getMailHeaders(uids)
|
||||
uidsWithHeaders.forEach(mail => {
|
||||
if (mail['attributes'].date > DeleteOlderThan || this.config.email.examples.uids.includes(parseInt(mail['attributes'].uid))) {
|
||||
if (mail['attributes'].date > DeleteOlderThan || this.config.http.examples.uids.includes(parseInt(mail['attributes'].uid))) {
|
||||
uids = uids.filter(uid => uid !== mail['attributes'].uid)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -13,7 +13,7 @@ class MailRepository {
|
|||
getForRecipient(address) {
|
||||
let mails = this.mailSummaries.get(address) || []
|
||||
mails.forEach(mail => {
|
||||
if (mail.to == this.config.email.examples.account && !this.config.email.examples.uids.includes(parseInt(mail.uid))) {
|
||||
if (mail.to == this.config.http.examples.email && !this.config.http.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.email.examples.uids.includes(parseInt(uid))) {
|
||||
if (!this.config.http.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) => {
|
||||
|
|
|
@ -14,7 +14,7 @@ router.get('/', (req, res, _next) => {
|
|||
title: `${config.http.branding[0]} | Your temporary Inbox`,
|
||||
username: randomWord(),
|
||||
purgeTime: purgeTime,
|
||||
domains: helper.getDomains(),
|
||||
domains: config.email.domains,
|
||||
branding: config.http.branding,
|
||||
})
|
||||
})
|
||||
|
@ -46,7 +46,6 @@ router.post(
|
|||
title: `${config.http.branding[0]} | Your temporary Inbox`,
|
||||
purgeTime: purgeTime,
|
||||
username: randomWord(),
|
||||
domains: helper.getDomains(),
|
||||
branding: config.http.branding,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "48hr.email",
|
||||
"version": "1.6.1",
|
||||
"version": "1.5.4",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"start": "node --trace-warnings ./app.js",
|
||||
|
|
Loading…
Reference in New Issue