public function process() { if (array_key_exists('smtp_send', $this->request->post)) { list($success, $form) = $this->process_form(array('compose_to', 'compose_subject', 'smtp_server_id')); if ($success) { $draft = array('draft_to' => $form['compose_to'], 'draft_body' => '', 'draft_subject' => $form['compose_subject']); $to = $form['compose_to']; $subject = $form['compose_subject']; $body = ''; $from = ''; $cc = ''; $bcc = ''; $in_reply_to = ''; if (array_key_exists('compose_body', $this->request->post)) { $body = $this->request->post['compose_body']; $draft['draft_body'] = $this->request->post['compose_body']; } if (array_key_exists('compose_cc', $this->request->post)) { $cc = $this->request->post['compose_cc']; $draft['draft_cc'] = $this->request->post['compose_cc']; } if (array_key_exists('compose_bcc', $this->request->post)) { $bcc = $this->request->post['compose_bcc']; $draft['draft_bcc'] = $this->request->post['compose_bcc']; } if (array_key_exists('compose_in_reply_to', $this->request->post)) { $in_reply_to = $this->request->post['compose_in_reply_to']; $draft['draft_in_reply_to'] = $this->request->post['compose_in_reply_to']; } $smtp_details = Hm_SMTP_List::dump($form['smtp_server_id'], true); if ($smtp_details) { $from = $smtp_details['user']; if (array_key_exists('auth', $smtp_details) && $smtp_details['auth'] == 'xoauth2') { $results = smtp_refresh_oauth2_token($smtp_details, $this->config); if (!empty($results)) { if (Hm_SMTP_List::update_oauth2_token($form['smtp_server_id'], $results[1], $results[0])) { Hm_Debug::add(sprintf('Oauth2 token refreshed for SMTP server id %d', $form['smtp_server_id'])); $servers = Hm_SMTP_List::dump(false, true); $this->user_config->set('smtp_servers', $servers); $this->session->set('user_data', $this->user_config->dump()); } } } $smtp = Hm_SMTP_List::connect($form['smtp_server_id'], false); if ($smtp && $smtp->state == 'authed') { $mime = new Hm_MIME_Msg($to, $subject, $body, $from, $this->get('smtp_compose_type', 0), $cc, $bcc, $in_reply_to); $mime->add_attachments($this->session->get('uploaded_files', array())); $recipients = $mime->get_recipient_addresses(); if (empty($recipients)) { Hm_Msgs::add("ERRNo valid receipts found"); } else { $err_msg = $smtp->send_message($from, $recipients, $mime->get_mime_msg()); if ($err_msg) { Hm_Msgs::add(sprintf("ERR%s", $err_msg)); } else { $draft = array(); delete_uploaded_files($this->session); Hm_Msgs::add("Message Sent"); } } } else { Hm_Msgs::add("ERRFailed to authenticate to the SMTP server"); } } $this->session->set('compose_draft', $draft); } else { Hm_Msgs::add('ERRRequired field missing'); } } }
/** * Destroy a session for good * @param object $request request details * @return void */ public function destroy($request) { if (function_exists('delete_uploaded_files')) { delete_uploaded_files($this); } if ($this->dbh) { $sql = $this->dbh->prepare("delete from hm_user_session where hm_id=?"); $sql->execute(array($this->session_key)); } $this->secure_cookie($request, $this->cname, '', time() - 3600); $this->secure_cookie($request, 'hm_id', '', time() - 3600); $this->active = false; Hm_Request_Key::load($this, $request, false); }