2.4 RC BUG: %%MESSAGE%% on admin reply

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
somjue
Posts: 5
Joined: Wed Jul 18, 2012 9:11 pm

2.4 RC BUG: %%MESSAGE%% on admin reply

Post by somjue »

Script URL: internal
Version of script: 2.4 RC
What terms did you try when SEARCHING for a solution: reply mail body

Hi, I used the %%MESSAGE%% tag in email replies to display the reply directly in the e-mail.

In case of user-reply, everything works fine, but if an admin replies, the tag is replaced by the original support request instead of the reply.

Solution:
in admin/admin_reply_ticket.php search for (about line 215)

Code: Select all

hesk_notifyCustomer('new_reply_by_staff');
Insert BEFORE:

Code: Select all

/* --> Prepare reply message */
$ticket['message'] = hesk_msgToPlain($message, 1);
So everything works fine.

I also have a second problem with german special chars (ä ö ü) und ISO-8859-1 coded mails with pop3-fetching. Here i had to comment out the line

Code: Select all

$tmpvar['message'] = hesk_input($results['message']);
in inc/pipe_functions.inc.php (line 81), but that's maybe a configuration error of my server. With PHP 5.4.x I had also some codepage-errors on my own scripts. Maybe you would check it yourself.

For me now everything works fine, but you maybe would include this to your version.

btw: i also have a german translation for the 2.4 RC version (based on 2.3 with the new elements). Are you interested or would you like to wait until the final version is released? If you are interested, contact me and tell me, where I should send it.

Greetings,
Juerg
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: BUG: %%MESSAGE%% on admin reply

Post by Klemen »

Hello Juerg,

Thanks for reporting this. I will check it out and update you on what I find (probably over the weekend).

PHP 5.4 is causing a lot of problems with non-UTF 8 encoding because they changed default encoding for some functions from ISO-8859-1 to UTF-8 and now if you send anything non-UTF8 to those functions they just return an empty value. htmlspecialchars() and htmlentities() are two functions effected by this change and there is no other way to change the default encoding back to ISO-8859-1 instead by modifying source code.

You may be able to fix your scripts by changing

Code: Select all

htmlspecialchars($variable);
to

Code: Select all

htmlspecialchars($variable, ENT_COMPAT | ENT_SUBSTITUTE | ENT_XHTML, 'ISO-8859-1');
(similar for htmlentities).

As for translation - please hold on until final version is released as I may change the files more before that happens.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: 2.4 RC BUG: %%MESSAGE%% on admin reply

Post by Klemen »

Could you please confirm that German chars work with POP fetching if you change

Code: Select all

$tmpvar['message'] = hesk_input($results['message']);
to

Code: Select all

$tmpvar['message'] = hesk_input($tmpvar['message']);
in the inc/pipe_functions.php file function hesk_email2ticket?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
somjue
Posts: 5
Joined: Wed Jul 18, 2012 9:11 pm

Re: 2.4 RC BUG: %%MESSAGE%% on admin reply

Post by somjue »

Hi Klemen

Thanks for your answer. I know the additinal parameters un htmlentities/htmlspecialchars, but that means change every script file (and with php < 5.4 you'll get a notice).

I tested your change from $results to $tmpvar and it work's fine.

But I also saw, that the subject-line is also affected too. Changing line 73 from $results to $tmpvar solves this problem too.

Thanks for putting this into the next stable version. For me it's okay, I know what I have to change :)

Greetings,
Juerg
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: 2.4 RC BUG: %%MESSAGE%% on admin reply

Post by Klemen »

Yes, I will include the fix in final version.

I wish PHP team included a php.ini setting to set the default encoding for this. The way it is now PHP 5.4 will cause problems for thousands of scripts and force developers to rewrite the code :?

P.s.: here's what I used at the top of common.inc.php to avoid Notices in PHP < 5.4

Code: Select all

if ( ! defined('ENT_SUBSTITUTE'))
{
	define('ENT_SUBSTITUTE', 0);
}
if ( ! defined('ENT_XHTML'))
{
	define('ENT_XHTML', 0);
}
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
somjue
Posts: 5
Joined: Wed Jul 18, 2012 9:11 pm

Re: 2.4 RC BUG: %%MESSAGE%% on admin reply

Post by somjue »

Hi again.

Oh yes, a php.ini setting for encoding would be great. We'll see...

btw. i created an imap-fetcher, based on your pop3-fetcher. Maybe you would include this in a further version too. I used the pop3-variabled from your settings, so the naming is confusing :) If you include it to your standard-version you would maybe change it (and create a dropdown for servertype and create the check-routine). So there's something to do for you. For me that worked (in my case I configured a valid pop3-server and reconfigured my imap-server in the script; not very good, but it works).

I put the source-code in this forum, maybe it would be corruped, then I can send it to you by mail.

Greetings,
Juerg

Code: Select all

#!/usr/bin/php -q
<?php

define('IN_SCRIPT',1);
define('HESK_PATH', dirname(dirname(dirname(__FILE__))) . '/');

// Get required files and functions
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');

// should be included from hesk_settings.inc.php
/*
$hesk_settings['pop3']=1;
$hesk_settings['pop3_host_name']='imap.myserver.ch';
$hesk_settings['pop3_host_port']=143;
$hesk_settings['pop3_tls']=0;
$hesk_settings['pop3_user']='myusername';
$hesk_settings['pop3_password']='mypassword';
*/

// Is this feature enabled?
if (empty($hesk_settings['pop3']))
{
	die($hesklang['pfd']);
}

// Email piping is enabled, get other required includes
require(HESK_PATH . 'inc/pipe_functions.inc.php');

// Connecting zu Server
if ($hesk_settings['pop3_host_port'] == 993) {
	$host = "{".$hesk_settings['pop3_host_name'].":993/imap/ssl/novalidate-cert}"."INBOX";
} else {
	$host = "{".$hesk_settings['pop3_host_name'].":".$hesk_settings['pop3_host_port']."}INBOX";
}


// Connect to IMAP
if ($conn = imap_open($host, $hesk_settings['pop3_user'], $hesk_settings['pop3_password']	)) {
	echo $hesk_settings['debug_mode'] ? "<pre>Connected to the IMAP server "" . $host . "".</pre>\n" : '';
	echo $hesk_settings['debug_mode'] ? "<pre>User "" . $hesk_settings['pop3_user'] . "" logged in.</pre>\n" : '';

	// Get number of messages
	//$msgnos = imap_search($conn, 'UNSEEN');
	$msgnos = imap_search($conn, 'ALL');

	echo $hesk_settings['debug_mode'] ? "<pre>There are ".count($msgnos)." messages in the mail box.</pre>\n" : '';

	// If we have any messages, process them
	if(count($msgnos)>0) {
		// Connect to the database
		hesk_dbConnect();

		for ($msgno = 0; $msgno < count($msgnos); $msgno++) {
			echo $hesk_settings['debug_mode'] ? "<pre>Parsing message ".intval($msgno+1)." of ".count($msgnos).".</pre>\n" : '';

			// get full Message
			$message_raw = imap_fetchheader($conn, $msgnos[$msgno]).imap_body($conn, $msgnos[$msgno]);
			$fh=fopen("imap.eml","w");
			fwrite($fh, $message_raw);
			fclose($fh);

			// Parse the incoming email
			$results = parser("imap.eml");

			unlink("imap.eml");

			// Convert email into a ticket (or new reply)
			if ( $id = hesk_email2ticket($results, 1) ) {
				echo $hesk_settings['debug_mode'] ? "<pre>Ticket $id created/updated.</pre>\n" : '';
			} else {
				echo $hesk_settings['debug_mode'] ? "<pre>Ticket NOT inserted - may be duplicate, blocked or an error.</pre>\n" : '';
			}

			echo $hesk_settings['debug_mode'] ? "<br /><br />\n\n" : '';

			imap_delete($conn, $msgnos[$msgno]);  // mark the current message for deletion
		}

		imap_expunge($conn);  // delete all messages marked for deletion


	}

	imap_close($conn);
	echo $hesk_settings['debug_mode'] ? "<pre>Disconnected from the IMAP server "" . $host. "".</pre>\n" : '';
} else {
	$error=imap_errors()[0];
}

// Any error messages?
if($error != '')
{
	echo "<h2>Error: " . htmlspecialchars($error) . "</h2>";
}
return NULL;
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: 2.4 RC BUG: %%MESSAGE%% on admin reply

Post by Klemen »

Thanks for sharing - I didn't have the means to test imap yet so it won't be included in 2.4, but something that can easily be added in the future. And your modification will help people who need this until it's officially included.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
somjue
Posts: 5
Joined: Wed Jul 18, 2012 9:11 pm

Re: 2.4 RC BUG: %%MESSAGE%% on admin reply

Post by somjue »

No Problem, add it any time you want, it's not very important (but pop3 is not standard anymore and with imap you have the possibility to move it to another folder after parsing...)

btw two remarks:
1) because your parser-function requires a eml-file or a stream I saved the message as imap.eml in the actual directory. this would maybe get a permission-error on other installations. a temp directory would be better.

2) there's also another imap plugin in the forum. this version hat it's own parsing-engine and is maybe outdated. my extension use your parsing- and adding-functions and should be better.

Greetings,
Juerg
Post Reply