Add example mail(s)

pull/16/head
ClaraCrazy 2024-10-02 02:36:25 +02:00
parent 84338ee1c1
commit 1d42862c46
No known key found for this signature in database
GPG Key ID: EBBC896ACB497011
3 changed files with 20 additions and 6 deletions

View File

@ -14,7 +14,11 @@ const config = {
}, },
http: { http: {
port: normalizePort(process.env.HTTP_PORT || 3000), port: normalizePort(process.env.HTTP_PORT || 3000),
branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"] branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"],
examples: process.env.HTTP_EXAMPLES || {
email: "example@48hr.email",
ids: [1, 2, 3]
}
}, },
} }

View File

@ -213,7 +213,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) { if (mail['attributes'].date > DeleteOlderThan || this.config.http.examples.uids.includes(parseInt(mail['attributes'].id))) {
uids.filter(uid => uid !== mail['attributes'].uid) uids.filter(uid => uid !== mail['attributes'].uid)
} }
}) })
@ -235,10 +235,12 @@ class ImapService extends EventEmitter {
*/ */
async deleteSpecificEmail(uid) { async deleteSpecificEmail(uid) {
debug(`deleting mails ${uid}`) debug(`deleting mails ${uid}`)
if (!this.config.http.examples.uids.includes(parseInt(uid))) {
await this.connection.deleteMessage(uid) await this.connection.deleteMessage(uid)
console.log(`deleted mail with UID: ${uid}.`) console.log(`deleted mail with UID: ${uid}.`)
this.emit(ImapService.EVENT_DELETED_MAIL, uid) this.emit(ImapService.EVENT_DELETED_MAIL, uid)
} }
}
/** /**
* Helper method because ImapSimple#search also fetches each message. We just need the uids here. * Helper method because ImapSimple#search also fetches each message. We just need the uids here.

View File

@ -1,15 +1,23 @@
const debug = require('debug')('48hr-email:mail-summary-store') const debug = require('debug')('48hr-email:mail-summary-store')
const MultiMap = require('mnemonist/multi-map') const MultiMap = require('mnemonist/multi-map')
const _ = require('lodash') const _ = require('lodash')
const config = require('../application/config')
class MailRepository { class MailRepository {
constructor() { constructor() {
// MultiMap docs: https://yomguithereal.github.io/mnemonist/multi-map // MultiMap docs: https://yomguithereal.github.io/mnemonist/multi-map
this.mailSummaries = new MultiMap() this.mailSummaries = new MultiMap()
this.config = config
} }
getForRecipient(address) { getForRecipient(address) {
const mails = this.mailSummaries.get(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))) {
mails = mails.filter(m => m.uid != mail.uid)
console.log('prevent non-example email from being shown', mail.uid)
}
})
return _.orderBy(mails, mail => Date.parse(mail.date), ['desc']) return _.orderBy(mails, mail => Date.parse(mail.date), ['desc'])
} }