function rescue_item($user_id, $mail_id, $resend = false) { global $dbh, $logger; $sth = $dbh->prepare("SELECT sender_email, contents, " . "envelope_to, maia_mail_recipients.type " . "FROM maia_mail, maia_mail_recipients " . "WHERE maia_mail.id = maia_mail_recipients.mail_id " . "AND maia_mail_recipients.recipient_id = ? " . "AND maia_mail_recipients.mail_id = ?"); $res = $sth->execute(array($user_id, $mail_id)); if (PEAR::isError($sth)) { die($sth->getMessage()); } if ($row = $res->fetchrow()) { $sender_email = $row["sender_email"]; $body = $row["contents"]; $type = $row["type"]; if (extension_loaded('mcrypt')) { if (text_is_encrypted($body)) { $key = get_encryption_key(); $body = decrypt_text($key, $body); } } if (is_a_domain_default_user($user_id)) { // System default user (@.) or domain-class user (e.g. @domain) $my_email_address = $row["envelope_to"]; } else { // Regular user (e.g. user@domain) $rlist = explode(" ", trim($row["envelope_to"])); $sth2 = $dbh->prepare("SELECT email FROM users " . "WHERE maia_user_id = ? " . "AND email = ?"); $my_email_address = ""; foreach ($rlist as $rmail) { $res2 = $sth2->execute(array($user_id, $rmail)); if (PEAR::isError($sth2)) { die($sth2->getMessage()); } if ($row2 = $res2->fetchrow()) { $my_email_address = $row2["email"]; break; } } $sth2->free(); } if (!empty($my_email_address)) { if ($resend || $type != 'P') { // don't send if it is a labeled fp $smtp_result = smtp_send($sender_email, $my_email_address, $body); } else { $smtp_result = "200 no delivery needed"; } if (($succeeded = strncmp($smtp_result, "2", 1) == 0) || $type == 'P') { if (!$resend) { if ($type == 'S' || $type == 'P') { record_mail_stats($user_id, $mail_id, "fp"); if (get_user_value($user_id, "auto_whitelist") == "Y") { add_address_to_wb_list($user_id, $sender_email, "W"); } } set_item_confirmations('G', $user_id, $mail_id); } } else { $logger->err("rescue attempt failed! " . $smtp_result); } } else { $smtp_result = $lang['text_rescue_error'] . "(EmptyAddress)"; // code really shouldn't be here. } } else { $smtp_result = $lang['text_rescue_error'] . "(MessageNotFound)"; // code really shouldn't be here. } $sth->free(); $logger->info($smtp_result); return $smtp_result; }
function confirm_cache($euid) { $message = ""; $ham_list = array(); $spam_list = array(); $delete_list = array(); $resend_list = array(); global $_POST, $lang, $logger; if (isset($_POST['cache_item'])) { $items = $_POST['cache_item']; } else { $items = array(); } foreach ($items as $type => $mail_item) { foreach ($mail_item as $mail_id => $value) { if ($type == "generic") { $newtype = $_POST['submit']; } else { $newtype = $value; } // report item if ($newtype == "spam") { switch ($this->type) { case 'ham': // Mark the item as false negative. It will also be marked as confirmed. record_mail_stats($euid, $mail_id, "fn"); $this->reported++; break; default: $this->confirmed++; } array_push($spam_list, $mail_id); //send item } elseif ($newtype == "ham") { switch ($this->type) { case 'ham': array_push($ham_list, $mail_id); $this->confirmed++; break; default: $result = rescue_item($euid, $mail_id); // done individually because of mail delivery if (strncmp($result, "2", 1) == 0) { $this->rescued++; } else { $message .= $result . "\n"; } } //delete item. } elseif ($newtype == "delete") { array_push($delete_list, $mail_id); $this->deleted++; // resend the item and leave it in the cache } elseif ($newtype == "resend") { array_push($resend_list, $mail_id); $this->resent++; } } } if (count($ham_list) > 0) { confirm_ham($euid, $ham_list); } if (count($spam_list) > 0) { confirm_spam($euid, $spam_list); } if (count($delete_list) > 0) { delete_mail_reference($euid, $delete_list); } if (count($resend_list) > 0) { resend_message($euid, $resend_list); } update_mail_stats($euid, "suspected_ham"); if ($this->confirmed > 0) { switch ($this->type) { case "ham": $message .= sprintf($lang['text_ham_confirmed'], $this->confirmed) . ".<br>"; break; case "spam": $message .= sprintf($lang['text_spam_confirmed'], $this->confirmed) . ".<br>"; break; default: $message .= sprintf($lang['text_messages_confirmed'], $this->confirmed) . ".<br>"; } } if ($this->reported > 0) { $message .= sprintf($lang['text_spam_reported'], $this->reported) . ".<br>"; } if ($this->deleted > 0) { switch ($this->type) { case 'ham': $message .= sprintf($lang['text_ham_deleted'], $this->deleted) . ".<br>"; break; case 'spam': $message .= sprintf($lang['text_spam_deleted'], $this->deleted) . ".<br>"; break; case 'virus': $message .= sprintf($lang['text_viruses_deleted'], $this->deleted) . ".<br>"; break; case 'attachment': $message .= sprintf($lang['text_attachments_deleted'], $this->deleted) . ".<br>"; break; case 'header': $message .= sprintf($lang['text_headers_deleted'], $this->deleted) . ".<br>"; break; } } if ($this->rescued > 0) { switch ($this->type) { case 'spam': $message .= sprintf($lang['text_spam_rescued'], $this->rescued) . ".<br>"; break; case 'virus': $message .= sprintf($lang['text_viruses_rescued'], $this->rescued) . ".<br>"; break; case 'attachment': $message .= sprintf($lang['text_attachments_rescued'], $this->rescued) . ".<br>"; break; case 'header': $message .= sprintf($lang['text_headers_rescued'], $this->rescued) . ".<br>"; break; } } if ($this->resent > 0) { $message .= sprintf($lang['text_message_resent'], $this->resent) . ".<br>"; } return $message; }