Example #1
0
 function saveAccount($id = null, $data)
 {
     global $osC_Database, $osC_Language;
     if ($id != null) {
         $Qpassword = $osC_Database->query('select password from :table_email_accounts where accounts_id = :accounts_id');
         $Qpassword->bindTable(':table_email_accounts', TABLE_EMAIL_ACCOUNTS);
         $Qpassword->bindInt(':accounts_id', $id);
         $password = $Qpassword->value('password');
         $fake_password = str_pad('', strlen($password), '*');
         if ($fake_password == $data['password']) {
             $data['password'] = $password;
         }
     }
     if ($id != null) {
         $Qaccounts = $osC_Database->query('update :table_email_accounts set accounts_name = :accounts_name, accounts_email = :accounts_email, signature = :signature, port = :port, host = :host, save_copy_on_server = :save_copy_on_server, use_ssl = :use_ssl, novalidate_cert = :novalidate_cert, username = :username, password = :password, mbroot = :mbroot, sent = :sent, drafts = :drafts, trash = :trash, examine_headers = :examine_headers, use_system_mailer = :use_system_mailer, smtp_host = :smtp_host, smtp_port = :smtp_port, smtp_encryption = :smtp_encryption, smtp_username = :smtp_username, smtp_password = :smtp_password where accounts_id = :accounts_id');
         $Qaccounts->bindInt(':accounts_id', $id);
     } else {
         $Qaccounts = $osC_Database->query('insert into :table_email_accounts (user_id, accounts_name, accounts_email, type, host, port, save_copy_on_server, use_ssl, novalidate_cert, username, password, signature, mbroot, sent, drafts, trash, spam, examine_headers, use_system_mailer, smtp_host, smtp_port, smtp_encryption, smtp_username, smtp_password) values (:user_id, :accounts_name, :accounts_email, :type, :host, :port, :save_copy_on_server, :use_ssl, :novalidate_cert, :username, :password, :signature, :mbroot, :sent, :drafts, :trash, :spam, :examine_headers, :use_system_mailer, :smtp_host, :smtp_port, :smtp_encryption, :smtp_username, :smtp_password)');
         if ($data['type'] == 'pop3') {
             $data['sent'] = $osC_Language->get('pop3_mailbox_sent_items');
             $data['trash'] = $osC_Language->get('pop3_mailbox_trash');
             $data['drafts'] = $osC_Language->get('pop3_mailbox_drafts');
             $data['spam'] = $osC_Language->get('pop3_mailbox_spam');
         }
     }
     $Qaccounts->bindTable(':table_email_accounts', TABLE_EMAIL_ACCOUNTS);
     $Qaccounts->bindInt(':user_id', $data['user_id']);
     $Qaccounts->bindValue(':accounts_name', $data['accounts_name']);
     $Qaccounts->bindValue(':accounts_email', $data['accounts_email']);
     $Qaccounts->bindValue(':type', $data['type']);
     $Qaccounts->bindValue(':host', $data['host']);
     $Qaccounts->bindInt(':port', $data['port']);
     $Qaccounts->bindInt(':save_copy_on_server', $data['save_copy_on_server']);
     $Qaccounts->bindInt(':use_ssl', $data['use_ssl']);
     $Qaccounts->bindInt(':novalidate_cert', $data['novalidate_cert']);
     $Qaccounts->bindValue(':username', $data['username']);
     $Qaccounts->bindValue(':password', $data['password']);
     $Qaccounts->bindValue(':signature', $data['signature']);
     $Qaccounts->bindInt(':examine_headers', $data['examine_headers']);
     $Qaccounts->bindValue(':mbroot', $data['mbroot']);
     $Qaccounts->bindValue(':sent', $data['sent']);
     $Qaccounts->bindValue(':drafts', $data['drafts']);
     $Qaccounts->bindValue(':trash', $data['trash']);
     $Qaccounts->bindValue(':spam', $data['spam']);
     $Qaccounts->bindInt(':use_system_mailer', $data['use_system_mailer']);
     $Qaccounts->bindValue(':smtp_host', $data['smtp_host']);
     $Qaccounts->bindInt(':smtp_port', $data['smtp_port']);
     $Qaccounts->bindValue(':smtp_encryption', $data['smtp_encryption']);
     $Qaccounts->bindValue(':smtp_username', $data['smtp_username']);
     $Qaccounts->bindValue(':smtp_password', $data['smtp_password']);
     $Qaccounts->execute();
     if (!$osC_Database->isError()) {
         if ($id == null) {
             $accounts_id = $osC_Database->nextID();
             $toC_Email_Account = new toC_Email_Account($accounts_id);
             if ($toC_Email_Account->initializeAccount()) {
                 return $accounts_id;
             } else {
                 return false;
             }
         }
         return $id;
     }
     return false;
 }
Example #2
0
 function sendMail()
 {
     global $toC_Json, $osC_Language;
     $to = array();
     $emails = explode(';', $_REQUEST['to']);
     foreach ($emails as $email) {
         if (!empty($email)) {
             $to[] = osC_Mail::parseEmail($email);
         }
     }
     $cc = array();
     if (isset($_REQUEST['cc']) && !empty($_REQUEST['cc'])) {
         $emails = explode(';', $_REQUEST['cc']);
         foreach ($emails as $email) {
             if (!empty($email)) {
                 $cc[] = osC_Mail::parseEmail($email);
             }
         }
     }
     $bcc = array();
     if (isset($_REQUEST['bcc']) && !empty($_REQUEST['bcc'])) {
         $emails = explode(';', $_REQUEST['bcc']);
         foreach ($emails as $email) {
             if (!empty($email)) {
                 $bcc[] = osC_Mail::parseEmail($email);
             }
         }
     }
     $attachments = array();
     if (isset($_REQUEST['attachments']) && !empty($_REQUEST['attachments'])) {
         $attachments = explode(';', $_REQUEST['attachments']);
     }
     $toC_Email_Account = new toC_Email_Account($_REQUEST['accounts_id']);
     $data = array('accounts_id' => $toC_Email_Account->getAccountId(), 'id' => $_REQUEST['id'], 'to' => $to, 'cc' => $cc, 'bcc' => $bcc, 'from' => $toC_Email_Account->getAccountName(), 'sender' => $toC_Email_Account->getAccountEmail(), 'subject' => $_REQUEST['subject'], 'reply_to' => $toC_Email_Account->getAccountEmail(), 'full_from' => $toC_Email_Account->getAccountName() . ' <' . $toC_Email_Account->getAccountEmail() . '>', 'body' => $_REQUEST['body'], 'priority' => $_REQUEST['priority'], 'content_type' => $_REQUEST['content_type'], 'notification' => $_REQUEST['notification'], 'udate' => time(), 'date' => date('m/d/Y H:i:s'), 'fetch_timestamp' => time(), 'messages_flag' => EMAIL_MESSAGE_DRAFT, 'attachments' => $attachments);
     if ($toC_Email_Account->sendMail($data)) {
         $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed'));
     } else {
         $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed'));
     }
     echo $toC_Json->encode($response);
 }