Modifying email notifications with plugin adding attachments

General discussion of Mantis.

Moderators: Developer, Contributor

Post Reply
tomzero
Posts: 3
Joined: 11 Apr 2023, 11:25

Modifying email notifications with plugin adding attachments

Post by tomzero »

The task
When assigning a user to a bug the notification email MUST contain the bug's attachments of type image

The reason
Workers in the field get their tasks by assigning bugs to them. They are craftsmen equiped with mobile phones and actually never access the MantisBT system. Their respective users are just dummys with valid email addresses to be able to forward the task to them

The solution approaches
1) I wrote a plugin hooking to EVENT_DISPLAY_EMAIL which reads the attachments from the database via file_api, converts them into base64 encoded email attachments, creates the appropriate attachment structure and appends it to the message text provided to the hook function. This kind of works: my string is inserted into the mail correctly but it cannot work since the mail itself ist not flagged as multipart.

Question: Is there any other event I am not aware of (I've read the Developers guide thoroughly) which gives deeper access to the notification email's structure? I'd actually create it myself completely. Maybe I look the wrong way and there is some other solution approach I don't see yet.

2) I wrote a plugin hooking to EVENT_DISPLAY_EMAIL which inserts valid URLs pointing to the attachments located in a publicly acessible folder on the webserver. The links are inserted into the notification email and can be clicked. The browser opens and the image should be displayed in the browser. Unfortunately, the files in Mantis' upload folder lose their file extension when being renamed by the file_api. Due to the HTTP header configuration of the webserver - which is not under my administrative control - the browser downloads the file immediately instead of displaying it. If I append an appropriate file extension to the attachment files on the disk the browser shows the image instead of downloading it.

Question: Is there any chance to modify the behavior of the file_api generating the file names by means of a plugin? Maybe via the EVENT_REPORT_BUG hook? Are the attachment filenames accessible and persistently modifyable from there?
cas
Posts: 1622
Joined: 11 Mar 2006, 16:08
Contact:

Re: Modifying email notifications with plugin adding attachments

Post by cas »

The attachment filenames are stored in the the file_table including the type of file. So there you can find them.
Out of the box theer is not much possible with the emails as such.
I did create an option to define your own templates for emails but that does require some adjustments is core files.
This (https://mantisbt.org/forums/viewtopic.php?p=74209) can be modified to insert the image you deem necessary.
tomzero
Posts: 3
Joined: 11 Apr 2023, 11:25

Re: Modifying email notifications with plugin adding attachments

Post by tomzero »

I was already aware of your template system. I definitely won't modify core files since we maintain numerous MantisBT installations and perform automated updates. Nonetheless, your reply brought up a new idea: I will build a plugin that doesn't use the upload folder but writes the attachments into a separate folder. There I can set the filenames to whatever I want to and put the links into the notification emails. Not as good as a real email attachment but better than nothing for now. Cleanup may become an issue in the future but that's probably quite simple to solve.
cas
Posts: 1622
Joined: 11 Mar 2006, 16:08
Contact:

Re: Modifying email notifications with plugin adding attachments

Post by cas »

There is the forward plugin which you could modify to become active on the EVENT_REPORT_BUG. Next add the attachment to the mail. Perhaps that will work for you.
Post Reply