How to merge multiple Mail into one mail as conversation ?

This plugin allows you to report an issue in MantisBT by sending an email to a particular mail account

Moderators: Developer, Contributor

Post Reply
simonyeh
Posts: 9
Joined: 05 Feb 2018, 07:08

How to merge multiple Mail into one mail as conversation ?

Post by simonyeh »

Hi there

My environment is :
MantisBT : v2.10.0
PHP : v7.0.27
DB : mySQL 5.5.56-MariaDB

MY question is
How to merge multiple mails into a single one like coversation ?
Because my vendor will send a email like a new mail with NO "RE:" but the same subject so that the plugin will create a new ticket in the Mantis
Please check the picture:
https://drive.google.com/file/d/1R9abtW ... sp=sharing
the 1st row is the mail from my vendor which is to reply the 2nd mail, but it without "RE" that seems to be a new mail and you can see that subject is same.

Can EmailRorting merge these 2 mail into single one as a conversation? or How to use subject of mail as the condition for reply?
SL-Gundam
Posts: 722
Joined: 06 Jul 2011, 14:17

Re: How to merge multiple Mail into one mail as conversation ?

Post by SL-Gundam »

Just an FYI: One thing that you should never do is have 2 Ticket systems mail each other.

Having said that, EmailReporting uses 2 mechanisms to decide whether an email is part of the same ticket
  1. It checks whether the message id is known. When you reply to a message it will record the original message id in the reply and that way EmailReporting will know when emails belong together
  2. It checks whether the ticket number is in the subject line -> See https://www.mantisbt.org/wiki/doku.php/ ... t_id_regex
Number 1 is useful when you are adding MantisBT as a CC to a ongoing mailing.
Number 2 is useful when somebody replies to a MantisBT notification email
The "RE:" or "FW:" are unimportant. EmailReporting does nothing with it

Since another ticketing system creates a new email for every new answer, Number 1 will not work.
Since another ticketing system uses its own ticket number and subject formatting, Number 2 is unlikely (not impossible) to work. Based on your screenshot i suspect that the "Case 00063247" is the ticket number in your system. Make sure that that part of the subject line is encased in brackets like this "[Case 00063247]" and it might work
simonyeh
Posts: 9
Joined: 05 Feb 2018, 07:08

Re: How to merge multiple Mail into one mail as conversation ?

Post by simonyeh »

Hi, Sir

Yes , You are right , "CASE XXXX" is the ID number from my vendor's ticket system and he will reply the answer by sending a new mail with the same subject. I know it will become a new 'Message-ID' so that MailRporting will think it is a new ticket.

Based on this situation, it seems to need to modify source code to have another regular expression to replace original one. Right?
Which file of source code and which method should I modify?
SL-Gundam
Posts: 722
Joined: 06 Jul 2011, 14:17

Re: How to merge multiple Mail into one mail as conversation ?

Post by SL-Gundam »

If "CASE XXXX" is your vendors number then that is not what were looking for. You need to make sure that somewhere in the subject line is the ticket number of your MantisBT installation

These formats are supported: https://www.mantisbt.org/wiki/doku.php/ ... t_id_regex

If thats not possible. then you will need to modify EmailReporting as required
This function deals with the detection of the email towards an existing issue
https://github.com/mantisbt-plugins/Ema ... .php#L1417
simonyeh
Posts: 9
Joined: 05 Feb 2018, 07:08

Re: How to merge multiple Mail into one mail as conversation ?

Post by simonyeh »

Hi Sir

According to your suggestion , My idea is to modify the code , my idea is :
1. Create a customized column field (it called ID2) in Mantis and using this column to store my vendor's ticket id found in mail subject
https://drive.google.com/file/d/1s4c9J9 ... sp=sharing

2. Modify get_bug_id_from_subject( $p_mail_subject ) in order to parse my vendor's ticket id correctly, I've done this.
3. Change and add some code like below,

Code: Select all

       Search ID2 and if exist  then select ID (<- this is Mantis Case ID) from Mantis table 
       if ( isset( $v_matches[ 'id' ] ) )
		{
			return( (int) $v_matches[ 'id' ] );
		}
      else return false

my questions are
1. Is my idea workable ?
2. I'm new to PHP coding , could anyone give me some sample code ? I don't know which table contain my customized field and how to use

Thanks in advance
SL-Gundam
Posts: 722
Joined: 06 Jul 2011, 14:17

Re: How to merge multiple Mail into one mail as conversation ?

Post by SL-Gundam »

The table that would contain the custom fields contents is: "custom_field_string_table"

The code to get the contents of the custom field should be more or less like this i think (code not tested)

Code: Select all

$t_query = 'SELECT A.bug_id FROM ' . db_get_table( 'custom_field_string' ) . ' A WHERE A.field_id = ??? AND A.value = ' . db_param();
$t_bug_id = db_result( db_query_bound( $t_query, array( (int)$t_vendor_id ), 1 ) );
You will have to replace ??? with whatever id number your custom field has in the "custom_field_table"
$t_vendor_id is the vendor CASE number retrieved from the subject line
If a value is returned then thats the MantisBT issue id where you want to merge the mail content into
simonyeh
Posts: 9
Joined: 05 Feb 2018, 07:08

Re: How to merge multiple Mail into one mail as conversation ?

Post by simonyeh »

Hi Sir

Firstly , i'm very appreciated your kindly help and useful information , it seems to be workable !
And I encounter another problem ...
If searching Vendor's ID and it is not found in customer_string_table. That means it is a new BUG to Mantis.
In order to have a correct logic , the next step I should do is adding the new Mantis bug_id into customer_string_table and my vendor's ID as well
it should like the picture below
https://drive.google.com/file/d/14SaNKU ... sp=sharing

bug_id is Mantis Bug ID
value is my vendor's ticket ID

But which PHP file and function which I should modify ?
What I want is to add new Bug_id and my vendor's ID into the customer_string_table when a new bug is reported
I can not tell these PHP file correctly when I checked the source file of Mantis PHP and EMAILREPORT
Thanks.
SL-Gundam
Posts: 722
Joined: 06 Jul 2011, 14:17

Re: How to merge multiple Mail into one mail as conversation ?

Post by SL-Gundam »

There are 2 sections of code that pertain to updating custom fields

https://github.com/mantisbt-plugins/Ema ... i.php#L982
https://github.com/mantisbt-plugins/Ema ... .php#L1014

Only the second one is functional to process the default values.
These 2 sections would need to be modified so that it will import your vendor case number in the proper custom field
Post Reply