mirror of
				https://github.com/Crazyco-xyz/48hr.email.git
				synced 2025-11-04 15:26:33 +01:00 
			
		
		
		
	Compare commits
	
		
			8 commits
		
	
	
		
			17cf534612
			...
			919c770fe3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						919c770fe3 | ||
| 
							 | 
						5040b06264 | ||
| 
							 | 
						2026a360bf | ||
| 
							 | 
						d0acf32b7f | ||
| 
							 | 
						74c13678a8 | ||
| 
							 | 
						a11c41c954 | ||
| 
							 | 
						5690348137 | ||
| 
							 | 
						e5d9a6cf8c | 
					 7 changed files with 94 additions and 18 deletions
				
			
		
							
								
								
									
										22
									
								
								app.json
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								app.json
									
										
									
									
									
								
							| 
						 | 
					@ -8,7 +8,7 @@
 | 
				
			||||||
    "disposable-mail"
 | 
					    "disposable-mail"
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  "env": {
 | 
					  "env": {
 | 
				
			||||||
    "DOMAINS": {
 | 
					    "EMAIL_DOMAINS": {
 | 
				
			||||||
      "description": "Email domains"
 | 
					      "description": "Email domains"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "EMAIL_PURGE_TIME": {
 | 
					    "EMAIL_PURGE_TIME": {
 | 
				
			||||||
| 
						 | 
					@ -19,6 +19,13 @@
 | 
				
			||||||
        "convert": true
 | 
					        "convert": true
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "EMAIL_EXAMPLES": {
 | 
				
			||||||
 | 
					      "description": "Examples of the domains",
 | 
				
			||||||
 | 
					      "value": {
 | 
				
			||||||
 | 
					        "account": "example@48hr.email",
 | 
				
			||||||
 | 
					        "uids": [1, 2, 3]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "IMAP_USER": {
 | 
					    "IMAP_USER": {
 | 
				
			||||||
      "description": "Username to login to the imap server"
 | 
					      "description": "Username to login to the imap server"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
| 
						 | 
					@ -52,12 +59,13 @@
 | 
				
			||||||
      "description": "The branding of the site",
 | 
					      "description": "The branding of the site",
 | 
				
			||||||
      "value": ["48hr.email", "Crazyco", "https://crazyco.xyz"]
 | 
					      "value": ["48hr.email", "Crazyco", "https://crazyco.xyz"]
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "HTTP_EXAMPLES": {
 | 
					    "HTTP_DISPLAY_SORT": {
 | 
				
			||||||
      "description": "Examples of the domains",
 | 
					      "description": "Sort the emails for use",
 | 
				
			||||||
      "value": {
 | 
					      "value": 0
 | 
				
			||||||
        "email": "example@48hr.email",
 | 
					    },
 | 
				
			||||||
        "ids": [1, 2, 3]
 | 
					    "HTTP_HIDE_OTHER": {
 | 
				
			||||||
      }
 | 
					      "description": "Hide other emails from the list besides the first",
 | 
				
			||||||
 | 
					      "value": false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,11 @@ const config = {
 | 
				
			||||||
			time: 48, // Time value for when to purge
 | 
								time: 48, // Time value for when to purge
 | 
				
			||||||
			unit: 'hours', // minutes, hours, days
 | 
								unit: 'hours', // minutes, hours, days
 | 
				
			||||||
			convert: true, // Convert to highest sensible unit (and round)
 | 
								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
 | 
						imap: { // IMAP configuration
 | 
				
			||||||
		user: process.env.IMAP_USER, // imap user
 | 
							user: process.env.IMAP_USER, // imap user
 | 
				
			||||||
| 
						 | 
					@ -18,11 +22,13 @@ const config = {
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	http: { // HTTP configuration
 | 
						http: { // HTTP configuration
 | 
				
			||||||
		port: normalizePort(process.env.HTTP_PORT || 3000), // http port to listen on
 | 
							port: normalizePort(process.env.HTTP_PORT || 3000), // http port to listen on
 | 
				
			||||||
		branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"], // branding
 | 
							branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"], // branding [service_title, company_name, company_url]
 | 
				
			||||||
		examples: process.env.HTTP_EXAMPLES || { // Examples to use to demonstrate the service
 | 
							displaySort: process.env.HTTP_DISPLAY_SORT || 0, // Sorting logic used for display:
 | 
				
			||||||
			email: "example@48hr.email", // example email to keep clean, besides the IDs specified below
 | 
							// 0 does not modify, 
 | 
				
			||||||
			ids: [1, 2, 3] // example ids to keep
 | 
							// 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)
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,6 +84,67 @@ class Helper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return footer
 | 
					        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
 | 
					module.exports = Helper
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -222,7 +222,7 @@ class ImapService extends EventEmitter {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const uidsWithHeaders = await this._getMailHeaders(uids)
 | 
							const uidsWithHeaders = await this._getMailHeaders(uids)
 | 
				
			||||||
		uidsWithHeaders.forEach(mail => {
 | 
							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)
 | 
									uids = uids.filter(uid => uid !== mail['attributes'].uid)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ class MailRepository {
 | 
				
			||||||
	getForRecipient(address) {
 | 
						getForRecipient(address) {
 | 
				
			||||||
		let mails = this.mailSummaries.get(address) || []
 | 
							let mails = this.mailSummaries.get(address) || []
 | 
				
			||||||
		mails.forEach(mail => {
 | 
							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)
 | 
									mails = mails.filter(m => m.uid != mail.uid)
 | 
				
			||||||
				debug('prevented non-example email from being shown in example inbox', mail.uid)
 | 
									debug('prevented non-example email from being shown in example inbox', mail.uid)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ class MailRepository {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	removeUid(uid, address) {
 | 
						removeUid(uid, address) {
 | 
				
			||||||
		if (!this.config.http.examples.uids.includes(parseInt(uid))) {
 | 
							if (!this.config.email.examples.uids.includes(parseInt(uid))) {
 | 
				
			||||||
			var deleted = false
 | 
								var deleted = false
 | 
				
			||||||
			// TODO: make this more efficient, looping through each email is not cool.
 | 
								// TODO: make this more efficient, looping through each email is not cool.
 | 
				
			||||||
			this.mailSummaries.forEachAssociation((mails, to) => {
 | 
								this.mailSummaries.forEachAssociation((mails, to) => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ router.get('/', (req, res, _next) => {
 | 
				
			||||||
		title: `${config.http.branding[0]} | Your temporary Inbox`,
 | 
							title: `${config.http.branding[0]} | Your temporary Inbox`,
 | 
				
			||||||
		username: randomWord(),
 | 
							username: randomWord(),
 | 
				
			||||||
		purgeTime: purgeTime,
 | 
							purgeTime: purgeTime,
 | 
				
			||||||
		domains: config.email.domains,
 | 
							domains: helper.getDomains(),
 | 
				
			||||||
		branding: config.http.branding,
 | 
							branding: config.http.branding,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
| 
						 | 
					@ -46,6 +46,7 @@ router.post(
 | 
				
			||||||
				title: `${config.http.branding[0]} | Your temporary Inbox`,
 | 
									title: `${config.http.branding[0]} | Your temporary Inbox`,
 | 
				
			||||||
				purgeTime: purgeTime,
 | 
									purgeTime: purgeTime,
 | 
				
			||||||
				username: randomWord(),
 | 
									username: randomWord(),
 | 
				
			||||||
 | 
									domains: helper.getDomains(),
 | 
				
			||||||
				branding: config.http.branding,
 | 
									branding: config.http.branding,
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  "name": "48hr.email",
 | 
					  "name": "48hr.email",
 | 
				
			||||||
  "version": "1.5.4",
 | 
					  "version": "1.6.1",
 | 
				
			||||||
  "private": false,
 | 
					  "private": false,
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "start": "node --trace-warnings ./app.js",
 | 
					    "start": "node --trace-warnings ./app.js",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue