Example #1
0
 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');
         }
     }
 }
Example #2
0
 public function process()
 {
     list($success, $form) = $this->process_form(array('nux_pass', 'nux_service', 'nux_email', 'nux_name'));
     if ($success) {
         if (Nux_Quick_Services::exists($form['nux_service'])) {
             $details = Nux_Quick_Services::details($form['nux_service']);
             $details['name'] = $form['nux_name'];
             Hm_IMAP_List::add(array('name' => $details['name'], 'server' => $details['server'], 'port' => $details['port'], 'tls' => $details['tls'], 'user' => $form['nux_email'], 'pass' => $form['nux_pass']));
             $servers = Hm_IMAP_List::dump(false, true);
             $ids = array_keys($servers);
             $new_id = array_pop($ids);
             $imap = Hm_IMAP_List::connect($new_id, false);
             if ($imap && $imap->get_state() == 'authenticated') {
                 if (isset($details['smtp'])) {
                     Hm_SMTP_List::add(array('name' => $details['name'], 'server' => $details['smtp']['server'], 'port' => $details['smtp']['port'], 'tls' => $details['smtp']['tls'], 'user' => $form['nux_email'], 'pass' => $form['nux_pass']));
                     $this->session->record_unsaved('SMTP server added');
                     $smtp_servers = Hm_SMTP_List::dump(false, true);
                     $this->user_config->set('smtp_servers', $smtp_servers);
                 }
                 $this->user_config->set('imap_servers', $servers);
                 Hm_IMAP_List::clean_up();
                 $user_data = $this->user_config->dump();
                 if (!empty($user_data)) {
                     $this->session->set('user_data', $user_data);
                 }
                 $this->session->record_unsaved('IMAP server added');
                 $this->session->record_unsaved('SMTP server added');
                 $this->session->secure_cookie($this->request, 'hm_reload_folders', '1');
                 Hm_Msgs::add('E-mail account successfully added');
                 $msgs = Hm_Msgs::get();
                 if (!empty($msgs)) {
                     $this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(serialize($msgs)), 0);
                 }
                 $this->session->close_early();
                 $this->out('nux_account_added', true);
             } else {
                 Hm_IMAP_List::del($new_id);
                 Hm_Msgs::add('ERRAuthentication failed');
             }
         }
     }
 }