Replies: 2 comments
|
have you figured out a way to do this properly? |
0 replies
|
A few things in the sample stop it from working:
Something like this collects all of it: exports.hook_data = function (next, connection) {
const txn = connection.transaction
txn.parse_body = true
txn.notes.attachments = []
txn.attachment_hooks((ct, filename, body, stream) => {
stream.connection = connection // backpressure while we read
const chunks = []
stream.on('data', (chunk) => chunks.push(chunk))
stream.on('end', () => {
const content = Buffer.concat(chunks)
txn.notes.attachments.push({ filename, contentType: ct, size: content.length, content })
})
})
next()
}
function collectText(part, found = { text: [], html: [] }) {
const ct = (part.ct || '').toLowerCase()
if (ct.startsWith('text/plain')) found.text.push(part.bodytext)
if (ct.startsWith('text/html')) found.html.push(part.bodytext)
for (const child of part.children) collectText(child, found)
return found
}
exports.hook_data_post = function (next, connection) {
const txn = connection.transaction
const { text, html } = collectText(txn.body)
this.loginfo(connection, `from: ${txn.mail_from.address()}`)
this.loginfo(connection, `to: ${txn.rcpt_to.map((rcpt) => rcpt.address()).join(', ')}`)
this.loginfo(connection, `subject: ${txn.header.get_decoded('Subject')}`)
this.loginfo(connection, `text parts: ${text.length}, html parts: ${html.length}`)
for (const att of txn.notes.attachments) {
this.loginfo(connection, `attachment: ${att.filename} (${att.contentType}, ${att.size} bytes)`)
}
next()
}
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Trying to use Haraka as the Mail Server in our new project ,We are trying to make our own plugin and no way we could find a solution to access the mail properties like Body and the attachments , Can any one please help us to find an existing plugin which we could get the mail properties like , Receivers, Body , Attachment etc.. Or the sample code snippet that can be used to access this properties
Below is a sample code which we are writing our plugin
All reactions