public function __construct()
    {
        $this->bootstrap = true;
        if (Configuration::get('PS_LOG_EMAILS')) {
            $this->table = 'mail';
            $this->className = 'Mail';
            $this->lang = false;
            $this->noLink = true;
            $this->list_no_link = true;
            $this->explicitSelect = true;
            $this->addRowAction('delete');
            $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
            foreach (Language::getLanguages() as $language) {
                $languages[$language['id_lang']] = $language['name'];
            }
            $this->fields_list = array('id_mail' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'recipient' => array('title' => $this->l('Recipient')), 'template' => array('title' => $this->l('Template')), 'language' => array('title' => $this->l('Language'), 'type' => 'select', 'color' => 'color', 'list' => $languages, 'filter_key' => 'a!id_lang', 'filter_type' => 'int', 'order_key' => 'language'), 'subject' => array('title' => $this->l('Subject')), 'date_add' => array('title' => $this->l('Sent'), 'type' => 'datetime'));
            $this->_select .= 'l.name as language';
            $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (a.id_lang = l.id_lang)';
            $this->_use_found_rows = false;
        }
        parent::__construct();
        foreach (Contact::getContacts($this->context->language->id) as $contact) {
            $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']);
        }
        $this->fields_options = array('email' => array('title' => $this->l('Email'), 'icon' => 'icon-envelope', 'fields' => array('PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send email to'), 'desc' => $this->l('Where customers send messages from the order page.'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr), 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(3 => $this->l('Never send emails (may be useful for testing purposes)'), 2 => $this->l('Set my own SMTP parameters (for advanced users ONLY)'))), 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(Mail::TYPE_HTML => $this->l('Send email in HTML format'), Mail::TYPE_TEXT => $this->l('Send email in text format'), Mail::TYPE_BOTH => $this->l('Both'))), 'PS_LOG_EMAILS' => array('title' => $this->l('Log Emails'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool')), 'submit' => array('title' => $this->l('Save'))), 'smtp' => array('title' => $this->l('Email'), 'fields' => array('PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain name'), 'hint' => $this->l('Fully qualified domain name (keep this field empty if you don\'t know).'), 'empty' => true, 'validation' => 'isUrl', 'type' => 'text'), 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server'), 'hint' => $this->l('IP address or server name (e.g. smtp.mydomain.com).'), 'validation' => 'isGenericName', 'type' => 'text'), 'PS_MAIL_USER' => array('title' => $this->l('SMTP username'), 'hint' => $this->l('Leave blank if not applicable.'), 'validation' => 'isGenericName', 'type' => 'text'), 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password'), 'hint' => $this->l('Leave blank if not applicable.'), 'validation' => 'isAnything', 'type' => 'password', 'autocomplete' => false), 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption'), 'hint' => $this->l('Use an encrypt protocol'), 'desc' => extension_loaded('openssl') ? '' : '/!\\ ' . $this->l('SSL does not seem to be available on your server.'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL')))), 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port'), 'hint' => $this->l('Port number to use.'), 'validation' => 'isInt', 'type' => 'text', 'cast' => 'intval', 'class' => 'fixed-width-sm')), 'submit' => array('title' => $this->l('Save'))), 'test' => array('title' => $this->l('Test your email configuration'), 'hide_multishop_checkbox' => true, 'fields' => array('PS_SHOP_EMAIL' => array('title' => $this->l('Send a test email to'), 'type' => 'text', 'id' => 'testEmail', 'no_multishop_checkbox' => true)), 'bottom' => '<div class="row"><div class="col-lg-9 col-lg-offset-3">
					<div class="alert" id="mailResultCheck" style="display:none;"></div>
				</div></div>', 'buttons' => array(array('title' => $this->l('Send a test email'), 'icon' => 'process-icon-envelope', 'name' => 'btEmailTest', 'js' => 'verifyMail()', 'class' => 'btn btn-default pull-right'))));
        if (!defined('_PS_HOST_MODE_')) {
            $this->fields_options['email']['fields']['PS_MAIL_METHOD']['choices'][1] = $this->l('Use PHP\'s mail() function (recommended; works in most cases)');
        }
        ksort($this->fields_options['email']['fields']['PS_MAIL_METHOD']['choices']);
    }
Exemplo n.º 2
0
    public function __construct()
    {
        $this->className = 'Configuration';
        $this->table = 'configuration';
        parent::__construct();
        foreach (Contact::getContacts($this->context->language->id) as $contact) {
            $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']);
        }
        $this->fields_options = array('email' => array('title' => $this->l('E-mail'), 'icon' => 'email', 'fields' => array('PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to'), 'desc' => $this->l('Where customers send messages from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr), 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Use PHP mail() function.  Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#smtp\').slideUp();"', 2 => 'onclick="$(\'#smtp\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(Mail::TYPE_HTML => $this->l('Send e-mail as HTML'), Mail::TYPE_TEXT => $this->l('Send e-mail as Text'), Mail::TYPE_BOTH => $this->l('Both')))), 'submit' => array()), 'smtp' => array('title' => $this->l('E-mail'), 'icon' => 'email', 'top' => '<div id="smtp" style="display: ' . (Configuration::get('PS_MAIL_METHOD') == 2 ? 'block' : 'none') . ';">', 'bottom' => '</div>', 'fields' => array('PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain name:'), 'desc' => $this->l('Fully qualified domain name (keep empty if you do not know)'), 'empty' => true, 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP address or server name (e.g. smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'******'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'******'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL, 'autocomplete' => false), 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Port number to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL)), 'submit' => array()), 'test' => array('title' => $this->l('Test your e-mail configuration'), 'icon' => 'email', 'fields' => array('PS_SHOP_EMAIL' => array('title' => $this->l('Send a test e-mail to'), 'type' => 'text', 'size' => 40, 'id' => 'testEmail')), 'bottom' => '<div class="margin-form"><input type="button" class="button" name="btEmailTest" id="btEmailTest" value="' . $this->l('Send an e-mail test') . '" onclick="verifyMail();" /><br />
					<p id="mailResultCheck" style="display:none;"></p></div>'));
    }
Exemplo n.º 3
0
 public function __construct()
 {
     global $cookie;
     $this->className = 'Configuration';
     $this->table = 'configuration';
     foreach (Contact::getContacts((int) $cookie->id_lang) as $contact) {
         $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']);
     }
     $this->_fieldsEmail = array('PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr), 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Use PHP mail() function.  Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#SMTP_CONTAINER\').slideUp();"', 2 => 'onclick="$(\'#SMTP_CONTAINER\').slideDown();"')), 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))), 'SMTP_CONTAINER' => array('title' => '', 'type' => 'container'), 'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'validation' => 'isUrl', 'size' => 30, 'type' => 'text'), 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text'), 'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'******'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text'), 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'******'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password'), 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL')))), 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval'), 'SMTP_CONTAINER_END' => array('title' => '', 'type' => 'container_end', 'content' => '<script type="text/javascript">if (getE("PS_MAIL_METHOD2_on").checked == false) { $(\'#SMTP_CONTAINER\').hide(); }</script>'));
     parent::__construct();
 }
Exemplo n.º 4
0
    public function __construct()
    {
        $this->bootstrap = true;
        $this->className = 'Configuration';
        $this->table = 'configuration';
        parent::__construct();
        foreach (Contact::getContacts($this->context->language->id) as $contact) {
            $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']);
        }
        $this->fields_options = array('email' => array('title' => $this->l('Email'), 'icon' => 'icon-envelope', 'fields' => array('PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send email to'), 'desc' => $this->l('Where customers send messages from the order page.'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr), 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(3 => $this->l('Never send emails (may be useful for testing purposes)'), 1 => $this->l('Use PHP\'s mail() function (recommended; works in most cases)'), 2 => $this->l('Set my own SMTP parameters (for advanced users ONLY)')), 'js' => array(1 => 'onclick="$(\'#configuration_fieldset_smtp\').slideUp();"', 2 => 'onclick="$(\'#configuration_fieldset_smtp\').slideDown();"', 3 => 'onclick="$(\'#configuration_fieldset_smtp\').slideUp();"'), 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(Mail::TYPE_HTML => $this->l('Send email in HTML format'), Mail::TYPE_TEXT => $this->l('Send email in text format'), Mail::TYPE_BOTH => $this->l('Both')))), 'submit' => array('title' => $this->l('Save'))), 'smtp' => array('title' => $this->l('Email'), 'fields' => array('PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain name'), 'hint' => $this->l('Fully qualified domain name (keep this field empty if you don\'t know).'), 'empty' => true, 'validation' => 'isUrl', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server'), 'hint' => $this->l('IP address or server name (e.g. smtp.mydomain.com).'), 'validation' => 'isGenericName', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_USER' => array('title' => $this->l('SMTP user'), 'hint' => $this->l('Leave blank if not applicable.'), 'validation' => 'isGenericName', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password'), 'hint' => $this->l('Leave blank if not applicable.'), 'validation' => 'isAnything', 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL, 'autocomplete' => false), 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption'), 'hint' => $this->l('Use an encrypt protocol'), 'desc' => Tools::apacheModExists('mod_ssl') ? '/!\\  ' . $this->l('SSL mod seems to not be installed on your server.') : '', 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL), 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port'), 'hint' => $this->l('Port number to use.'), 'validation' => 'isInt', 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL)), 'submit' => array('title' => $this->l('Save'))), 'test' => array('title' => $this->l('Test your email configuration'), 'hide_multishop_checkbox' => true, 'fields' => array('PS_SHOP_EMAIL' => array('title' => $this->l('Send a test email to'), 'type' => 'text', 'id' => 'testEmail', 'no_multishop_checkbox' => true)), 'bottom' => '<div class="row"><div class="col-lg-9 col-lg-offset-3">
					<div class="alert" id="mailResultCheck" style="display:none;"></div>
				</div></div>', 'buttons' => array(array('title' => $this->l('Send an email test'), 'icon' => 'process-icon-envelope', 'name' => 'btEmailTest', 'js' => 'verifyMail()', 'class' => 'btn btn-default pull-right'))));
    }
    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 = array_unique(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(trim($str_errors), ',');
            }
            //checks if imap connexion is active
            if (!$mbox) {
                $array = array('hasError' => true, 'errors' => array('Cannot connect to the mailbox :<br />' . $str_errors));
                die(Tools::jsonEncode($array));
            }
            //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;
                            }
                            // we want to assign unrecognized mails to the right contact category
                            $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)) {
                                // if not use the default contact category
                                $id_contact = $contacts[0]['id_contact'];
                            }
                            $customer = new Customer();
                            $client = $customer->getByEmail($from);
                            //check if we already have a customer with this email
                            $ct = new CustomerThread();
                            if (isset($client->id)) {
                                //if mail is owned by a customer assign to him
                                $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;
                            //new customer threads for unrecognized mails are not shown without 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);
            $array = array('hasError' => false, 'errors' => array($str_errors . $str_error_delete));
            die(Tools::jsonEncode($array));
        }
    }
Exemplo n.º 6
0
 /**
  * Get available shop contacts.
  */
 protected function getShopContacts()
 {
     return Contact::getContacts($this->context->language->id);
 }
Exemplo n.º 7
0
    /**
     * Assign template vars related to page content
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        parent::initContent();
        $this->assignOrderList();
        $email = Tools::safeOutput(Tools::getValue('from', isset($this->context->cookie) && isset($this->context->cookie->email) && Validate::isEmail($this->context->cookie->email) ? $this->context->cookie->email : ''));
        $this->context->smarty->assign(array('errors' => $this->errors, 'email' => $email, 'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD')));
        if ($id_customer_thread = (int) Tools::getValue('id_customer_thread') && ($token = Tools::getValue('token'))) {
            $customerThread = Db::getInstance()->getRow('
				SELECT cm.* 
				FROM ' . _DB_PREFIX_ . 'customer_thread cm
				WHERE cm.id_customer_thread = ' . (int) $id_customer_thread . ' 
				AND cm.id_shop = ' . (int) $this->context->shop->id . ' 
				AND token = \'' . pSQL($token) . '\'
			');
            $this->context->smarty->assign('customerThread', $customerThread);
        }
        $this->context->smarty->assign(array('contacts' => Contact::getContacts($this->context->language->id), 'message' => html_entity_decode(Tools::getValue('message'))));
        $this->setTemplate(_PS_THEME_DIR_ . 'contact-form.tpl');
    }
Exemplo n.º 8
0
<?php

/**
 * about.php
 *
 * Content for About us page
 *
 * @version    1.2 2011-02-03
 * @package    Smithside Auctions
 * @copyright  Copyright (c) 2011 Smithside Auctions
 * @license    GNU General Public License
 * @since      Since Release 1.0
 */
// Get the contact information
$items = Contact::getContacts();
?>
<h1>About Us<a class="button" href="index.php?content=contactmaint&id=0">Add</a></h1>
<p>We are all happy to be a part of this. Please contact any of us with questions.</p>

<ul class="ulfancy">
  <?php 
foreach ($items as $i => $item) {
    ?>
    <li class="row<?php 
    echo $i % 2;
    ?>
">
      <h2><?php 
    echo htmlspecialchars($item->name());
    ?>
</h2>
Exemplo n.º 9
0
 protected function _buildStoreMap($item, $layout, $shopId, $langId, $cacheKey = '')
 {
     if (!$item) {
         return '';
     }
     if (!$this->isCached('megaboxs.' . $layout . '.group.store_map.tpl', Tools::encrypt($cacheKey))) {
         $this->context->smarty->assign(array('megaboxs_group_id' => $item['id'], 'megaboxs_group_display_title' => $item['display_title'], 'megaboxs_group_custom_class' => $item['custom_class'], 'megaboxs_group_width' => $item['width'], 'megaboxs_group_name' => $item['name'], 'megaboxs_group_content' => $item['html'], 'megaboxs_group_description' => $item['description'], 'contacts' => Contact::getContacts($this->context->language->id)));
     }
     return $this->display(__FILE__, 'megaboxs.' . $layout . '.group.store_map.tpl', Tools::encrypt($cacheKey));
 }
 protected function generateContactData()
 {
     $delimiter = ';';
     $line = array();
     $titles = array();
     $id_lang = $this->use_lang;
     $new_path = new Sampledatainstall();
     $f = fopen($new_path->sendPath() . 'output/contacts.vsc', 'w');
     foreach ($this->contacts_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $contacts = Contact::getContacts($id_lang);
     if ($contacts) {
         foreach ($contacts as $contact) {
             $c = new Contact($contact['id_contact'], $id_lang);
             foreach ($this->contacts_fields as $field => $array) {
                 $line[$field] = property_exists('Contact', $field) && !is_array($c->{$field}) && !Tools::isEmpty($c->{$field}) ? $c->{$field} : '';
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }
    public function process()
    {
        parent::process();
        $email = Tools::safeOutput(Tools::getValue('from', (isset(self::$cookie) and isset(self::$cookie->email) and Validate::isEmail(self::$cookie->email)) ? self::$cookie->email : ''));
        self::$smarty->assign(array('errors' => $this->errors, 'email' => $email, 'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD')));
        if ($id_customer_thread = (int) Tools::getValue('id_customer_thread') and $token = Tools::getValue('token')) {
            $customerThread = Db::getInstance()->getRow('
			SELECT cm.* FROM ' . _DB_PREFIX_ . 'customer_thread cm
			WHERE cm.id_customer_thread = ' . (int) $id_customer_thread . ' AND token = \'' . pSQL($token) . '\'');
            self::$smarty->assign('customerThread', $customerThread);
        }
        self::$smarty->assign(array('contacts' => Contact::getContacts((int) self::$cookie->id_lang), 'message' => html_entity_decode(Tools::getValue('message'))));
    }
 protected function displayMessage($message, $email = false, $id_employee = null)
 {
     $tpl = $this->createTemplate('message.tpl');
     $contacts = Contact::getContacts($this->context->language->id);
     foreach ($contacts as $contact) {
         $contact_array[$contact['id_contact']] = array('id_contact' => $contact['id_contact'], 'name' => $contact['name']);
     }
     $contacts = $contact_array;
     if (!$email) {
         if (!empty($message['id_product']) && empty($message['employee_name'])) {
             $id_order_product = Order::getIdOrderProduct((int) $message['id_customer'], (int) $message['id_product']);
         }
     }
     $message['date_add'] = Tools::displayDate($message['date_add'], null, true);
     $message['user_agent'] = strip_tags($message['user_agent']);
     $message['message'] = preg_replace('/(https?:\\/\\/[a-z0-9#%&_=\\(\\)\\.\\? \\+\\-@\\/]{6,1000})([\\s\\n<])/Uui', '<a href="\\1">\\1</a>\\2', html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8'));
     $tpl->assign(array('current' => self::$currentIndex, 'token' => $this->token, 'message' => $message, 'id_order_product' => isset($id_order_product) ? $id_order_product : null, 'email' => $email, 'id_employee' => $id_employee, 'PS_SHOP_NAME' => Configuration::get('PS_SHOP_NAME'), 'file_name' => file_exists(_PS_UPLOAD_DIR_ . $message['file_name']), 'contacts' => $contacts, 'PS_CUSTOMER_SERVICE_SIGNATURE' => str_replace('\\r\\n', "\n", Configuration::get('PS_CUSTOMER_SERVICE_SIGNATURE', $message['id_lang']))));
     return $tpl->fetch();
 }
Exemplo n.º 13
0
    private function displayMsg($message, $email = false, $id_employee = null)
    {
        global $cookie, $currentIndex;
        $customersToken = Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee);
        $contacts = Contact::getContacts($cookie->id_lang);
        if (!$email) {
            if (!empty($message['id_product']) and empty($message['id_employee'])) {
                $id_order_product = Db::getInstance()->getValue('
				SELECT o.id_order
				FROM ' . _DB_PREFIX_ . 'orders o
				LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order
				WHERE o.id_customer = ' . (int) $message['id_customer'] . '
				AND od.product_id = ' . (int) $message['id_product'] . '
				ORDER BY o.date_add DESC');
            }
            $output = '
			<fieldset style="' . (!empty($message['id_employee']) ? 'background: rgb(255,236,242);' : '') . 'width:600px;margin-top:10px">
				<legend ' . (empty($message['id_employee']) ? '' : 'style="background:rgb(255,210,225)"') . '>' . (!empty($message['employee_name']) ? '<img src="../img/t/AdminCustomers.gif" alt="' . Configuration::get('PS_SHOP_NAME') . '" /> ' . Configuration::get('PS_SHOP_NAME') . ' - ' . $message['employee_name'] : '<img src="' . __PS_BASE_URI__ . 'img/admin/tab-customers.gif" alt="' . Configuration::get('PS_SHOP_NAME') . '" /> ' . (!empty($message['id_customer']) ? '<a href="index.php?tab=AdminCustomers&id_customer=' . (int) $message['id_customer'] . '&viewcustomer&token=' . $customersToken . '" title="' . $this->l('View customer') . '">' . $message['customer_name'] . '</a>' : $message['email'])) . '</legend>
				<div style="font-size:11px">' . ((!empty($message['id_customer']) and empty($message['id_employee'])) ? '<b>' . $this->l('Customer ID:') . '</b> <a href="index.php?tab=AdminCustomers&id_customer=' . (int) $message['id_customer'] . '&viewcustomer&token=' . $customersToken . '" title="' . $this->l('View customer') . '">' . (int) $message['id_customer'] . ' <img src="../img/admin/search.gif" alt="' . $this->l('view') . '" /></a><br />' : '') . '
					<b>' . $this->l('Sent on:') . '</b> ' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true) . '<br />' . (empty($message['id_employee']) ? '<b>' . $this->l('Browser:') . '</b> ' . strip_tags($message['user_agent']) . '<br />' : '') . ((!empty($message['file_name']) and file_exists(_PS_UPLOAD_DIR_ . $message['file_name'])) ? '<b>' . $this->l('File attachment') . '</b> <a href="index.php?tab=AdminCustomerThreads&id_customer_thread=' . $message['id_customer_thread'] . '&viewcustomer_thread&token=' . Tools::getAdminToken('AdminCustomerThreads' . (int) Tab::getIdFromClassName('AdminCustomerThreads') . (int) $cookie->id_employee) . '&filename=' . $message['file_name'] . '" title="' . $this->l('View file') . '"><img src="../img/admin/search.gif" alt="' . $this->l('view') . '" /></a><br />' : '') . ((!empty($message['id_order']) and empty($message['id_employee'])) ? '<b>' . $this->l('Order #') . '</b> <a href="index.php?tab=AdminOrders&id_order=' . (int) $message['id_order'] . '&vieworder&token=' . Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee) . '" title="' . $this->l('View order') . '">' . (int) $message['id_order'] . ' <img src="../img/admin/search.gif" alt="' . $this->l('view') . '" /></a><br />' : '') . ((!empty($message['id_product']) and empty($message['id_employee'])) ? '<b>' . $this->l('Product #') . '</b> <a href="index.php?tab=AdminOrders&id_order=' . (int) $id_order_product . '&vieworder&token=' . Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee) . '" title="' . $this->l('View order') . '">' . (int) $message['id_product'] . ' <img src="../img/admin/search.gif" alt="' . $this->l('view') . '" /></a><br />' : '') . '<br />
					<form action="' . Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']) . '" method="post">
						<b>' . $this->l('Subject:') . '</b>
						<input type="hidden" name="id_customer_message" value="' . $message['id_customer_message'] . '" />
						<select name="id_contact" onchange="this.form.submit();">';
            foreach ($contacts as $contact) {
                $output .= '<option value="' . (int) $contact['id_contact'] . '" ' . ($contact['id_contact'] == $message['id_contact'] ? 'selected="selected"' : '') . '>' . Tools::htmlentitiesutf8($contact['name']) . '</option>';
            }
            $output .= '</select>
					</form>';
        } else {
            $output = '<div style="font-size:11px">
			' . ($id_employee ? '<a href="' . Tools::getHttpHost(true) . $currentIndex . '&token=' . Tools::getAdminToken('AdminCustomerThreads' . (int) Tab::getIdFromClassName('AdminCustomerThreads') . (int) $id_employee) . '&id_customer_thread=' . (int) $message['id_customer_thread'] . '&viewcustomer_thread">' . $this->l('View this thread') . '</a><br />' : '') . '
			<b>' . $this->l('Sent by:') . '</b> ' . (!empty($message['customer_name']) ? $message['customer_name'] . ' (' . $message['email'] . ')' : $message['email']) . ((!empty($message['id_customer']) and empty($message['employee_name'])) ? '<br /><b>' . $this->l('Customer ID:') . '</b> ' . (int) $message['id_customer'] . '<br />' : '') . ((!empty($message['id_order']) and empty($message['employee_name'])) ? '<br /><b>' . $this->l('Order #') . ':</b> ' . (int) $message['id_order'] . '<br />' : '') . ((!empty($message['id_product']) and empty($message['employee_name'])) ? '<br /><b>' . $this->l('Product #') . ':</b> ' . (int) $message['id_product'] . '<br />' : '') . '<br /><b>' . $this->l('Subject:') . '</b> ' . $message['subject'];
        }
        $message['message'] = preg_replace('/(https?:\\/\\/[a-z0-9#%&_=\\(\\)\\.\\? \\+\\-@\\/]{6,1000})([\\s\\n<])/Uui', '<a href="\\1">\\1</a>\\2', html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8'));
        $output .= '<br /><br />
			<b>' . $this->l('Thread ID:') . '</b> ' . (int) $message['id_customer_thread'] . '<br />
			<b>' . $this->l('Message ID:') . '</b> ' . (int) $message['id_customer_message'] . '<br />
			<b>' . $this->l('Message:') . '</b><br />
			' . $message['message'] . '
		</div>';
        if (!$email) {
            if (empty($message['employee_name'])) {
                $output .= '
				<p style="text-align:right">
					<button style="font-family: Verdana; font-size: 11px; font-weight:bold; height: 65px; width: 120px;" onclick="$(\'#reply_to_' . (int) $message['id_customer_message'] . '\').show(500); $(this).hide();">
						<img src="' . __PS_BASE_URI__ . 'img/admin/contact.gif" alt="" style="margin-bottom: 5px;" /><br />' . $this->l('Reply to this message') . '
					</button>
				</p>
				<div id="reply_to_' . (int) $message['id_customer_message'] . '" style="display: none; margin-top: 20px;"">
					<form action="' . Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']) . '" method="post" enctype="multipart/form-data">
						<p>' . $this->l('Please type your reply below:') . '</p>
						<textarea style="width: 450px; height: 175px;" name="reply_message">' . str_replace('\\r\\n', "\n", Configuration::get('PS_CUSTOMER_SERVICE_SIGNATURE', $message['id_lang'])) . '</textarea>
						<div style="width: 450px; text-align: right; font-style: italic; font-size: 9px; margin-top: 2px;">
							' . $this->l('Your reply will be sent to:') . ' ' . $message['email'] . '
						</div>
						<div style="width: 450px; margin-top: 0px;">
							<input type="file" name="joinFile"/>
						<div>
						<div style="width: 450px; text-align: center;">
							<input type="submit" class="button" name="submitReply" value="' . $this->l('Send my reply') . '" style="margin-top:20px;" />
							<input type="hidden" name="id_customer_thread" value="' . (int) $message['id_customer_thread'] . '" />
							<input type="hidden" name="msg_email" value="' . $message['email'] . '" />
						</div>					
					</form>
				</div>';
            }
            $output .= '
			</fieldset>';
        }
        return $output;
    }
Exemplo n.º 14
0
<?php

$useSSL = true;
include dirname(__FILE__) . '/config/config.inc.php';
include dirname(__FILE__) . '/header.php';
$errors = array();
$smarty->assign('contacts', Contact::getContacts(intval($cookie->id_lang)));
if (Tools::isSubmit('submitMessage')) {
    $message = Tools::htmlentitiesUTF8(Tools::getValue('message'));
    if (!($from = Tools::getValue('from')) or !Validate::isEmail($from)) {
        $errors[] = Tools::displayError('invalid e-mail address');
    } elseif (!($message = nl2br2($message))) {
        $errors[] = Tools::displayError('message cannot be blank');
    } elseif (!Validate::isMessage($message)) {
        $errors[] = Tools::displayError('invalid message');
    } elseif (!($id_contact = intval(Tools::getValue('id_contact'))) or !Validate::isLoadedObject($contact = new Contact(intval($id_contact), intval($cookie->id_lang)))) {
        $errors[] = Tools::displayError('please select a contact in the list');
    } else {
        if (intval($cookie->id_customer)) {
            $customer = new Customer(intval($cookie->id_customer));
        }
        if (Mail::Send(intval($cookie->id_lang), 'contact', 'Message from contact form', array('{email}' => $from, '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, intval($cookie->id_customer) ? $customer->firstname . ' ' . $customer->lastname : $from)) {
            $smarty->assign('confirmation', 1);
        } else {
            $errors[] = Tools::displayError('an error occurred while sending message');
        }
    }
}
$email = Tools::safeOutput(Tools::getValue('from', (isset($cookie) and isset($cookie->email) and Validate::isEmail($cookie->email)) ? $cookie->email : ''));
$smarty->assign(array('errors' => $errors, 'email' => $email));
$smarty->display(_PS_THEME_DIR_ . 'contact-form.tpl');
Exemplo n.º 15
0
 public function getTemplateVarContact()
 {
     $contacts = array();
     $all_contacts = Contact::getContacts($this->context->language->id);
     foreach ($all_contacts as $one_contact_id => $one_contact) {
         $contacts[$one_contact['id_contact']] = $one_contact;
     }
     if ($this->customer_thread['id_contact']) {
         return [$contacts[$this->customer_thread['id_contact']]];
     }
     return $contacts;
 }
    /**
     * Imap synchronization method.
     *
     * @return array Errors list.
     */
    public function syncImap()
    {
        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'))) {
            return array('hasError' => true, 'errors' => array('IMAP configuration is not correct'));
        }
        $conf = Configuration::getMultiple(array('PS_SAV_IMAP_OPT_POP3', '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_POP3']) {
            $conf_str .= '/pop3';
        }
        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')) {
            return array('hasError' => true, 'errors' => array('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();
        if (is_array($errors)) {
            $errors = array_unique($errors);
        }
        $str_errors = '';
        $str_error_delete = '';
        if (count($errors) && is_array($errors)) {
            $str_errors = '';
            foreach ($errors as $error) {
                $str_errors .= $error . ', ';
            }
            $str_errors = rtrim(trim($str_errors), ',');
        }
        //checks if imap connexion is active
        if (!$mbox) {
            return array('hasError' => true, 'errors' => array('Cannot connect to the mailbox :<br />' . $str_errors));
        }
        //Returns information about the current mailbox. Returns FALSE on failure.
        $check = imap_check($mbox);
        if (!$check) {
            return array('hasError' => true, 'errors' => array('Fail to get information about the current mailbox'));
        }
        if ($check->Nmsgs == 0) {
            return array('hasError' => true, 'errors' => array('NO message to sync'));
        }
        $result = imap_fetch_overview($mbox, "1:{$check->Nmsgs}", 0);
        $message_errors = array();
        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);
                $match_found = false;
                if (isset($matches1[1]) && isset($matches2[1])) {
                    $match_found = true;
                }
                $new_ct = Configuration::get('PS_SAV_IMAP_CREATE_THREADS') && !$match_found && strpos($subject, '[no_sync]') == false;
                $fetch_succeed = true;
                if ($match_found || $new_ct) {
                    if ($new_ct) {
                        // parse from attribute and fix it if needed
                        $from_parsed = array();
                        if (!isset($overview->from) || !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, $from_parsed) && !Validate::isEmail($overview->from)) {
                            $message_errors[] = $this->trans('Cannot create message in a new thread.', array(), 'Admin.OrdersCustomers.Notification');
                            continue;
                        }
                        // fix email format: from "Mr Sanders <*****@*****.**>" to "*****@*****.**"
                        $from = $overview->from;
                        if (isset($from_parsed[1])) {
                            $from = $from_parsed[1];
                        }
                        // we want to assign unrecognized mails to the right contact category
                        $contacts = Contact::getContacts($this->context->language->id);
                        if (!$contacts) {
                            continue;
                        }
                        foreach ($contacts as $contact) {
                            if (isset($overview->to) && strpos($overview->to, $contact['email']) !== false) {
                                $id_contact = $contact['id_contact'];
                            }
                        }
                        if (!isset($id_contact)) {
                            // if not use the default contact category
                            $id_contact = $contacts[0]['id_contact'];
                        }
                        $customer = new Customer();
                        $client = $customer->getByEmail($from);
                        //check if we already have a customer with this email
                        $ct = new CustomerThread();
                        if (isset($client->id)) {
                            //if mail is owned by a customer assign to him
                            $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;
                        //new customer threads for unrecognized mails are not shown without 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)) {
                        $structure = imap_bodystruct($mbox, $overview->msgno, '1');
                        if ($structure->type == 0) {
                            $message = imap_fetchbody($mbox, $overview->msgno, '1');
                        } elseif ($structure->type == 1) {
                            $structure = imap_bodystruct($mbox, $overview->msgno, '1.1');
                            $message = imap_fetchbody($mbox, $overview->msgno, '1.1');
                        } else {
                            continue;
                        }
                        switch ($structure->encoding) {
                            case 3:
                                $message = imap_base64($message);
                                break;
                            case 4:
                                $message = imap_qprint($message);
                                break;
                        }
                        $message = iconv($this->getEncoding($structure), 'utf-8', $message);
                        $message = nl2br($message);
                        if (!$message || strlen($message) == 0) {
                            $message_errors[] = $this->trans('The message body is empty, cannot import it.', array(), 'Admin.OrdersCustomers.Notification');
                            $fetch_succeed = false;
                            continue;
                        }
                        $cm = new CustomerMessage();
                        $cm->id_customer_thread = $ct->id;
                        if (empty($message) || !Validate::isCleanHtml($message)) {
                            $str_errors .= Tools::displayError(sprintf('Invalid Message Content for subject: %1s', $subject));
                        } else {
                            try {
                                $cm->message = $message;
                                $cm->add();
                            } catch (PrestaShopException $pse) {
                                $message_errors[] = $this->trans('The message content is not valid, cannot import it.', array(), 'Admin.OrdersCustomers.Notification');
                                $fetch_succeed = false;
                                continue;
                            }
                        }
                    }
                }
                if ($fetch_succeed) {
                    Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'customer_message_sync_imap` (`md5_header`) VALUES (\'' . pSQL($md5) . '\')');
                }
            }
        }
        imap_expunge($mbox);
        imap_close($mbox);
        if (sizeof($message_errors) > 0) {
            if (($more_error = $str_errors . $str_error_delete) && strlen($more_error) > 0) {
                $message_errors = array_merge(array($more_error), $message_errors);
            }
            return array('hasError' => true, 'errors' => $message_errors);
        }
        if ($str_errors . $str_error_delete) {
            return array('hasError' => true, 'errors' => array($str_errors . $str_error_delete));
        } else {
            return array('hasError' => false, 'errors' => '');
        }
    }