Page 1 of 1

Custom email notification content

Posted: 01 Jun 2020, 14:58
by eleyes
Dear mantis forum members.
My question is regarding the email content sent when notifying users related to tickets. I know there are already some posts talking about it and that there isn't yet a visual way to modify it.
However that, and knowing the PHP file i must modify in order to customize email contents, i'd please ask if someone would point me in the right direction inside this PHP file.
My objective is to shorten the content of the mail that informer receives.

Thanks a lot in advance for your help.

Re: Custom email notification content

Posted: 06 Jun 2020, 11:31
by cas
Look in core/email_api.php :mrgreen:

Re: Custom email notification content

Posted: 22 Jun 2020, 16:42
by eleyes
Thanks a lot for your reply!
I am investigating the content of this file and isn't quite understandable for my level... Sorry.
If someone could point me to the line number or any other reference inside this file, where to modify, i will appreciate a lot.
Best,

Re: Custom email notification content

Posted: 23 Jun 2020, 09:21
by cas
If you check bug_update.php, you will find at the bottom og the script the following:

Code: Select all

# Allow a custom function to respond to the modifications made to the bug. Note
# that custom functions are being deprecated in MantisBT. You should migrate to
# the new plugin system instead.
helper_call_custom_function( 'issue_update_notify', array( $f_bug_id ) );

# Send a notification of changes via email.
if( $t_resolve_issue ) {
	email_resolved( $f_bug_id );
	email_relationship_child_resolved( $f_bug_id );
} else if( $t_close_issue ) {
	email_close( $f_bug_id );
	email_relationship_child_closed( $f_bug_id );
} else if( $t_reopen_issue ) {
	email_bug_reopened( $f_bug_id );
} else if( $t_existing_bug->handler_id != $t_updated_bug->handler_id ) {
	email_owner_changed( $f_bug_id, $t_existing_bug->handler_id, $t_updated_bug->handler_id );
} else if( $t_existing_bug->status != $t_updated_bug->status ) {
	$t_new_status_label = MantisEnum::getLabel( config_get( 'status_enum_string' ), $t_updated_bug->status );
	$t_new_status_label = str_replace( ' ', '_', $t_new_status_label );
	email_bug_status_changed( $f_bug_id, $t_new_status_label );
} else {
	email_bug_updated( $f_bug_id );
} 
So depending on the change another routine is used, all within email_api.php.
Try to follow the code to find where you would like to change something.

Re: Custom email notification content

Posted: 23 Jun 2020, 11:57
by eleyes
Thanks a lot for your reply! Following the info you provided me, it lead me to the "email_build_visible_bug_data" function where it seems that if i comment some parts of it, the notification info will be modified.
I'll try and post back here.
Thanks again.

Re: Custom email notification content

Posted: 24 Jun 2020, 01:03
by Starbuck
Ugh, I've had email_api.php sitting on my desktop for months and I need to make changes.
It's just staring at me. "Go ahead, I dare you to start messing with me."
I haven't allocated the time to wrestle with the beast.

I love that Mantis is so versatile in some ways, but it's so hard-coded in others...
I know: "If you don't like it, change it and submit a PR".
Note that thing about time.

In the end, there can be only one... :twisted:

Re: Custom email notification content

Posted: 02 Jul 2020, 11:52
by eleyes
Here is my little contribution regarding this topic.
The lines in /core/email_api.php from 1706 to 1993 are related to what finally contains the email notification:

Some examples (just comment it if don't want to include it in email):

Reporter:

Code: Select all

$t_message .= email_format_attribute( $p_visible_bug_data, 'email_reporter' );
Ticket priority:

Code: Select all

if ( isset( $p_visible_bug_data[ 'email_priority' ] ) ) {
		$p_visible_bug_data['email_priority'] = get_enum_element( 'priority', $p_visible_bug_data['email_priority'] );
		$t_message .= email_format_attribute( $p_visible_bug_data, 'email_priority' );
	}
Custom fields:

Code: Select all

foreach( $p_visible_bug_data['custom_fields'] as $t_custom_field_name => $t_custom_field_data ) {
		$t_message .= utf8_str_pad( lang_get_defaulted( $t_custom_field_name, null ) . ': ', $t_email_padding_length, ' ', STR_PAD_RIGHT );
		$t_message .= string_custom_field_value_for_email( $t_custom_field_data['value'], $t_custom_field_data['type'] );
		$t_message .= " \n";
	}
And so on.

I hope it helps someone.

Best,