function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) { global $trash_folder; if ($tree[$index]['doIHaveChildren']) { for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) { walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree); } if ($tree[$index]['value'] != $trash_folder) { sqimap_mailbox_delete($imap_stream, $tree[$index]['value']); } else { $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder); if ($mbx_response['EXISTS'] > 0) { sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true); sqimap_mailbox_expunge($imap_stream, $trash_folder, true); } } } else { if ($tree[$index]['value'] != $trash_folder) { sqimap_mailbox_delete($imap_stream, $tree[$index]['value']); } else { $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder); if ($mbx_response['EXISTS'] > 0) { sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true); sqimap_mailbox_expunge($imap_stream, $trash_folder, true); } } } }
function sqimap_messages_delete($imap_stream, $start, $end, $mailbox) { global $move_to_trash, $trash_folder, $auto_expunge, $uid_support; if ($move_to_trash == true && (sqimap_mailbox_exists($imap_stream, $trash_folder) && $mailbox != $trash_folder)) { sqimap_messages_copy($imap_stream, $start, $end, $trash_folder); } sqimap_messages_flag($imap_stream, $start, $end, "Deleted", true); }
/** * Recursively walk the tree of trash mailboxes and delete all folders and messages * * @param int index the place in the tree to start, usually 0 * @param stream imap_stream the IMAP connection to send commands to * @param array tree the tree to walk * @return void */ function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) { global $trash_folder; if ($tree[$index]['doIHaveChildren']) { for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) { walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree); } if ($tree[$index]['value'] != $trash_folder) { sqimap_mailbox_delete($imap_stream, $tree[$index]['value']); } else { $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder); if ($mbx_response['EXISTS'] > 0) { sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true); // CLOSE === EXPUNGE and UNSELECT sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message); } } } else { if ($tree[$index]['value'] != $trash_folder) { sqimap_mailbox_delete($imap_stream, $tree[$index]['value']); } else { $mbx_response = sqimap_mailbox_select($imap_stream, $trash_folder); if ($mbx_response['EXISTS'] > 0) { sqimap_messages_flag($imap_stream, 1, '*', 'Deleted', true); // CLOSE === EXPUNGE and UNSELECT sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message); } } } }
function deliverMessage($composeMessage, $draft = false) { global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $popuser, $usernamedata, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $color, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent; global $imapServerAddress, $imapPort, $sent_folder, $key; $rfc822_header = $composeMessage->rfc822_header; $abook = addressbook_init(false, true); $rfc822_header->to = $rfc822_header->parseAddress($send_to, true, array(), '', $domain, array(&$abook, 'lookup')); $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc, true, array(), '', $domain, array(&$abook, 'lookup')); $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc, true, array(), '', $domain, array(&$abook, 'lookup')); $rfc822_header->priority = $mailprio; $rfc822_header->subject = $subject; $special_encoding = ''; if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } $composeMessage->setBody($body); if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $from_mail = $idents[$identity]['email_address']; $full_name = $idents[$identity]['full_name']; $reply_to = $idents[$identity]['reply_to']; if (!$from_mail) { $from_mail = "{$popuser}@{$domain}"; } $rfc822_header->from = $rfc822_header->parseAddress($from_mail, true); if ($full_name) { $from = $rfc822_header->from[0]; if (!$from->host) { $from->host = $domain; } $full_name_encoded = encodeHeader($full_name); if ($full_name_encoded != $full_name) { $from_addr = $full_name_encoded . ' <' . $from->mailbox . '@' . $from->host . '>'; } else { $from_addr = '"' . $full_name . '" <' . $from->mailbox . '@' . $from->host . '>'; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true); } if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true); } /* Receipt: On Read */ if (isset($request_mdn) && $request_mdn) { $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail, true); } /* Receipt: On Delivery */ if (isset($request_dr) && $request_dr) { $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; } /* multipart messages */ if (count($composeMessage->entities)) { $message_body = new Message(); $message_body->body_part = $composeMessage->body_part; $composeMessage->body_part = ''; $mime_header = new MessageHeader(); $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '8bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $message_body->mime_header = $mime_header; array_unshift($composeMessage->entities, $message_body); $content_type = new ContentType('multipart/mixed'); } else { $content_type = new ContentType('text/plain'); if ($special_encoding) { $rfc822_header->encoding = $special_encoding; } else { $rfc822_header->encoding = '8bit'; } if ($default_charset) { $content_type->properties['charset'] = $default_charset; } } $rfc822_header->content_type = $content_type; $composeMessage->rfc822_header = $rfc822_header; /* Here you can modify the message structure just before we hand it over to deliver */ $hookReturn = do_hook('compose_send', $composeMessage); /* Get any changes made by plugins to $composeMessage. */ if (is_object($hookReturn[1])) { $composeMessage = $hookReturn[1]; } if (!$useSendmail && !$draft) { require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php'; $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech; $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php'; global $sendmail_path; $deliver = new Deliver_SendMail(); $stream = $deliver->initStream($composeMessage, $sendmail_path); } elseif ($draft) { global $draft_folder; require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (sqimap_mailbox_exists($imap_stream, $draft_folder)) { require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $length = $imap_deliver->mail($composeMessage); sqimap_append($imap_stream, $draft_folder, $length); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done($imap_stream, $draft_folder); sqimap_logout($imap_stream); unset($imap_deliver); return $length; } else { $msg = '<br />' . sprintf(_("Error: Draft folder %s does not exist."), $draft_folder); plain_error_message($msg, $color); return false; } } $succes = false; if ($stream) { $length = $deliver->mail($composeMessage, $stream); $succes = $deliver->finalizeStream($stream); } if (!$succes) { $msg = $deliver->dlv_msg . '<br />' . _("Server replied: ") . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg; plain_error_message($msg, $color); } else { unset($deliver); $move_to_sent = getPref($data_dir, $username, 'move_to_sent'); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); /* Move to sent code */ if (isset($default_move_to_sent) && $default_move_to_sent != 0) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && ($sent_folder != '' || $sent_folder != 'none') && sqimap_mailbox_exists($imap_stream, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if (isset($move_to_sent) && $move_to_sent != 0 || !isset($move_to_sent)) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if ($fld_sent && $svr_allow_sent && !$lcl_allow_sent || $fld_sent && $lcl_allow_sent) { global $passed_id, $mailbox, $action; if ($action == 'reply' || $action == 'reply_all') { $save_reply_with_orig = getPref($data_dir, $username, 'save_reply_with_orig'); if ($save_reply_with_orig) { $sent_folder = $mailbox; } } sqimap_append($imap_stream, $sent_folder, $length); require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done($imap_stream, $sent_folder); unset($imap_deliver); } global $passed_id, $mailbox, $action; ClearAttachments($composeMessage); if ($action == 'reply' || $action == 'reply_all') { sqimap_mailbox_select($imap_stream, $mailbox); sqimap_messages_flag($imap_stream, $passed_id, $passed_id, 'Answered', false); } sqimap_logout($imap_stream); } return $succes; }
/** * Deletes specified messages and moves them to trash if possible * Obsolete */ function sqimap_messages_delete($imap_stream, $start, $end, $mailbox) { global $move_to_trash, $trash_folder, $auto_expunge, $uid_support; if ($move_to_trash == true && (sqimap_mailbox_exists($imap_stream, $trash_folder) && $mailbox != $trash_folder)) { /** * turn off internal error handling (fifth argument = false) and * ignore copy to trash errors (allows to delete messages when overquota) */ sqimap_messages_copy($imap_stream, $start, $end, $trash_folder, false); } sqimap_messages_flag($imap_stream, $start, $end, "Deleted", true); }
function delete_move_next_move() { global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox; // Move message sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox); sqimap_messages_flag($imapConnection, $move_id, $move_id, "Deleted"); if ($auto_expunge == true) { sqimap_mailbox_expunge($imapConnection, $mailbox, true); } }
function delete_move_next_move() { global $imapConnection, $mailbox, $auto_expunge, $lastTargetMailbox; sqgetGlobalVar('move_id', $move_id, SQ_POST); sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST); // Move message sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox); sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true); if ($auto_expunge) { delete_move_expunge_from_all($move_id); // sqimap_mailbox_expunge($imapConnection, $mailbox, true); } if ($targetMailbox != $lastTargetMailbox) { $lastTargetMailbox = $targetMailbox; sqsession_register($lastTargetMailbox, 'lastTargetMailbox'); } }
/** * FIXME: Undocumented function * @access private */ function spam_filters($imap_stream) { global $data_dir, $username, $uid_support; global $SpamFilters_YourHop; global $SpamFilters_DNScache; global $SpamFilters_SharedCache; global $SpamFilters_BulkQuery; $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan'); $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder'); $filters = load_spam_filters(); if ($SpamFilters_SharedCache) { filters_LoadCache(); } $run = 0; foreach ($filters as $Key => $Value) { if ($Value['enabled']) { $run++; } } // short-circuit if ($run == 0) { return; } sqimap_mailbox_select($imap_stream, 'INBOX'); // Ask for a big list of all "Received" headers in the inbox with // flags for each message. Kinda big. if ($filters_spam_scan != 'new') { $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' . '(RECEIVED)])', true, $response, $message, $uid_support); } else { $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, $uid_support); if ($response != 'OK' || trim($read[0]) == '* SEARCH') { $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' . '(RECEIVED)])', true, $response, $message, $uid_support); } else { if (isset($read[0])) { if (preg_match("/^\\* SEARCH (.+)\$/", $read[0], $regs)) { $search_array = preg_split("/ /", trim($regs[1])); } } $msgs_str = sqimap_message_list_squisher($search_array); $imap_query = 'FETCH ' . $msgs_str; $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS '; $imap_query .= '(RECEIVED)])'; $read = sqimap_run_command($imap_stream, $imap_query, true, $response, $message, $uid_support); } } if (isset($response) && $response != 'OK') { return; } if (strlen($SpamFilters_BulkQuery) > 0) { filters_bulkquery($filters_spam_scan, $filters, $read); } $i = 0; while ($i < count($read)) { // EIMS will give funky results $Chunks = explode(' ', $read[$i]); if ($Chunks[0] != '*') { $i++; continue; } $MsgNum = $Chunks[1]; $IPs = array(); $i++; $IsSpam = 0; // Look through all of the Received headers for IP addresses // Stop when I get ")" on a line // Stop if I get "*" on a line (don't advance) // and above all, stop if $i is bigger than the total # of lines while ($i < count($read) && ($read[$i][0] != ')' && $read[$i][0] != '*' && $read[$i][0] != "\n") && !$IsSpam) { // Check to see if this line is the right "Received from" line // to check if (is_int(strpos($read[$i], $SpamFilters_YourHop))) { // short-circuit and skip work if we don't scan this one $read[$i] = ereg_replace('[^0-9\\.]', ' ', $read[$i]); $elements = explode(' ', $read[$i]); foreach ($elements as $value) { if ($value != '' && ereg('[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}', $value, $regs)) { $Chunks = explode('.', $value); if (filters_spam_check_site($Chunks[0], $Chunks[1], $Chunks[2], $Chunks[3], $filters)) { $IsSpam++; break; // no sense in checking more IPs } // If we've checked one IP and YourHop is // just a space if ($SpamFilters_YourHop == ' ') { break; // don't check any more } } } } $i++; } // Lookie! It's spam! Yum! if ($IsSpam) { if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { // check if message copy was successful if (sqimap_messages_copy($imap_stream, $MsgNum, $MsgNum, $filters_spam_folder, false)) { sqimap_messages_flag($imap_stream, $MsgNum, $MsgNum, 'Deleted', false); } } } else { } } sqimap_mailbox_expunge($imap_stream, 'INBOX'); if ($SpamFilters_SharedCache) { filters_SaveCache(); } else { sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); } }