Jump to content

Customer Service module doesnt receive message from email


Recommended Posts

Hi,

 

Im running prestashop 1.5.6 and having problem with customer service module

I can send message out from prestashop to my email, but when i reply the mail it doesnt go into prestashop customer service module

 

Im not sure how to configure it but when i click sync, it show success (screenshot attached in this message)

 

 

Please help

 

 

 

Thanks

post-717809-0-69546000-1384177903_thumb.png

Link to comment
Share on other sites

  • 3 weeks later...

I am having a similar issue on version 1.5.6.1  I can receive and reply to messages when the messages are sent using the contact page. Messages from an email client or the mailto link on my page do not show up in the customer service module, even though my IMAP settings are correct and the sync button says success.  Thanks in advance

Link to comment
Share on other sites

there seems to be some cross talk on this thread...so this may help someone

 

The customer thread requires that the customer do initial contact and subsequent replies using the contact form.

 

This is my understanding of how the back office customer thread is maintained.

Link to comment
Share on other sites

there seems to be some cross talk on this thread...so this may help someone

 

The customer thread requires that the customer do initial contact and subsequent replies using the contact form.

 

This is my understanding of how the back office customer thread is maintained.

 

Hi El Patron,

 

I'm sorry, but I think you are wrong on that, at least that's not how it was initially intented for my understanding, infact since long time an option exists in BO that say:

"Create new threads" (Create new threads for unrecognized emails )

that should do exactly what the op asks but it doesn't work, due to some errors in adminCustomersThreadsController.php

 

When you check that option the PS_SAV_IMAP_CREATE_THREADS variable is correctly set, and indeed messages are really scanned and imported and customer threads created in database for "unrecognized mails" but they never show on BO because the shop_id is 0 for those ct and some other bug inside the controller

 

to fix that create the folders: override/controllers/admin/

 

inside that folder create a file AdminCustomerThreadsController.php

 

open it and paste the following:

<?php

class AdminCustomerThreadsController extends AdminCustomerThreadsControllerCore {

	public function ajaxProcessSyncImap()
	{
		if ($this->tabAccess['edit'] != '1')
			throw new PrestaShopException(Tools::displayError('You do not have permission to edit this.'));

		if (Tools::isSubmit('syncImapMail'))
		{
			if (!($url = Configuration::get('PS_SAV_IMAP_URL'))
			|| !($port = Configuration::get('PS_SAV_IMAP_PORT'))
			|| !($user = Configuration::get('PS_SAV_IMAP_USER'))
			|| !($password = Configuration::get('PS_SAV_IMAP_PWD')))
			die('{"hasError" : true, "errors" : ["Configuration is not correct"]}');

			$conf = Configuration::getMultiple(array(
				'PS_SAV_IMAP_OPT_NORSH', 'PS_SAV_IMAP_OPT_SSL',
				'PS_SAV_IMAP_OPT_VALIDATE-CERT', 'PS_SAV_IMAP_OPT_NOVALIDATE-CERT',
				'PS_SAV_IMAP_OPT_TLS', 'PS_SAV_IMAP_OPT_NOTLS'));
	
			$conf_str = '';
			if ($conf['PS_SAV_IMAP_OPT_NORSH'])
				$conf_str .= '/norsh';
			if ($conf['PS_SAV_IMAP_OPT_SSL'])
				$conf_str .= '/ssl';
			if ($conf['PS_SAV_IMAP_OPT_VALIDATE-CERT'])
				$conf_str .= '/validate-cert';
			if ($conf['PS_SAV_IMAP_OPT_NOVALIDATE-CERT'])
				$conf_str .= '/novalidate-cert';
			if ($conf['PS_SAV_IMAP_OPT_TLS'])
				$conf_str .= '/tls';
			if ($conf['PS_SAV_IMAP_OPT_NOTLS'])
				$conf_str .= '/notls';

			if (!function_exists('imap_open'))
				die('{"hasError" : true, "errors" : ["imap is not installed on this server"]}');

			$mbox = @imap_open('{'.$url.':'.$port.$conf_str.'}', $user, $password);

			//checks if there is no error when connecting imap server
			$errors = imap_errors();
			$str_errors = '';
			$str_error_delete = '';
			if (sizeof($errors) && is_array($errors))
			{
				$str_errors = '';
				foreach($errors as $error)
					$str_errors .= '"'.$error.'",';
				$str_errors = rtrim($str_errors, ',').'';
			}
			//checks if imap connexion is active
			if (!$mbox)
				die('{"hasError" : true, "errors" : ["Cannot connect to the mailbox:.<br />'.addslashes($str_errors).'"]}');

			//Returns information about the current mailbox. Returns FALSE on failure.
			$check = imap_check($mbox);
			if (!$check)
				die('{"hasError" : true, "errors" : ["Fail to get information about the current mailbox"]}');

			if ($check->Nmsgs == 0)
				die('{"hasError" : true, "errors" : ["NO message to sync"]}');

			$result = imap_fetch_overview($mbox,"1:{$check->Nmsgs}",0);
			foreach ($result as $overview)
			{	
				
				 //check if message exist in database
				 if (isset($overview->subject))
						$subject = $overview->subject;
					else
						$subject = '';
				//Creating an md5 to check if message has been allready processed
				 $md5 = md5($overview->date.$overview->from.$subject.$overview->msgno);
				 $exist = Db::getInstance()->getValue(
						 'SELECT `md5_header`
						 FROM `'._DB_PREFIX_.'customer_message_sync_imap`
						 WHERE `md5_header` = \''.pSQL($md5).'\'');
				 if ($exist) {
					if (Configuration::get('PS_SAV_IMAP_DELETE_MSG'))
						if (!imap_delete($mbox, $overview->msgno))
							$str_error_delete = ', "Fail to delete message"';
				 } else {
				 	//check if subject has id_order
				 	preg_match('/\#ct([0-9]*)/', $subject, $matches1);
				 	preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2);
					
					$matchFound = false;
					if (isset($matches1[1]) && isset($matches2[1]))
						$matchFound = true;
					
					$new_ct = ( Configuration::get('PS_SAV_IMAP_CREATE_THREADS') && !$matchFound && (strpos($subject, '[no_sync]') == false));				
					
					if ( $matchFound || $new_ct)
					{
						if ($new_ct)
						{
							if (!preg_match('/<('.Tools::cleanNonUnicodeSupport('[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z0-9]+').')>/', $overview->from, $result)|| !Validate::isEmail($from = $result[1]))
								continue;
									
							$contacts = Contact::getContacts($this->context->language->id);
							if (!$contacts)
								continue;
								
							foreach ($contacts as $contact) {
								if (strpos($overview->to , $contact['email']) !== false)
									$id_contact = $contact['id_contact'];
							}
							
							if (!isset($id_contact))							
								$id_contact = $contacts[0]['id_contact'];
								
							$customer = new Customer;
								
							$client = $customer->getByEmail($from);

							$ct = new CustomerThread();
							if (isset($client->id))
								$ct->id_customer = $client->id;
							$ct->email = $from;
							$ct->id_contact = $id_contact;
							$ct->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
							$ct->id_shop = $this->context->shop->id;
							$ct->status = 'open';
							$ct->token = Tools::passwdGen(12);
							$ct->add();	
						}
						else
							$ct = new CustomerThread((int)$matches1[1]); //check if order exist in database

						if (Validate::isLoadedObject($ct) && ((isset($matches2[1]) && $ct->token == $matches2[1]) || $new_ct))
						{
							$message = imap_fetchbody($mbox, $overview->msgno, 1);
							$message = quoted_printable_decode($message);
							$message = utf8_encode($message);
							$message = quoted_printable_decode($message);
							$message = nl2br($message);
							$cm = new CustomerMessage();
							$cm->id_customer_thread = $ct->id;
							$cm->message = $message;
							$cm->add();
						}
					}
					Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` (`md5_header`) VALUES (\''.pSQL($md5).'\')');
				}
			}
			imap_expunge($mbox);
			imap_close($mbox);
			die('{"hasError" : false, "errors" : ["'.$str_errors.$str_error_delete.'"]}');
		}
	}
}

save it go in cache folder and delete the class_index file (it will be recreated automatically)

 

This Override does 3 things:

1) show in backoffice message sent to customer service even if directly sent by mail without using the contact page

Than I added 2 new functionalities to that:

2) it is now able to insert the message in the right customer thread "category" (if you have more than one like support or suggestions etc..) depending on the mail the message is directed to.

3) it is now able to detect if the mail sending the message is owned by one of the registered customer and assign it to him showing customer details correctly (like customer name)

 

Enjoy!

 

ps: I'm going to ask to merge this in the github repository if I'm able to understand the new branching system.... :lol:

Edited by misthero (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

Hi Misthero,

 

I followed your method but it doesn't work. Sending from my email client still doesn't show up using sync. 

 

 

 

I followed your instruction.

 

-double check the class_index file.

-Create new threads Yes

 

Do you know what may be the problem?

Edited by samuel89 (see edit history)
Link to comment
Share on other sites

Dont worry about it. It works. for newer messages. Just not previous ones before the above steps are done.

 

But can the sync be runn automatically or using a cronjob or it needs to be manually pressed every signle time.

 

Thannks.

 

hello, I'm glad it worked, i have answered this question in another topic, is not the ideal solution but a workaround to make it sync semi-automatically without pressing the sync button, you can find the solution here:

 

http://www.prestashop.com/forums/topic/282002-auto-retrieve-customer-mails-in-customer-service/?do=findComment&comment=1495152

Link to comment
Share on other sites

I've modified this to re-open a thread when customer replies. Currently the thread is still marked closed even after a customer reply.

                                                else {
                                                        $ct = new CustomerThread((int)$matches1[1]); //check if order exist in database
                                                        $ct->status = 'open';
                                                        $ct->save();
                                                }
Edited by _Zico_ (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Thanks for sharing ,made my day, but i got a problem if customer its replying to my answer by email will start a new thread wont add the message to the thread ive replied from. Best Regards

 

mm... it's possible , have to check, is the message connected to an order (i mean the orignal one), can you show us the subject? it should contain a string like #ct..something #tc..something

Link to comment
Share on other sites

Excuse my english. Ill try to explan how ive tested your hack

 

1. ive sent an email from [email protected] (email never used in prestahsop ) to [email protected] ( shop customer service email )

2. login in BO synced the email

3. new message with green icon appeared in message centre

4. i have sent a replay from BO to that message ( thread go in closed status after message sent )

5. received an email mesage from [email protected] ( with subject as you said tc ct )

6. sent a reply from that email message ( subject was intact , only Re added default by email service )

7. login in BO synced the email

8. the message sent step 6 received as a new thread not added to thread i first replied in setp 4

 

Hope you understand

 

I have tested without modification as _zyco_ said in a previous post and also with that modification ( when ive tested i have deleted all message form my shop and used another email address to make the test ( new email generated from my hosting account ). Also i tested the email with yahoo and hotmail email account

no luck

 

this is my code

<?php

class AdminCustomerThreadsController extends AdminCustomerThreadsControllerCore {

	public function ajaxProcessSyncImap()
	{
		if ($this->tabAccess['edit'] != '1')
			throw new PrestaShopException(Tools::displayError('You do not have permission to edit this.'));

		if (Tools::isSubmit('syncImapMail'))
		{
			if (!($url = Configuration::get('PS_SAV_IMAP_URL'))
			|| !($port = Configuration::get('PS_SAV_IMAP_PORT'))
			|| !($user = Configuration::get('PS_SAV_IMAP_USER'))
			|| !($password = Configuration::get('PS_SAV_IMAP_PWD')))
			die('{"hasError" : true, "errors" : ["Configuration is not correct"]}');

			$conf = Configuration::getMultiple(array(
				'PS_SAV_IMAP_OPT_NORSH', 'PS_SAV_IMAP_OPT_SSL',
				'PS_SAV_IMAP_OPT_VALIDATE-CERT', 'PS_SAV_IMAP_OPT_NOVALIDATE-CERT',
				'PS_SAV_IMAP_OPT_TLS', 'PS_SAV_IMAP_OPT_NOTLS'));
	
			$conf_str = '';
			if ($conf['PS_SAV_IMAP_OPT_NORSH'])
				$conf_str .= '/norsh';
			if ($conf['PS_SAV_IMAP_OPT_SSL'])
				$conf_str .= '/ssl';
			if ($conf['PS_SAV_IMAP_OPT_VALIDATE-CERT'])
				$conf_str .= '/validate-cert';
			if ($conf['PS_SAV_IMAP_OPT_NOVALIDATE-CERT'])
				$conf_str .= '/novalidate-cert';
			if ($conf['PS_SAV_IMAP_OPT_TLS'])
				$conf_str .= '/tls';
			if ($conf['PS_SAV_IMAP_OPT_NOTLS'])
				$conf_str .= '/notls';

			if (!function_exists('imap_open'))
				die('{"hasError" : true, "errors" : ["imap is not installed on this server"]}');

			$mbox = @imap_open('{'.$url.':'.$port.$conf_str.'}', $user, $password);

			//checks if there is no error when connecting imap server
			$errors = imap_errors();
			$str_errors = '';
			$str_error_delete = '';
			if (sizeof($errors) && is_array($errors))
			{
				$str_errors = '';
				foreach($errors as $error)
					$str_errors .= '"'.$error.'",';
				$str_errors = rtrim($str_errors, ',').'';
			}
			//checks if imap connexion is active
			if (!$mbox)
				die('{"hasError" : true, "errors" : ["Cannot connect to the mailbox:.<br />'.addslashes($str_errors).'"]}');

			//Returns information about the current mailbox. Returns FALSE on failure.
			$check = imap_check($mbox);
			if (!$check)
				die('{"hasError" : true, "errors" : ["Fail to get information about the current mailbox"]}');

			if ($check->Nmsgs == 0)
				die('{"hasError" : true, "errors" : ["NO message to sync"]}');

			$result = imap_fetch_overview($mbox,"1:{$check->Nmsgs}",0);
			foreach ($result as $overview)
			{	
				
				 //check if message exist in database
				 if (isset($overview->subject))
						$subject = $overview->subject;
					else
						$subject = '';
				//Creating an md5 to check if message has been allready processed
				 $md5 = md5($overview->date.$overview->from.$subject.$overview->msgno);
				 $exist = Db::getInstance()->getValue(
						 'SELECT `md5_header`
						 FROM `'._DB_PREFIX_.'customer_message_sync_imap`
						 WHERE `md5_header` = \''.pSQL($md5).'\'');
				 if ($exist) {
					if (Configuration::get('PS_SAV_IMAP_DELETE_MSG'))
						if (!imap_delete($mbox, $overview->msgno))
							$str_error_delete = ', "Fail to delete message"';
				 } else {
				 	//check if subject has id_order
				 	preg_match('/\#ct([0-9]*)/', $subject, $matches1);
				 	preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2);
					
					$matchFound = false;
					if (isset($matches1[1]) && isset($matches2[1]))
						$matchFound = true;
					
					$new_ct = ( Configuration::get('PS_SAV_IMAP_CREATE_THREADS') && !$matchFound && (strpos($subject, '[no_sync]') == false));				
					
					if ( $matchFound || $new_ct)
					{
						if ($new_ct)
						{
							if (!preg_match('/<('.Tools::cleanNonUnicodeSupport('[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z0-9]+').')>/', $overview->from, $result)|| !Validate::isEmail($from = $result[1]))
								continue;
									
							$contacts = Contact::getContacts($this->context->language->id);
							if (!$contacts)
								continue;
								
							foreach ($contacts as $contact) {
								if (strpos($overview->to , $contact['email']) !== false)
									$id_contact = $contact['id_contact'];
							}
							
							if (!isset($id_contact))							
								$id_contact = $contacts[0]['id_contact'];
								
							$customer = new Customer;
								
							$client = $customer->getByEmail($from);

							$ct = new CustomerThread();
							if (isset($client->id))
								$ct->id_customer = $client->id;
							$ct->email = $from;
							$ct->id_contact = $id_contact;
							$ct->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
							$ct->id_shop = $this->context->shop->id;
							$ct->status = 'open';
							$ct->token = Tools::passwdGen(12);
							$ct->add();	
						}
						else
							{
$ct = new CustomerThread((int)$matches1[1]); //check if order exist in database
$ct->status = 'open';
$ct->save();
}

						if (Validate::isLoadedObject($ct) && ((isset($matches2[1]) && $ct->token == $matches2[1]) || $new_ct))
						{
							$message = imap_fetchbody($mbox, $overview->msgno, 1);
							$message = quoted_printable_decode($message);
							$message = utf8_encode($message);
							$message = quoted_printable_decode($message);
							$message = nl2br($message);
							$cm = new CustomerMessage();
							$cm->id_customer_thread = $ct->id;
							$cm->message = $message;
							$cm->add();
						}
					}
					Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` (`md5_header`) VALUES (\''.pSQL($md5).'\')');
				}
			}
			imap_expunge($mbox);
			imap_close($mbox);
			die('{"hasError" : false, "errors" : ["'.$str_errors.$str_error_delete.'"]}');
		}
	}
}
Link to comment
Share on other sites

thank you for the amount of details, i found why it is giving the problem, but i don't know yet how to fix, something has changed in the way mails are received

 

customer thread controller is looking for #tc and #ct in subject but it cannot find it because lately the subject read from the system is like this

Re: [site_name] =?UTF-8?B?w4ggZGlzcG9uaWJpbGUgdW5hIHJpc3Bvc3Rh?= =?UTF-8?B?IGFsIHR1byBtZXNzYWdnaW8gI2N0MSAjdGNOR1NBQmNNajRDMzUu?=

it is something to do wih swiftmailer and some change made lately, but i have yet to figure out where is the problem..

Link to comment
Share on other sites

Thank you so much for trying and hopefully you will find a solution

 

Best Regards

 

ok you can try this:

 

go around line 85 you should see:

                     //check if subject has id_order
                     preg_match('/\#ct([0-9]*)/', $subject, $matches1);
                     preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2);

replace with this

                     //check if subject has id_order
                    $subject = iconv_mime_decode($subject); //added to fix imap message encoding ??
                     preg_match('/\#ct([0-9]*)/', $subject, $matches1);
                     preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2);

let me know if it works for you

Link to comment
Share on other sites

its working thats.

anyway the message its displayed quite strange in BO but its understable

1.first message that ive from my email account -  body { font-family: "Calibri","Slate Pro","sans-serif"; color:#262626 } I have one question ?

because ive sent it using another colour that i have in my email ?

2.second message that ive sent it after i received a reply from BO - Perfect - the my signature from email addres then  From: Asistentă CliențiSent: duminică 

this its because i translate in romanian language no ?
Link to comment
Share on other sites

  • 1 month later...

ajaxProcessSyncImap() this function doesn't exist in the file AdminCustomerThreadsController.php in the 1.5.2 ...

 

it call : "POST",url:"ajax.php",data:"syncImapMail=1"

 

and with ajax.php modified it won't work

 

that function has been introduced in 1.5.4 this thread is about version 1.5.6

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

Hi El Patron,

 

I'm sorry, but I think you are wrong on that, at least that's not how it was initially intented for my understanding, infact since long time an option exists in BO that say:

"Create new threads" (Create new threads for unrecognized emails )

that should do exactly what the op asks but it doesn't work, due to some errors in adminCustomersThreadsController.php

 

When you check that option the PS_SAV_IMAP_CREATE_THREADS variable is correctly set, and indeed messages are really scanned and imported and customer threads created in database for "unrecognized mails" but they never show on BO because the shop_id is 0 for those ct and some other bug inside the controller

 

to fix that create the folders: override/controllers/admin/

 

inside that folder create a file AdminCustomerThreadsController.php

 

open it and paste the following:

<?php

class AdminCustomerThreadsController extends AdminCustomerThreadsControllerCore {

	public function ajaxProcessSyncImap()
	{
		if ($this->tabAccess['edit'] != '1')
			throw new PrestaShopException(Tools::displayError('You do not have permission to edit this.'));

		if (Tools::isSubmit('syncImapMail'))
		{
			if (!($url = Configuration::get('PS_SAV_IMAP_URL'))
			|| !($port = Configuration::get('PS_SAV_IMAP_PORT'))
			|| !($user = Configuration::get('PS_SAV_IMAP_USER'))
			|| !($password = Configuration::get('PS_SAV_IMAP_PWD')))
			die('{"hasError" : true, "errors" : ["Configuration is not correct"]}');

			$conf = Configuration::getMultiple(array(
				'PS_SAV_IMAP_OPT_NORSH', 'PS_SAV_IMAP_OPT_SSL',
				'PS_SAV_IMAP_OPT_VALIDATE-CERT', 'PS_SAV_IMAP_OPT_NOVALIDATE-CERT',
				'PS_SAV_IMAP_OPT_TLS', 'PS_SAV_IMAP_OPT_NOTLS'));
	
			$conf_str = '';
			if ($conf['PS_SAV_IMAP_OPT_NORSH'])
				$conf_str .= '/norsh';
			if ($conf['PS_SAV_IMAP_OPT_SSL'])
				$conf_str .= '/ssl';
			if ($conf['PS_SAV_IMAP_OPT_VALIDATE-CERT'])
				$conf_str .= '/validate-cert';
			if ($conf['PS_SAV_IMAP_OPT_NOVALIDATE-CERT'])
				$conf_str .= '/novalidate-cert';
			if ($conf['PS_SAV_IMAP_OPT_TLS'])
				$conf_str .= '/tls';
			if ($conf['PS_SAV_IMAP_OPT_NOTLS'])
				$conf_str .= '/notls';

			if (!function_exists('imap_open'))
				die('{"hasError" : true, "errors" : ["imap is not installed on this server"]}');

			$mbox = @imap_open('{'.$url.':'.$port.$conf_str.'}', $user, $password);

			//checks if there is no error when connecting imap server
			$errors = imap_errors();
			$str_errors = '';
			$str_error_delete = '';
			if (sizeof($errors) && is_array($errors))
			{
				$str_errors = '';
				foreach($errors as $error)
					$str_errors .= '"'.$error.'",';
				$str_errors = rtrim($str_errors, ',').'';
			}
			//checks if imap connexion is active
			if (!$mbox)
				die('{"hasError" : true, "errors" : ["Cannot connect to the mailbox:.<br />'.addslashes($str_errors).'"]}');

			//Returns information about the current mailbox. Returns FALSE on failure.
			$check = imap_check($mbox);
			if (!$check)
				die('{"hasError" : true, "errors" : ["Fail to get information about the current mailbox"]}');

			if ($check->Nmsgs == 0)
				die('{"hasError" : true, "errors" : ["NO message to sync"]}');

			$result = imap_fetch_overview($mbox,"1:{$check->Nmsgs}",0);
			foreach ($result as $overview)
			{	
				
				 //check if message exist in database
				 if (isset($overview->subject))
						$subject = $overview->subject;
					else
						$subject = '';
				//Creating an md5 to check if message has been allready processed
				 $md5 = md5($overview->date.$overview->from.$subject.$overview->msgno);
				 $exist = Db::getInstance()->getValue(
						 'SELECT `md5_header`
						 FROM `'._DB_PREFIX_.'customer_message_sync_imap`
						 WHERE `md5_header` = \''.pSQL($md5).'\'');
				 if ($exist) {
					if (Configuration::get('PS_SAV_IMAP_DELETE_MSG'))
						if (!imap_delete($mbox, $overview->msgno))
							$str_error_delete = ', "Fail to delete message"';
				 } else {
				 	//check if subject has id_order
				 	preg_match('/\#ct([0-9]*)/', $subject, $matches1);
				 	preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2);
					
					$matchFound = false;
					if (isset($matches1[1]) && isset($matches2[1]))
						$matchFound = true;
					
					$new_ct = ( Configuration::get('PS_SAV_IMAP_CREATE_THREADS') && !$matchFound && (strpos($subject, '[no_sync]') == false));				
					
					if ( $matchFound || $new_ct)
					{
						if ($new_ct)
						{
							if (!preg_match('/<('.Tools::cleanNonUnicodeSupport('[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z0-9]+').')>/', $overview->from, $result)|| !Validate::isEmail($from = $result[1]))
								continue;
									
							$contacts = Contact::getContacts($this->context->language->id);
							if (!$contacts)
								continue;
								
							foreach ($contacts as $contact) {
								if (strpos($overview->to , $contact['email']) !== false)
									$id_contact = $contact['id_contact'];
							}
							
							if (!isset($id_contact))							
								$id_contact = $contacts[0]['id_contact'];
								
							$customer = new Customer;
								
							$client = $customer->getByEmail($from);

							$ct = new CustomerThread();
							if (isset($client->id))
								$ct->id_customer = $client->id;
							$ct->email = $from;
							$ct->id_contact = $id_contact;
							$ct->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
							$ct->id_shop = $this->context->shop->id;
							$ct->status = 'open';
							$ct->token = Tools::passwdGen(12);
							$ct->add();	
						}
						else
							$ct = new CustomerThread((int)$matches1[1]); //check if order exist in database

						if (Validate::isLoadedObject($ct) && ((isset($matches2[1]) && $ct->token == $matches2[1]) || $new_ct))
						{
							$message = imap_fetchbody($mbox, $overview->msgno, 1);
							$message = quoted_printable_decode($message);
							$message = utf8_encode($message);
							$message = quoted_printable_decode($message);
							$message = nl2br($message);
							$cm = new CustomerMessage();
							$cm->id_customer_thread = $ct->id;
							$cm->message = $message;
							$cm->add();
						}
					}
					Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` (`md5_header`) VALUES (\''.pSQL($md5).'\')');
				}
			}
			imap_expunge($mbox);
			imap_close($mbox);
			die('{"hasError" : false, "errors" : ["'.$str_errors.$str_error_delete.'"]}');
		}
	}
}

save it go in cache folder and delete the class_index file (it will be recreated automatically)

 

This Override does 3 things:

1) show in backoffice message sent to customer service even if directly sent by mail without using the contact page

Than I added 2 new functionalities to that:

2) it is now able to insert the message in the right customer thread "category" (if you have more than one like support or suggestions etc..) depending on the mail the message is directed to.

3) it is now able to detect if the mail sending the message is owned by one of the registered customer and assign it to him showing customer details correctly (like customer name)

 

Enjoy!

 

ps: I'm going to ask to merge this in the github repository if I'm able to understand the new branching system.... :lol:

Hi Great post, Now I am getting messages at both places customer service, and order page when a customer sends me a message during checkout ,

But when  I sends a reply, on customer order history page in From clumn it says custoemr name instad of support or site webmaster name.in message reply column.

post-411458-0-59343300-1404370761_thumb.jpg

post-411458-0-24814700-1404370764_thumb.jpg

Edited by lovemyseo (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Wondering the same thing, has anyone tried this on 1.6? Is it even needed on 1.6?

 

There seems to be a major issue left to fix in the code and that is when replies contains attachments the decoding of the message fails.

I suggest us doing a gist for this class including all the fixes mentioned then we could improve it from there.

Edited by _Zico_ (see edit history)
Link to comment
Share on other sites

this is already included in ps 1.6: https://github.com/PrestaShop/PrestaShop/blob/1.6/controllers/admin/AdminCustomerThreadsController.php

 

anyway if you have problem with attachments can you try changing this line:

$message = imap_fetchbody($mbox, $overview->msgno, 1);

with this

$message = imap_fetchbody($mbox, $overview->msgno, 1.2);

and report the results?

Link to comment
Share on other sites

this is already included in ps 1.6: https://github.com/PrestaShop/PrestaShop/blob/1.6/controllers/admin/AdminCustomerThreadsController.php

 

anyway if you have problem with attachments can you try changing this line:

$message = imap_fetchbody($mbox, $overview->msgno, 1);

with this

$message = imap_fetchbody($mbox, $overview->msgno, 1.2);

and report the results?

 

Yeah just found it yesterday. Currently I experience problem syncing. Getting parse errors. And one email keeps repeating it self every time I sync. This happens even after cleaning out my imap folder. Still the same email comes back and presta complains about parse error.

Link to comment
Share on other sites

  • 2 weeks later...

Hi!

 

Any advise here?

 

The interesting thing is that while testing this feature with a clean 1.6 installation (not upgraded from 1.5) it works as a charm. Whereas, and upgraded from 1.5 gives such Technical Error.

In fact, it was partly a reason why I have decided to move from 1.5 to 1.6 and now it is a bit disappointing.

 

It seems that upgrading doesn't fix this issue in some certain files - do you have an idea where to look?

The peak season is approaching and to handle all requests without a common "gate" will be too challenging.

 

Thank you in advance!

Link to comment
Share on other sites

  • 2 months later...

Hi!

 

Any advise here?

 

The interesting thing is that while testing this feature with a clean 1.6 installation (not upgraded from 1.5) it works as a charm. Whereas, and upgraded from 1.5 gives such Technical Error.

In fact, it was partly a reason why I have decided to move from 1.5 to 1.6 and now it is a bit disappointing.

 

It seems that upgrading doesn't fix this issue in some certain files - do you have an idea where to look?

The peak season is approaching and to handle all requests without a common "gate" will be too challenging.

 

Thank you in advance!

Hi

 

I have the same problem in the 1.6.9; did you fix it?

 

Thanks

Angela

Link to comment
Share on other sites

Hi!

 

Yes, my hosting company had to change Firewall settings as my mailboxes are hosted elsewhere.

 

Sometimes I still get this error when there are messages with attachments. Login, delete them and start again.

Ok thanks

 

I will try it.

Link to comment
Share on other sites

  • 1 month later...

Hi,

I was also having trouble with the same issue. I am using 1.6.0.9. I have updated it from 1.5.0.6 version. 

I uploaded the file from github to my Admin controller. It did not solve the problem of sending the messages to a particular category. 

Then I uploaded the changes suggested by Misthero. But this also did not solve this problem. Can anyone guide me for this issue. 

FYI: I am not using any IMAP settings.

Link to comment
Share on other sites

  • 4 months later...
  • 11 months later...

Hello. I am new to the prestashop. A new module uses Mail::send() function to mail some data. Also the data is stored in 'mail' table and shown in the 'email' tab. In the code I can't understand the portion that saves into the database table.Anyone can help me?

Thanks in advance.

Link to comment
Share on other sites

  • 5 months later...

change

 

$mbox = @imap_open('{'.$url.':'.$port.$conf_str.'}', $user, $password);

 

to

 

$mbox = @imap_open('{'.$url.':'.$port.$conf_str.'/novalidate-cert}', $user, $password);

 

in AdminCustomerThreadsController.php 

 

 

if see error "prestashop Cannot connect to the mailbox : Certificate failure for yourshop.com: self signed certificate: /OU=IMAP server/CN=imap.example.com/[email protected]"

 

 

works in 1.6.1.9

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...