Haraka icon indicating copy to clipboard operation
Haraka copied to clipboard

Adding an attachment to a message

Open thannaske opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Under specific conditions I want to add an attachment to an e-mail message. I'm currently working on a plugin that does some GPG magic under the hood and I therefore need to add public keys to a message. While playing with the add_body_filter method I realized that this filter is applied for every MIME-part of the message and thus can not be used to add another attachment to the e-mail.

Describe the solution you'd like Would be great to have a function available for plugin development that allows adding an attachment. I'm no JavaScript/NodeJS expert by any means but I would love to see something like this:

exports.recrypt_enable = function (next, connection) {
    const plugin = this;
    connection.transaction.parse_body = true;

    // Run this under specific conditions
    connection.transaction.add_attachment({
        filename: 'public.asc',
        contentType: 'application/octet-stream',
        content: Buffer.from('...'),
    });

    return next();
}

Describe alternatives you've considered I tried to use the add_body_filter functionality but unfortunately this method is somewhat restricted because you can not add a whole new MIME attachment to the message body. Furthermore the filtered content needs to be the same encoding and type as before. So no way to add something to the message in here.

Additional context Would be great if there would be more possibilities to write plugins that can do more with the message body itself. Haraka has a powerful API for working with anything e-mail related but the capacities regarding the message body are somewhat limited.

thannaske avatar Mar 08 '22 13:03 thannaske