Page 1 of 1
How to add CC: email to incoming message?
Posted: 15 Jan 2019, 22:46
by mushu
Mantis 2.18.0
EmailReporting 0.10.1
I added these two lines of code in
mail_api.php but they don't seem to be doing anything in Mantis. We are trying to add a custom email address read from the body text of an incoming bug report via email. What am I doing wrong? The incoming email body text contains a line like this: blahblah Client
someEmail@domain.com blahblah
Code: Select all
private function parse_content( &$p_msg )
{
$this->show_memory_usage( 'Start Mail Parser' );
$t_mp = new ERP_Mail_Parser( $this->_mp_options, $this->_mailbox_starttime );
$t_mp->setInputString( $p_msg );
if ( $this->_mail_add_complete_email )
{
$t_part = array(
'name' => 'Complete email.txt',
'ctype' => 'text/plain',
'body' => $p_msg,
);
}
preg_match('/Client\s(.+)\@(.+)\s/', $t_part['body'], $pmatch); # ADDED THIS HERE
if ($pmatch[1] !== "") { $t_email[ 'Cc' ] = $pmatch[1] . "@" . $pmatch[2]; } # ADDED THIS HERE
$p_msg = NULL;
$t_mp->parse();
$t_email[ 'From_parsed' ] = $this->parse_from_field( trim( $t_mp->from() ) );
$t_email[ 'Reporter_id' ] = $this->get_user( $t_email[ 'From_parsed' ] );
$t_email[ 'Subject' ] = trim( $t_mp->subject() );
$t_email[ 'To' ] = $this->get_emailaddr_from_string( $t_mp->to() );
# $t_email[ 'Cc' ] = $this->get_emailaddr_from_string( $t_mp->cc() ); # COMMENTED THIS LINE OUT
$t_email[ 'X-Mantis-Body' ] = trim( $t_mp->body() );
$t_email[ 'X-Mantis-Parts' ] = $t_mp->parts();
Does Mantis even use the CC: field when it processes status changes in a ticket? Or should I add it to the TO: line after a comma?
Re: How to add CC: email to incoming message?
Posted: 16 Jan 2019, 11:42
by SL-Gundam
Your code is applied to raw mail content which is only set apart there for debug purposes incase you've enabled:
https://www.mantisbt.org/wiki/doku.php/ ... lete_email
Apply your code a couple lines below that below the following line and use $t_email[ 'X-Mantis-Body' ]
Code: Select all
$t_email[ 'X-Mantis-Body' ] = trim( $t_mp->body() );
Re: How to add CC: email to incoming message?
Posted: 16 Jan 2019, 19:36
by mushu
Now I get this error:
Code: Select all
SYSTEM WARNING: 'array_merge(): Argument #2 is not an array' in 'C:\MantisBT2180\plugins\EmailReporting\core\mail_api.php' line 1779
and that line of code in the plugin is this:
Code: Select all
$t_emails = array_merge( $p_email[ 'To' ], $p_email[ 'Cc' ] );
?
Re: How to add CC: email to incoming message?
Posted: 16 Jan 2019, 19:44
by mushu
NEVERMIND I changed the line of code from this:
Code: Select all
if ("" !== $pmatch[1]) { $t_email[ 'Cc' ] = $pmatch[1] . "@" . $pmatch[2] ; }
to this:
Code: Select all
if ("" !== $pmatch[1]) { $t_email[ 'Cc' ] = $this->get_emailaddr_from_string( $pmatch[1] . "@" . $pmatch[2] ); }
I hope it will work!
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 17:07
by mushu
Bumping this topic because a while ago I noticed our incoming mantis emails were not being processed properly in the EmailReporting plugin, NOT due to the author of the awesome plugin.
It was code I had added in
private function parse_content( &$p_msg ) just before the final "
return" statement that scans the body of the email text looking for certain items and changing the subject line:
Code: Select all
if ( preg_match( '/\@salesforce.com/i', trim( $t_mp->sender() ) ) )
{
$t_email[ 'Subject' ] = preg_replace( '/Service Request \#(\d+)/i', '(Ref:IN:\\1)', trim( $t_mp->subject() ) );
$t_email[ 'Subject' ] = preg_replace( '/Incident \#(\d+)/i', '(Ref:IN:\\1)', trim( $t_mp->subject() ) );
$t_email[ 'Return-Path' ] = 'servicedesk@domain.com';
if ( preg_match('/Client\s(.+)\@(.+)/', $t_email['X-Mantis-Body'], $pmatch) ) {
$t_email[ 'Cc' ] = $this->get_emailaddr_from_string( $pmatch[1] . "@" . $pmatch[2] );
}
if ( preg_match('/Description\s+Subject:\s+(.+)\s+Body: /', $t_email['X-Mantis-Body'], $smatch) ) {
$t_email[ 'Subject' ] = $smatch[1] . " - " . $t_email[ 'Subject' ];
}
The problem is that suddenly there is nothing in
X-Mantis-Body somehow OR maybe
$t_mp->sender is empty?! I'm running Mantis 2.25.7 right now but think it may have happened a couple of versions back. I am also not using the github version of the EmailReporting plugin code, mine is 0.11.0-DEV.
Is this something in our mailer server or is it something that the Mantis code changed a version or two ago when generating emails?
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 17:31
by mushu
Okay, after more testing you can mostly ignore the previous post above. Here is a command-line run of bug_report_mail:
Code: Select all
>php bug_report_mail.php Message.txt
Call to undefined function str_contains()
C:\MantisBT2257\plugins\EmailReporting\core\mail_api.php: 1185: ERP_mailbox_api - -> - add_monitors( <integer>5143, <array> { ['From_parsed'] => <array> { ['name'] => 'servicedesk@domain.com', ['email'] => 'servicedesk@domain.com', ['From'] => '"servicedesk@domain.com" <servicedesk@domain.com>' }, ['Reporter_id'] => 864, ['Subject'] => 'testing ticket for developer queue - (Ref:IN:00079613) Is now Assigned to Developers Queue', ['To'] => <array> { [0] => 'devbugs@domain.com', [1] => 'devbugs@domain.com' }, ['Cc'] => <array> { [0] => 'user1@domain.com' }, ['X-Mantis-Body'] => 'External Email
[Company logo]
Incident assignment change
Description
Assignment for Incident #00079613 is now Developers Queue.
Incident Details
Incident Number 00079613
Client user1@domain.com
Category
Impact
Urgency
Priority
Description Subject: testing ticket for developer queue
Body: Just drop into developer queue
===
My line 1185 is:
$this->add_monitors( $t_bug_id, $p_email );
So I'm stuck at this point. Not sure why there is an error trying to add the monitors. Any suggestions?
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 20:44
by atrol
Code: Select all
Call to undefined function str_contains()
You might use an older PHP version.
The missing function is available since PHP 8.0, see
https://www.php.net/manual/en/function.str-contains.php
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 20:53
by mushu
I thought mantis was still compatible with version 7, it's not any more?
Code: Select all
PHP 7.4.33 (cli) (built: Nov 2 2022 15:06:48) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 20:56
by atrol
The missing function is not called from MantisBT Core, its called from the plugin.
MantisBT 2.26.x requires PHP 7.2, 2.27.x will require 7.4.
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 21:18
by mushu
Okay so I added this function to the
bug_report_mail.php file near the top and it seems to be working without errors now:
Code: Select all
public function str_contains(string $haystack, string $needle): bool
{
return strlen($needle) === 0 || strpos($haystack, $needle) !== false;
}
Any reason to not just keep adding this until we're ready to upgrade php on the servers?
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 21:29
by atrol
I downloaded EmailReporting 0.10.1. from GitHub.
There is not any call of function str_contains in it.
Looks like you changed the original source code of the plugin.
Re: How to add CC: email to incoming message?
Posted: 21 Mar 2024, 21:35
by mushu
atrol wrote: ↑21 Mar 2024, 21:29
I downloaded EmailReporting 0.10.1. from GitHub.
There is not any call of function str_contains in it.
Looks like you changed the original source code of the plugin.
No. The code came from the author himself, as I showed the version of the plugin above, which is higher than the github version because he gave me a direct download link previously. I didn't change the original code other than in a very few specific places and did not add any new function calls.
Re: How to add CC: email to incoming message?
Posted: 23 Mar 2024, 15:25
by atrol
You could contact the author and ask for a solution that works with PHP 7.x.
Be aware that PHP 7.4 is out of support, so it's certainly better if you upgrade to PHP 8.x
https://www.php.net/supported-versions.php