Ticket #238: inpatch.patch
| File inpatch.patch, 12.2 kB (added by dmorton, 6 years ago) |
|---|
-
cache.php
227 227 $reported = 0; 228 228 $deleted = 0; 229 229 $rescued = 0; 230 231 $ham_list = array(); 232 $spam_list = array(); 233 $delete_list = array(); 234 230 235 global $_POST, $lang, $logger; 231 236 $items = $_POST['cache_item']; 232 237 foreach ($items as $type => $mail_item) { … … 240 245 if ($newtype == "spam") { 241 246 switch ($this->type) { 242 247 case 'ham': 243 // Mark the item as Confirmed Spam 244 $update = "UPDATE maia_mail_recipients SET type = 'C' " . 245 "WHERE recipient_id = ? AND mail_id = ?"; 246 $this->dbh->query($update, array($euid, $mail_id)); 248 // Mark the item as false negative. It will also be marked as confirmed. 247 249 record_mail_stats($euid, $mail_id, "fn"); 248 250 $reported++; 249 251 break; 250 case 'spam': 251 confirm_spam($euid, $mail_id); 252 default: 252 253 $confirmed++; 253 default:254 254 } 255 array_push($spam_list, $mail_id); 256 255 257 //send item 256 258 } elseif ($newtype == "ham") { 257 259 switch ($this->type) { 258 260 case 'ham': 259 $logger->debug('confirming ' . $mail_id . ' as ham'); 260 confirm_ham($euid, $mail_id); 261 array_push($ham_list, $mail_id); 261 262 $confirmed++; 262 263 break; 263 264 default: 264 $result = rescue_item($euid, $mail_id); 265 $result = rescue_item($euid, $mail_id); // done individually because of mail delivery 265 266 if (strncmp($result, "2", 1) == 0) { 266 267 $rescued++; 267 268 } else { … … 270 271 } 271 272 //delete item. 272 273 } elseif ($newtype == "delete") { 273 $logger->debug('deleting ' . $mail_id); 274 275 delete_mail_reference($euid, $mail_id); 274 array_push($delete_list, $mail_id); 276 275 $deleted++; 277 276 } 278 277 } 279 278 } 279 280 if (count($ham_list) > 0) { confirm_ham($euid, $ham_list ); } 281 if (count($spam_list) > 0) { confirm_spam($euid, $spam_list); } 282 if (count($delete_list) > 0 ) { delete_mail_reference($euid, $delete_list); } 280 283 281 284 update_mail_stats($euid, "suspected_ham"); 282 285 if ($confirmed > 0) { -
maia_db.php
1676 1676 1677 1677 1678 1678 /* 1679 * delete_mail(): Deletes a single mail itemand all references1680 * to it.1679 * delete_mail(): Deletes mail items and all references 1680 * to them. 1681 1681 */ 1682 function delete_mail($mail_id )1682 function delete_mail($mail_ids) 1683 1683 { 1684 1684 global $dbh; 1685 1685 1686 1686 // Delete any references to recipients 1687 $delete = "DELETE FROM maia_mail_recipients WHERE mail_id = ?";1688 $dbh->query($delete, array($mail_id));1687 $delete = "DELETE FROM maia_mail_recipients WHERE mail_id IN (?" . str_repeat(',?', count($mail_ids) - 1) . ")"; 1688 $dbh->query($delete, $mail_ids); 1689 1689 1690 1690 // Delete any references to SpamAssassin rules 1691 $delete = "DELETE FROM maia_sa_rules_triggered WHERE mail_id = ?";1692 $dbh->query($delete, array($mail_id));1691 $delete = "DELETE FROM maia_sa_rules_triggered WHERE mail_id IN (?" . str_repeat(',?', count($mail_ids) - 1) . ")"; 1692 $dbh->query($delete, $mail_ids); 1693 1693 1694 1694 // Delete any references to viruses 1695 $delete = "DELETE FROM maia_viruses_detected WHERE mail_id = ?";1696 $dbh->query($delete, array($mail_id));1695 $delete = "DELETE FROM maia_viruses_detected WHERE mail_id IN (?" . str_repeat(',?', count($mail_ids) - 1) . ")"; 1696 $dbh->query($delete, $mail_ids); 1697 1697 1698 1698 // Delete any references to banned file attachments 1699 $delete = "DELETE FROM maia_banned_attachments_found WHERE mail_id = ?";1700 $dbh->query($delete, array($mail_id));1699 $delete = "DELETE FROM maia_banned_attachments_found WHERE mail_id IN (?" . str_repeat(',?', count($mail_ids) - 1) . ")"; 1700 $dbh->query($delete, $mail_ids); 1701 1701 1702 1702 // Delete the mail item itself 1703 $delete = "DELETE FROM maia_mail WHERE id = ?";1704 $dbh->query($delete, array($mail_id));1703 $delete = "DELETE FROM maia_mail WHERE id IN (?" . str_repeat(',?', count($mail_ids) - 1) . ")"; 1704 $dbh->query($delete, $mail_ids); 1705 1705 } 1706 1706 1707 1707 1708 1708 /* 1709 * delete_mail_references(): Deletes a single mail item'srecipient1709 * delete_mail_references(): Deletes mail items' recipient 1710 1710 * references. 1711 1711 */ 1712 function delete_mail_reference($user_id, $mail_id )1712 function delete_mail_reference($user_id, $mail_ids) 1713 1713 { 1714 1714 global $dbh; 1715 global $logger; 1715 1716 1716 // Delete a specific user's recipient reference to this mail. 1717 $delete = "DELETE FROM maia_mail_recipients WHERE recipient_id = ? AND mail_id = ?"; 1718 $dbh->query($delete, array($user_id, $mail_id)); 1717 // Delete a specific users' recipient reference to these mail messages. 1718 $delete = "DELETE FROM maia_mail_recipients WHERE recipient_id = ? AND mail_id IN ("; 1719 $delete .= '?' . str_repeat(',?', count($mail_ids) - 1); 1720 $delete .= ")"; 1719 1721 1720 // If there are no other recipients referenced by this mail item, 1722 $dbh->query($delete, array_merge($user_id, $mail_ids)); 1723 1724 // If there are no other recipients referenced by each mail item, 1721 1725 // delete it. 1722 $select = "SELECT recipient_id FROM maia_mail_recipients WHERE mail_id = ?"; 1723 $sth = $dbh->query($select, array($mail_id)); 1724 if (!$sth->fetchRow()) { 1725 delete_mail($mail_id); 1726 1727 $select = "SELECT recipient_id, mail_id, maia_mail.id ". 1728 "FROM maia_mail " . 1729 "LEFT JOIN maia_mail_recipients " . 1730 "ON maia_mail.id = maia_mail_recipients.mail_id " . 1731 "WHERE maia_mail.id IN (?" . str_repeat(',?', count($mail_ids) - 1) .") " . 1732 "AND mail_id IS NULL"; 1733 $sth = $dbh->query($select, $mail_ids); 1734 if (DB::isError($sth)) { 1735 1736 $logger->err('Standard Message: ' . $sth->getMessage() . $select); 1737 exit; 1726 1738 } 1727 $sth->free(); 1739 $deletions = array(); 1740 foreach ($mail_ids as $mail_id) { 1741 while ($row = $sth->fetchrow() ) { 1742 array_push($deletions, $row['id']); 1743 } 1744 $sth->free(); 1745 } 1746 delete_mail($deletions); 1747 1728 1748 } 1729 1749 1730 1750 … … 1805 1825 } 1806 1826 $sth->free(); 1807 1827 } 1828 1829 function get_database_type($dbh) 1830 { 1831 return $dbh->phptype; 1832 } 1808 1833 1809 1834 1835 /* update the confirmation settings on one or multiple items. */ 1836 function set_item_confirmations($message_type, $user_id, $mail_id) { 1837 global $dbh; 1838 if (get_database_type($dbh) == "mysql") { 1839 $token_code = "CONCAT('expired', recipient_id, mail_id)"; 1840 } else { 1841 $token_code = '"expired" || recipient_id || mail_id'; 1842 } 1843 $update = "UPDATE maia_mail_recipients SET type = ?, token=" . $token_code . 1844 " WHERE recipient_id = ? AND mail_id IN ("; 1845 1846 $update .= '?' . str_repeat(',?', count($mail_id) - 1); 1847 1848 $update .= ")"; 1849 $dbh->query($update, array_merge($message_type, $user_id, $mail_id)); 1850 } 1851 1810 1852 /* 1811 * report_spam(): Confirm a mail item as false negative spam for one recipient. 1812 */ 1853 * report_spam(): Confirm mail item(s) as false negative spam. 1854 mail_id can be a scalar or an array 1855 */ 1813 1856 function report_spam($user_id, $mail_id) 1814 1857 { 1815 1858 global $dbh; 1816 1859 1817 $expired_token = 'expired' . $user_id . $mail_id; 1818 1819 // Mark the item as Confirmed Spam 1820 $update = "UPDATE maia_mail_recipients SET type = 'C', token=? " . 1821 "WHERE recipient_id = ? AND mail_id = ?"; 1822 $dbh->query($update, array($expired_token, $user_id, $mail_id)); 1823 1824 // Add the item to the Spam stats columns 1860 // Mark the items as Confirmed Spam 1861 confirm_spam($user_id, $mail_id); 1862 1863 // Also add the items to the Spam stats columns 1825 1864 record_mail_stats($user_id, $mail_id, "fn"); 1826 1865 1827 1866 } 1828 1867 1829 1868 /* 1830 * confirm_spam(): Confirm a mail item as spam for one recipient. 1869 * confirm_spam(): Confirm mail item(s) as spam. 1870 mail_id can be a scalar or an array 1831 1871 */ 1832 1872 function confirm_spam($user_id, $mail_id) 1833 1873 { 1834 1874 global $dbh; 1835 1875 1836 $expired_token = 'expired' . $user_id . $mail_id; 1876 // Mark the items as Confirmed Spam 1877 set_item_confirmations('C', $user_id, $mail_id); 1837 1878 1838 // Mark the item as Confirmed Spam 1839 $update = "UPDATE maia_mail_recipients SET type = 'C', token=? " . 1840 "WHERE recipient_id = ? AND mail_id = ?"; 1841 $dbh->query($update, array($expired_token, $user_id, $mail_id)); 1842 1843 // Add the item to the Spam stats columns 1879 // Add the items to the Spam stats columns 1844 1880 record_mail_stats($user_id, $mail_id, "spam"); 1845 1881 } 1846 1882 1847 1883 1848 1884 /* 1849 * confirm_ham(): Confirm a mail item as ham for one recipient. 1885 * confirm_ham(): Confirm mail item(s) as ham. 1886 mail_id can be a scalar or an array 1850 1887 */ 1851 function confirm_ham($user_id, $mail_id )1888 function confirm_ham($user_id, $mail_ids) 1852 1889 { 1853 1890 global $dbh; 1854 1891 1855 $expired_token = 'expired' . $user_id . $mail_id; 1892 // Mark the items as Confirmed Ham 1893 set_item_confirmations('G', $user_id, $mail_ids); 1856 1894 1857 // Mark the item as Confirmed Ham 1858 $update = "UPDATE maia_mail_recipients SET type = 'G', token=? " . 1859 "WHERE recipient_id = ? AND mail_id = ?"; 1860 $dbh->query($update, array($expired_token, $user_id, $mail_id)); 1861 1862 // Add the item to the Ham stats columns 1863 record_mail_stats($user_id, $mail_id, "ham"); 1895 // Add the items to the Ham stats columns 1896 record_mail_stats($user_id, $mail_ids, "ham"); 1864 1897 } 1865 1898 1866 1899 … … 1872 1905 { 1873 1906 global $dbh; 1874 1907 1875 $expired_token = 'expired' . $user_id . $mail_id;1876 1877 1908 $select = "SELECT sender_email, contents, " . 1878 1909 "envelope_to, maia_mail_recipients.type " . 1879 1910 "FROM maia_mail, maia_mail_recipients " . … … 1922 1953 if ($succeeded = (strncmp($smtp_result, "2", 1) == 0)) { 1923 1954 if ($type == "S") { 1924 1955 record_mail_stats($user_id, $mail_id, "fp"); 1925 $update = "UPDATE maia_mail_recipients SET type = 'G', token=? " . 1926 "WHERE recipient_id = ? AND mail_id = ?"; 1927 $dbh->query($update, array($expired_token, $user_id, $mail_id)); 1956 set_item_confirmations('G', $user_id, $mail_id); 1928 1957 if (get_user_value($user_id, "auto_whitelist") == "Y") { 1929 1958 add_address_to_wb_list($user_id, $sender_email, "W"); 1930 1959 } … … 2036 2065 2037 2066 2038 2067 /* 2039 * record_mail_stats(): Recalculate the specified user 's stats record2068 * record_mail_stats(): Recalculate the specified users' stats records 2040 2069 * for items of the specified (static) type, after 2041 2070 * suspected [spam|ham] is confirmed. 2042 2071 */ 2043 function record_mail_stats($euid, $mail_id , $type)2072 function record_mail_stats($euid, $mail_ids, $type) 2044 2073 { 2045 global $dbh;2046 2074 global $dbh; 2075 foreach ($mail_ids as $mail_id) { 2047 2076 $select = "SELECT received_date, size, score " . 2048 2077 "FROM maia_mail WHERE id = ?"; 2049 2078 $sth = $dbh->query($select, array($mail_id)); … … 2161 2190 $sth2->free(); 2162 2191 } 2163 2192 $sth->free(); 2193 } 2164 2194 } 2165 2195 2166 2196 /*

