コード例 #1
0
ファイル: modules.php プロジェクト: GordonDiggs/hm3
 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');
             }
         }
     }
 }
コード例 #2
0
ファイル: modules.php プロジェクト: hanzubon/hm3
 protected function output()
 {
     $to = '';
     $subject = '';
     $body = '';
     $files = $this->get('uploaded_files', array());
     $cc = '';
     $bcc = '';
     $in_reply_to = '';
     $recip = '';
     $draft = $this->get('compose_draft', array());
     $reply = $this->get('reply_details', array());
     $reply_type = $this->get('reply_type', '');
     $html = $this->get('smtp_compose_type', 0);
     if (!empty($reply)) {
         list($to, $cc, $subject, $body, $in_reply_to) = format_reply_fields($reply['msg_text'], $reply['msg_headers'], $reply['msg_struct'], $html, $this, $reply_type, Hm_SMTP_List::address_list());
         $recip = get_primary_recipients($reply['msg_headers'], $this->get('smtp_servers', array()));
     } elseif (!empty($draft)) {
         $to = $draft['draft_to'];
         $subject = $draft['draft_subject'];
         $body = $draft['draft_body'];
     }
     $res = '';
     if ($html == 1) {
         $res .= '<script type="text/javascript" src="modules/smtp/assets/kindeditor/kindeditor-all-min.js"></script>' . '<link href="modules/smtp/assets/kindeditor/themes/default/default.css" rel="stylesheet" />' . '<script type="text/javascript">KindEditor.ready(function(K) { K.create("#compose_body", {items:' . "['formatblock', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold'," . "'italic', 'underline', 'strikethrough', 'lineheight', 'table', 'hr', 'pagebreak', 'link', 'unlink'," . "'justifyleft', 'justifycenter', 'justifyright'," . "'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', '|'," . "'undo', 'redo', 'preview', 'print', '|', 'selectall', 'cut', 'copy', 'paste'," . "'plainpaste', 'wordpaste', '|', 'source', 'fullscreen']" . ",basePath: 'modules/smtp/assets/kindeditor/'" . '})});;</script>';
     }
     $res .= '<div class="compose_page"><div class="content_title">' . $this->trans('Compose') . '</div>' . '<form class="compose_form" method="post" action="?page=compose">' . '<input type="hidden" name="hm_page_key" value="' . $this->html_safe(Hm_Request_Key::generate()) . '" />' . '<input type="hidden" name="compose_in_reply_to" value="' . $this->html_safe($in_reply_to) . '" />' . '<div class="to_outer"><input autocomplete="off" value="' . $this->html_safe($to) . '" required name="compose_to" class="compose_to" type="text" placeholder="' . $this->trans('To') . '" />' . '<a href="#" tabindex="-1" class="toggle_recipients">+</a></div><div id="to_contacts"></div>' . '<div class="recipient_fields"><input autocomplete="off" value="' . $this->html_safe($cc) . '" name="compose_cc" class="compose_cc" type="text" placeholder="' . $this->trans('Cc') . '" /><div id="cc_contacts"></div><input autocomplete="off" value="' . $this->html_safe($bcc) . '" name="compose_bcc" class="compose_bcc" type="text" placeholder="' . $this->trans('Bcc') . '" />' . '</div><div id="bcc_contacts"></div><input value="' . $this->html_safe($subject) . '" required name="compose_subject" class="compose_subject" type="text" placeholder="' . $this->trans('Subject') . '" /><textarea id="compose_body" name="compose_body" class="compose_body">' . $this->html_safe($body) . '</textarea><table class="uploaded_files">';
     foreach ($files as $file) {
         $res .= format_attachment_row($file, $this);
     }
     $res .= '</table>' . smtp_server_dropdown($this->module_output(), $this, $recip) . '<input class="smtp_send" type="submit" value="' . $this->trans('Send') . '" name="smtp_send" />' . '<input class="smtp_save" type="button" value="' . $this->trans('Save') . '" />' . '<input class="smtp_reset" type="button" value="' . $this->trans('Reset') . '" />' . '<input class="compose_attach_button" value="' . $this->trans('Attach') . '" name="compose_attach_button" type="button" /></form>' . '<form enctype="multipart/form-data" class="compose_attach_form" />' . '<input class="compose_attach_file" type="file" name="compose_attach_file" />' . '<input type="hidden" name="compose_attach_page_id" value="ajax_smtp_attach_file" />' . '</form>' . '</div>';
     return $res;
 }
コード例 #3
0
ファイル: modules.php プロジェクト: GordonDiggs/hm3
 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 = '';
             if (array_key_exists('compose_body', $this->request->post)) {
                 $body = $this->request->post['compose_body'];
                 $draft['draft_body'] = $this->request->post['compose_body'];
             }
             $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));
                     $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();
                             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');
         }
     }
 }