Add example mail(s)
parent
84338ee1c1
commit
1d42862c46
|
@ -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]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,9 +235,11 @@ class ImapService extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
async deleteSpecificEmail(uid) {
|
async deleteSpecificEmail(uid) {
|
||||||
debug(`deleting mails ${uid}`)
|
debug(`deleting mails ${uid}`)
|
||||||
await this.connection.deleteMessage(uid)
|
if (!this.config.http.examples.uids.includes(parseInt(uid))) {
|
||||||
console.log(`deleted mail with UID: ${uid}.`)
|
await this.connection.deleteMessage(uid)
|
||||||
this.emit(ImapService.EVENT_DELETED_MAIL, uid)
|
console.log(`deleted mail with UID: ${uid}.`)
|
||||||
|
this.emit(ImapService.EVENT_DELETED_MAIL, uid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue