Example #1
0
 function form_action_compose_send($form, $post)
 {
     global $user;
     global $imap;
     global $conf;
     global $message;
     global $hastymail_version;
     global $smtp;
     global $include_path;
     global $fd;
     $path = $conf['attachments_path'];
     if ($user->logged_in) {
         if (isset($post['contacts_visible']) && $post['contacts_visible']) {
             $user->page_data['contact_browse'] = true;
         }
         require_once $include_path . 'lib' . $fd . 'smtp_class.php';
         $message = hm_new('mime', $post['compose_session']);
         if (!isset($_SESSION['user_settings']['compose_hide_mailer']) || !$_SESSION['user_settings']['compose_hide_mailer']) {
             $message->set_header('x_Mailer', $hastymail_version);
         }
         if (isset($post['compose_to'])) {
             $message->to = $post['compose_to'];
         }
         if (isset($post['compose_cc'])) {
             $message->cc = $post['compose_cc'];
         }
         if (isset($post['compose_bcc'])) {
             $message->bcc = $post['compose_bcc'];
         }
         if (isset($post['compose_references'])) {
             $message->references = $post['compose_references'];
         }
         if (isset($post['compose_in_reply_to'])) {
             $message->in_reply_to = $post['compose_in_reply_to'];
         }
         if (isset($post['message_id'])) {
             $message->message_id = $post['message_id'];
         }
         if (isset($post['compose_from'])) {
             if (isset($_SESSION['user_settings']['profiles'][$post['compose_from']])) {
                 $from_atts = $_SESSION['user_settings']['profiles'][$post['compose_from']];
                 $message->from = '"' . $from_atts['profile_name'] . '" <' . $from_atts['profile_address'] . '> ';
                 $message->from_address = $from_atts['profile_address'];
                 if (isset($from_atts['profile_reply_to']) && $from_atts['profile_reply_to']) {
                     $message->reply_to = '<' . $from_atts['profile_address'] . '>';
                 }
             }
         }
         if ($message->from_address) {
             $recipients = $message->get_recipient_addresses();
             if (!empty($recipients)) {
                 $message->subject = $post['compose_subject'];
                 $message->body = $post['compose_message'];
                 $priortiy = 0;
                 if (isset($post['compose_priority']) && $post['compose_priority']) {
                     $priortiy = (int) $post['compose_priority'];
                 }
                 if ($priortiy && $priortiy != 3) {
                     $message->set_header('x_Priority', $priortiy);
                 }
                 if (isset($post['compose_mdn']) && $post['compose_mdn']) {
                     $message->set_header('disposition_Notification_To', $message->from_address);
                 }
                 $smtp = hm_new('smtp');
                 $res = $smtp->connect();
                 if (!$res) {
                     do_work_hook('message_send', array($message->body));
                     $res = $smtp->send_message($message->from_address, $recipients, $message);
                     if ($res) {
                         if ($smtp->smtp_err) {
                             $res .= '<br />' . $smtp->smtp_err;
                         }
                         $this->form_vals = $post;
                         $this->errors[] = $res;
                     } else {
                         $user->page_data['sent'] = 1;
                         $this->errors[] = $user->str[355];
                         $this->form_redirect = true;
                         if (isset($post['compose_in_reply_to']) && $post['compose_in_reply_to']) {
                             $this->perform_imap_action('ANSWERED', $post['reply_box'], array($post['reply_uid']), false, false);
                         }
                     }
                     if (!$res && !isset($post['compose_skip_sent']) || isset($post['compose_skip_sent']) && !$post['compose_skip_sent']) {
                         $sent_folder = $_SESSION['user_settings']['sent_folder'];
                         if (isset($_SESSION['sent_folder_override']) && isset($_SESSION['folders'][$_SESSION['sent_folder_override']])) {
                             $sent_folder = $_SESSION['sent_folder_override'];
                             unset($_SESSION['sent_folder_override']);
                         }
                         if (isset($sent_folder) && isset($_SESSION['folders'][$sent_folder])) {
                             $status = stream_imap_append($message, $post['compose_session'], $sent_folder);
                             if (!$status) {
                                 $this->errors[] = $user->str[539];
                             }
                         }
                     }
                     if (!$res && isset($_SESSION['user_settings']['draft_folder']) && isset($post['message_id']) && $post['message_id'] && isset($_SESSION['user_settings']['delete_draft']) && $_SESSION['user_settings']['delete_draft'] && $_SESSION['user_settings']['draft_folder']) {
                         $trash_folder = false;
                         if (isset($_SESSION['user_settings']['trash_folder']) && $_SESSION['user_settings']['trash_folder']) {
                             $trash_folder = $_SESSION['user_settings']['trash_folder'];
                         }
                         $select_res = $imap->select_mailbox($_SESSION['user_settings']['draft_folder'], false, false, true);
                         if ($select_res) {
                             $search_res = $imap->simple_search('header message-id', false, $post['message_id']);
                             if (isset($search_res[0])) {
                                 $this->perform_imap_action('DELETE', $_SESSION['user_settings']['draft_folder'], array($search_res[0]), $trash_folder, false);
                             }
                         }
                     }
                     do_work_hook('compose_after_send');
                 } else {
                     $this->errors[] = $res;
                     $this->form_vals = $post;
                 }
                 if (!$res) {
                     unset_attachments($post['compose_session']);
                 }
                 $smtp->disconnect();
             } else {
                 $this->form_vals = $post;
                 $this->errors[] = $user->str[356];
             }
         } else {
             $this->form_vals = $post;
             $this->errors[] = $user->str[357];
         }
     }
 }
Example #2
0
function ajax_save_outgoing_message($subject, $body, $to, $cc, $from, $id, $reply_to, $refs, $priortiy, $mdn, $c_session, $content_type)
{
    global $user;
    global $hastymail_version;
    global $imap;
    global $conf;
    global $include_path;
    global $fd;
    global $message;
    if ($user->user_action->gpc) {
        $to = stripslashes($to);
        $cc = stripslashes($cc);
        $from = stripslashes($from);
        $body = stripslashes($body);
        $subject = stripslashes($subject);
    }
    $path = $conf['attachments_path'];
    if ($user->logged_in) {
        $select_res = false;
        $_SESSION['compose_sessions'][$c_session] = time();
        if (trim($body)) {
            if (isset($_SESSION['user_settings']['draft_folder'])) {
                $mailbox = $_SESSION['user_settings']['draft_folder'];
                $select_res = $imap->select_mailbox($mailbox, false, false, true);
            } else {
                $mailbox = 'INBOX';
            }
            require_once $include_path . 'lib' . $fd . 'smtp_class.php';
            $message = hm_new('mime', $c_session);
            if ($to) {
                $message->to = $to;
            }
            if ($cc) {
                $message->cc = $cc;
            }
            if ($refs) {
                $message->references = $refs;
            }
            if ($reply_to) {
                $message->in_reply_to = $reply_to;
            }
            if ($id) {
                $message->message_id = $id;
            }
            if (isset($_SESSION['user_settings']['profiles'][$from])) {
                $from_atts = $_SESSION['user_settings']['profiles'][$from];
                $message->from = '"' . $from_atts['profile_name'] . '" <' . $from_atts['profile_address'] . '> ';
                $message->from_address = $from_atts['profile_address'];
                if (isset($from_atts['profile_reply_to']) && $from_atts['profile_reply_to']) {
                    $message->reply_to = '<' . $from_atts['profile_address'] . '>';
                }
            }
            $existing_id = false;
            if ($select_res) {
                $search_res = $imap->simple_search('header message-id', false, $message->message_id);
                if (isset($search_res[0])) {
                    $existing_id = $search_res[0];
                }
            }
            if ($message->from_address) {
                $message->subject = decode_unicode_url($subject);
                $message->body = decode_unicode_url($body);
                if (!isset($_SESSION['user_settings']['compose_hide_mailer']) || !$_SESSION['user_settings']['compose_hide_mailer']) {
                    $message->set_header('x_Mailer', $hastymail_version);
                }
                if ($priortiy && $priortiy != 3) {
                    $message->set_header('x_Priority', $priortiy);
                }
                if ($mdn) {
                    $message->set_header('disposition_Notification_To', $message->from_address);
                }
                do_work_hook('message_save', array($message->body));
                $status = stream_imap_append($message, $c_session, $mailbox);
                if ($status && $existing_id) {
                    $imap->message_action(array($existing_id), 'DELETE');
                    $imap->message_action(array($existing_id), 'EXPUNGE');
                    $_SESSION['uid_cache_refresh'][$mailbox] = 1;
                    $_SESSION['header_cache_refresh'][$mailbox] = 1;
                }
            }
        }
    }
    if (isset($message->message_id)) {
        return $message->message_id;
    } else {
        return '';
    }
}