How to add CC: email to incoming message?

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

Moderators: Contributor, Developer

Post Reply
mushu
Posts: 142
Joined: Jan 04, 2017 12:41 pm

How to add CC: email to incoming message?

Post by mushu » Jan 15, 2019 5:46 pm

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?

SL-Gundam
Posts: 553
Joined: Jul 06, 2011 9:17 am

Re: How to add CC: email to incoming message?

Post by SL-Gundam » Jan 16, 2019 6:42 am

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() );

mushu
Posts: 142
Joined: Jan 04, 2017 12:41 pm

Re: How to add CC: email to incoming message?

Post by mushu » Jan 16, 2019 2:36 pm

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' ] );
?

mushu
Posts: 142
Joined: Jan 04, 2017 12:41 pm

Re: How to add CC: email to incoming message?

Post by mushu » Jan 16, 2019 2:44 pm

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!

Post Reply