View Issue Details

IDProjectCategoryView StatusLast Update
0014510mantisbtemailpublic2012-08-09 16:46
ReporterErikRoelofs Assigned Toatrol  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionduplicate 
OSWindowsOS Version7 SP1 
Product Version1.2.10 
Summary0014510: Allowing Plugins to handle email sending
Description

Currently Mantis emails are not customizable. Since we need the ability to change the format and layout of the emails Mantis sends to customers, we wanted the ability to allow a Plugin to handle the sending of an email, overruling Mantis' default sender.

I added a new event for this (EVENT_NOTIFY_MAIL_SENDING) which works the same way as the EVENT_NOTIFY_USER_EXCLUDE event and allows a Plugin to hook into the actual sending of an email.

I would like to make this (minor) change to Mantis available to the core in case other developers would also be interested in this. Patch file included.

TagsNo tags attached.
Attached Files
feature_branch.patch (4,030 bytes)   
From d30d54762ca50f652ac701f8cf277ac94cd2e3d2 Mon Sep 17 00:00:00 2001
From: Erik Roelofs <e.roelofs@samson-it.nl>
Date: Wed, 25 Jul 2012 12:20:32 +0200
Subject: [PATCH 2/2] Addding an event to email_api that allows Plugins to
 overrule the Mantis mail sender.

---
 core/email_api.php  | 38 +++++++++++++++++++++++++++-----------
 core/events_inc.php |  1 +
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/core/email_api.php b/core/email_api.php
index ed70dc7..71a3ece 100755
--- a/core/email_api.php
+++ b/core/email_api.php
@@ -336,7 +336,7 @@ function email_collect_recipients( $p_bug_id, $p_notify_type, $p_extra_user_ids_
 	user_cache_array_rows( $t_user_ids );
 	user_pref_cache_array_rows( $t_user_ids );
 	user_pref_cache_array_rows( $t_user_ids, $t_bug->project_id );
-
+    
 	# Check whether users should receive the emails
 	# and put email address to $t_recipients[user_id]
 	foreach( $t_recipients as $t_id => $t_ignore ) {
@@ -408,7 +408,6 @@ function email_collect_recipients( $p_bug_id, $p_notify_type, $p_extra_user_ids_
 			$t_final_recipients[$t_id] = $t_email;
 		}
 	}
-
 	return $t_final_recipients;
 }
 
@@ -566,15 +565,32 @@ function email_generic( $p_bug_id, $p_notify_type, $p_message_id = null, $p_head
 		if( is_array( $t_recipients ) ) {
 			# send email to every recipient
 			foreach( $t_recipients as $t_user_id => $t_user_email ) {
-				log_event( LOG_EMAIL, sprintf( "Issue = #%d, Type = %s, Msg = '%s', User = @U%d, Email = '%s'.", $p_bug_id, $p_notify_type, $p_message_id, $t_user_id, $t_user_email ) );
-
-				# load (push) user language here as build_visible_bug_data assumes current language
-				lang_push( user_pref_get_language( $t_user_id, $t_project_id ) );
-
-				$t_visible_bug_data = email_build_visible_bug_data( $t_user_id, $p_bug_id, $p_message_id );
-				$t_ok = email_bug_info_to_one_user( $t_visible_bug_data, $p_message_id, $t_project_id, $t_user_id, $p_header_optional_params ) && $t_ok;
-
-				lang_pop();
+                
+                # check if any plugin(s) wish to handle the mail that is going to be sent
+                $t_completed = false;
+                $t_overrides = event_signal( 'EVENT_NOTIFY_MAIL_SENDING', array( $p_bug_id, $p_notify_type, $t_user_id ) );
+                foreach( $t_overrides as $t_plugin => $t_callbacks ) {
+                    foreach ( $t_callbacks as $t_callback => $t_override ) {
+                        if ( $t_override ) {
+                            log_event( LOG_EMAIL_RECIPIENT, sprintf( 'Issue = #%d, %s plugin handled email for user @U%d', $p_bug_id, $t_plugin, $t_id ) );
+                            $t_completed = true;
+                        }
+                    }
+                }
+                if ( $t_completed ) {
+                    # this mail was handled by a plugin
+                }
+                
+                # use the default mailer
+                log_event( LOG_EMAIL, sprintf( "Issue = #%d, Type = %s, Msg = '%s', User = @U%d, Email = '%s'.", $p_bug_id, $p_notify_type, $p_message_id, $t_user_id, $t_user_email ) );
+
+                # load (push) user language here as build_visible_bug_data assumes current language
+                lang_push( user_pref_get_language( $t_user_id, $t_project_id ) );
+
+                $t_visible_bug_data = email_build_visible_bug_data( $t_user_id, $p_bug_id, $p_message_id );
+                $t_ok = email_bug_info_to_one_user( $t_visible_bug_data, $p_message_id, $t_project_id, $t_user_id, $p_header_optional_params ) && $t_ok;
+
+                lang_pop();
 			}
 		}
 
diff --git a/core/events_inc.php b/core/events_inc.php
index 292ca1d..b373376 100755
--- a/core/events_inc.php
+++ b/core/events_inc.php
@@ -124,4 +124,5 @@ event_declare_many( array(
     'PRINT_ATTACHMENT'          => EVENT_TYPE_EXECUTE,    
     'EVENT_BLOCK_ATTACHMENT'    => EVENT_TYPE_CHAIN,    
     'EVENT_BUG_BUTTONS'         => EVENT_TYPE_EXECUTE,    
+    'EVENT_NOTIFY_MAIL_SENDING' => EVENT_TYPE_DEFAULT,
 ) );
-- 
1.7.11.msysgit.0

feature_branch.patch (4,030 bytes)   

Relationships

duplicate of 0012830 new new HTMLMail plugin v0.1 

Activities

Lapinkiller

Lapinkiller

2012-07-25 09:42

reporter   ~0032365

It's a good idea :)

for my office, in few days, i'll rewrite entirely the mail management (configuration and sending) it would be great if i can do it with a plugin to share it with the mantis community

atrol

atrol

2012-07-25 15:48

developer   ~0032367

Is it ok to close this as a duplicate of 0012830 ?
Have also a look at all other related issues.

ErikRoelofs

ErikRoelofs

2012-07-26 03:13

reporter   ~0032374

Yes, that seems like a more complete package for html mailing. Feel free to close this as a duplicate.

Gopi14

Gopi14

2012-07-31 02:21

reporter   ~0032412

I want to resolve this issues