diff -r -u twig-2.7.7/config/config.inc.php3 twig-2.7.7-dev/config/config.inc.php3 --- twig-2.7.7/config/config.inc.php3 2002-05-11 02:06:51.000000000 -0700 +++ twig-2.7.7-dev/config/config.inc.php3 2003-12-15 01:43:01.000000000 -0800 @@ -2,9 +2,9 @@ " size="">
+ [hiro-tan] " alt="[]">
diff -r -u twig-2.7.7/config/images.inc.php3 twig-2.7.7-dev/config/images.inc.php3 --- twig-2.7.7/config/images.inc.php3 2000-11-25 11:24:40.000000000 -0800 +++ twig-2.7.7-dev/config/images.inc.php3 2003-12-15 01:54:36.000000000 -0800 @@ -46,5 +46,6 @@ $img["rhand"] = $config["imgdir"] . "rhand.gif"; $img["thumbsup"] = $config["imgdir"] . "thumbsup.gif"; $img["thumbsdown"] = $config["imgdir"] . "thumbsdown.gif"; + $img["spam"] = $config["imgdir"] . "spam.jpg"; ?> diff -r -u twig-2.7.7/features/mail/mail.delete.inc.php3 twig-2.7.7-dev/features/mail/mail.delete.inc.php3 --- twig-2.7.7/features/mail/mail.delete.inc.php3 2002-06-06 10:09:14.000000000 -0700 +++ twig-2.7.7-dev/features/mail/mail.delete.inc.php3 2003-12-16 01:33:26.000000000 -0800 @@ -48,6 +48,17 @@ { include( "features/mail/mail.undelete.inc.php3" ); } +elseif ($submitbutton["unspam"]) + { + while (list ($path,$foo) = each($delete)) + { + TWIGDebug("MARKING AS NONSPAM : $path",1); + user_mark_as_nonspam($mbox,$path); + } + reset($delete); + include( "features/mail/mail.undelete.inc.php3" ); + } + elseif( $delete ) { @@ -55,8 +66,22 @@ // Disable after TWIG 2.7.6 ksort( $delete ); $delcount=0; + + if ($submitbutton["spam"]) + { + while (list ($path,$foo) = each($delete)) + { + TWIGDebug("MARKING AS SPAM : $path",1); + user_mark_as_spam($mbox,$path); + } + } + + reset($delete); + while( list( $path, $foo) = each( $delete ) ) { + TWIGDebug("DELETING : $path",1); + $delindex[$delcount++] = $path; } while( $delcount > 0 ) @@ -87,6 +112,7 @@ } else { + TWIGMailDelete( $mbox, $path ); if( GetPref( "dande", $dbconfig["prefs_table"], $config["defaults"]["mail"]["dande"] ) ) { TWIGMailEmptyTrash( $mbox ); } diff -r -u twig-2.7.7/features/mail/mail.feature.php3 twig-2.7.7-dev/features/mail/mail.feature.php3 --- twig-2.7.7/features/mail/mail.feature.php3 2000-11-14 15:25:27.000000000 -0800 +++ twig-2.7.7-dev/features/mail/mail.feature.php3 2003-12-13 23:56:14.000000000 -0800 @@ -7,10 +7,13 @@ } else { + + if( !$context["action"] ) { $context["action"] = "main"; } $mbox = TWIGOpenMB( $session["mailbox"], $mbox ); require( "features/mail/mail." . $context["action"] . ".inc.php3" ); + } ?> diff -r -u twig-2.7.7/features/mail/mail.inc.php3 twig-2.7.7-dev/features/mail/mail.inc.php3 --- twig-2.7.7/features/mail/mail.inc.php3 2002-10-24 07:41:40.000000000 -0700 +++ twig-2.7.7-dev/features/mail/mail.inc.php3 2003-12-20 15:26:57.175820400 -0800 @@ -836,6 +836,244 @@ return array( $maxlevel, $tree ); } +Function is_marked_as_spam($mailbox,$path) +{ + // look up $item in twig_spam + + global $login, $dbconfig, $userprefs; + + $header = imap_headerinfo($mailbox, $path); + $UID = $header->message_id; + $result = dbQuery( "SELECT * FROM twig_spam WHERE msg='$UID'" ); + $rows = dbNumRows( $result); + if( dbNumRows( $result ) > 0) + { + return TRUE; + } + return FALSE; +} + +Function user_mark_as_spam($mbox,$path) +{ + TWIGDebug("marking message : $path as spam",1); + $header = imap_headerinfo($mbox, $path); + $UID = $header->message_id; + $result = dbQuery("SELECT msg FROM twig_nonspam WHERE msg = '$UID'"); + $rows = dbNumRows($result); + if ($rows>0) { + $result = dbQuery("DELETE FROM twig_nonspam WHERE msg = '$UID'"); + $undo_table = "twig_nonspam_tokens"; + } + else { + $undo_table = ""; + } + $result = dbQuery("SELECT msg FROM twig_spam WHERE msg = '$UID'"); + $rows = dbNumRows($result); + if ($rows==0) { + $result = dbQuery("INSERT INTO twig_spam (msg) values ('$UID')"); + user_mark_as($mbox,$path,"twig_spam_tokens",$undo_table); + } +} + +Function user_mark_as_nonspam($mbox,$path) +{ + TWIGDebug("marking message : $path as nonspam",1); + $header = imap_headerinfo($mbox, $path); + $UID = $header->message_id; + $result = dbQuery("SELECT msg FROM twig_spam WHERE msg = '$UID'"); + $rows = dbNumRows($result); + if ($rows>0) { + $result = dbQuery("DELETE FROM twig_spam WHERE msg = '$UID'"); + $undo_table = "twig_spam_tokens"; + } + else { + $undo_table = ""; + } + $result = dbQuery("SELECT msg FROM twig_nonspam WHERE msg = '$UID'"); + $rows = dbNumRows($result); + if ($rows==0) { + $result = dbQuery("INSERT INTO twig_nonspam (msg) values ('$UID')"); + user_mark_as($mbox,$path,"twig_nonspam_tokens",$undo_table); + } +} + +Function user_mark_as($mbox,$path,$tokens_table,$tokens_undo_table) +{ + // get nbad : # spams. + // get ngood : # nonspams. + // + // get email headers,body, and (text or html) attachments, and concatenate into one big string + $text = TWIGMailFetchHeader( $mbox, $path ); + $text = $text.TWIGMailFetchBody($mbox,$path,"1" ); + + // split into tokens. + $tokens = preg_split("/\s+/",$text,-1,PREG_SPLIT_NO_EMPTY); + foreach ($tokens as $token) { + $token = strtolower($token); + $token = str_replace("'","\'",$token); + $token = str_replace(",","",$token); + $token = str_replace("!","",$token); + $result = dbQuery("SELECT times FROM $tokens_table WHERE token='$token'"); + if(dbNumRows( $result)) { + $row = dbResultArray($result,0); + $times = $row["times"]; + $times++; + dbquery("UPDATE $tokens_table SET times = $times WHERE token='$token'"); + } + else { + $result = dbQuery( "INSERT INTO $tokens_table (token,times) VALUES ('$token','1')"); + } + + if ($tokens_undo_table != "") { + $result = dbQuery("SELECT times FROM $tokens_undo_table WHERE token='$token'"); + if(dbNumRows( $result)) { + $row = dbResultArray($result,0); + $times = $row["times"]; + $times--; + if ($times < 0) { + TWIGDebug("ERROR : $times < 0",1); + } + else { + dbquery("UPDATE $tokens_undo_table SET times = $times WHERE token='$token'"); + } + } + } + } +} + +Function classify_whether_spam($mbox,$path) +{ + TWIGDebug("classifying message : $path",1); + + $spams = dbNumRows(dbQuery("SELECT msg FROM twig_spam")); + if ($spams == 0) { + $spams++; + } + $non_spams = dbNumRows(dbQuery("SELECT msg FROM twig_nonspam")); + if ($non_spams == 0) { + $non_spams++; + } + + // get email headers,body, and (text or html) attachments, and concatenate into one big string + $text = TWIGMailFetchHeader( $mbox, $path ); + $text = $text.TWIGMailFetchBody($mbox,$path,"1" ); + + // split into tokens. + $tokens = preg_split("/\s+/",$text,-1,PREG_SPLIT_NO_EMPTY); + + $queue = array(); + $queue_cutoff = 0.0; + + foreach ($tokens as $token) { + $token = strtolower($token); + #need to escape single quotes(') so that we can create an SQL query. + $token = str_replace("'","\'",$token); + + $result = dbQuery("SELECT times FROM twig_spam_tokens WHERE token='$token'"); + if(dbNumRows( $result)) { + $row = dbResultArray($result,0); + $occurances_in_spam = $row["times"]; + } + else { + $occurances_in_spam = 0; + } + + $result = dbQuery("SELECT times FROM twig_nonspam_tokens WHERE token='$token'"); + if(dbNumRows( $result)) { + $row = dbResultArray($result,0); + $occurances_in_nonspam = $row["times"]; + } + else { + $occurances_in_nonspam = 0; + } + + # calculate probability : P(spam|token) + $numerator = ($occurances_in_spam/$spams); + $denominator = (($occurances_in_nonspam/$non_spams)+($occurances_in_spam/$spams)); + if ($denominator > 0) { + $probability = min(0.9,max(0.1,$numerator/$denominator)); + } + else { + $probability = 0.5; + } + + # distance : distance from center (0.5). + $distance = abs(0.5-$probability); + $esc = HTMLSpecialChars($token); + + TWIGDebug("

tok : $esc; num = $numerator; denom = $denominator

",10); + TWIGDebug("

tok : $esc; prob = $probability (os:$occurances_in_spam;ons:$occurances_in_nonspam;#s:$spams;#ns:$non_spams); dist = $distance

",10); + + TWIGDebug("

COMPARING dist : $distance with cutoff $queue_cutoff

",10); + if ($distance >= $queue_cutoff) { + $queue += array($token => $probability); + if (count($queue) > 15) { + # find minimum element and remove it. + reset($queue); + while(list($tok,$prob) = each($queue)) { + if (abs(0.5-$prob) == $queue_cutoff) { + unset($queue[$tok]); + break; + } + } + } + reset($queue); + # set queue_cutoff to the new minimum element. + $queue_cutoff = 0.5; + while(list($tok,$prob) = each($queue)) { + if (abs(0.5-$prob) < $queue_cutoff) { + $queue_cutoff = abs(0.5-$prob); + TWIGDebug("

RESET CUTOFF to $queue_cutoff

",10); + } + } + } + } + + reset($queue); + TWIGDebug("interesting tokens for msg : $path",1); + while(list($tok,$prob) = each($queue)) { + $esc = HTMLSpecialChars($tok); + TWIGDebug("P(spam|$esc) = $prob",1); + } + + $numerator = 1; + reset($queue); + while(list($tok,$prob) = each($queue)) { + $numerator = $numerator*$prob; + TWIGDebug("

NUM : $numerator

",10); + } + + TWIGDebug("

FINAL NUM : $numerator

",10); + + $denom1 = 1; + $denom2 = 1; + reset($queue); + while(list($tok,$prob) = each($queue)) { + $denom1 = $denom1*$prob; + $denom2 = $denom2*(1-$prob); + TWIGDebug("

denom1 : $denom1

",10); + TWIGDebug("

denom2 : $denom2

",10); + } + $denominator = $denom1 + $denom2; + if ($denominator == 0) { + $denominator = 1; + } + + $probability = $numerator/$denominator; + + TWIGDebug("p(spam|msg) = $probability",1); + + if ($probability > .5) { # we think it's spam. + TWIGDebug("

PROBABLY SPAM


",1); + return TRUE; + } + else { + TWIGDebug("

PROBABLY OK
",1); + return FALSE; + } + +} + if( $attachment ) { include("features/mail/mail.attachment.inc.php3"); } if( !$session["mailtree"] ) { $session["mailtree"] = "0|"; } diff -r -u twig-2.7.7/features/mail/mail.main.inc.php3 twig-2.7.7-dev/features/mail/mail.main.inc.php3 --- twig-2.7.7/features/mail/mail.main.inc.php3 2002-12-08 11:04:40.000000000 -0800 +++ twig-2.7.7-dev/features/mail/mail.main.inc.php3 2003-12-20 10:01:54.000000000 -0800 @@ -128,7 +128,7 @@ twigLink( "" . $hilights[3][0] . $TWIGphrase["subject"] . $hilights[3][1] . "", "mail", "main", "", "", $sosubject ), " ", twigLink( "" . $hilights[6][0] . $TWIGphrase["Size"] . $hilights[6][1] . "", "mail", "main", "", "", $sosize ), - " " ); + " "); $itemp = ""; if( GetPref( "newwindow", $dbconfig["prefs_table"], $config["defaults"]["mail"]["newwindow"] ) ) { $nwtemp = "target=\"_blank\""; } else { $nwtemp = ""; } @@ -148,7 +148,16 @@ if( is_object( $headers ) ) { - if( $headers->Unseen == "U" || $headers->Recent == "N" ) { $itemp = TWIGLink( TWIGImage( $img["unread"], $TWIGphrase["unread"] ), "mail", "msgview", "path=" . $sorted[$i-1] ); } + if( $headers->Unseen == "U" || $headers->Recent == "N" ) { + $itemp = TWIGLink( TWIGImage( $img["unread"], $TWIGphrase["unread"] ), "mail", "msgview", "path=" . $sorted[$i-1] ); + if (classify_whether_spam($mbox,$sorted[$i-1]) == TRUE) { + # mark message as deleted but DO NOT EXPUNGE. + user_mark_as_spam($mbox,$sorted[$i-1]); + } + else { + user_mark_as_nonspam($mbox,$sorted[$i-1]); + } + } else { $itemp = TWIGLink( TWIGImage( $img["read"], $TWIGphrase["read"] ), "mail", "unread", "path=" . $sorted[$i-1] ); } if( $showattach ) // Check to see if we're show attachments @@ -176,12 +185,20 @@ if( !$headers->Subject ) { $headers->Subject = $TWIGphrase["[no subject]"]; } - if( $headers->Deleted == "D" ) { $dtemp = TWIGLink( TWIGImage( $img["deleted"], $TWIGphrase["Deleted"] ), "mail", "undelete", "path=" . $sorted[$i-1] ); } - else { $dtemp = TWIGLink( TWIGImage( $img["undeleted"], $TWIGphrase["Not deleted"] ), "mail", "delete", "path=" . $sorted[$i-1] ); } + if( $headers->Deleted == "D" ) { +# if it's spam, use $img["spam"], not regular trash can.. + if (is_marked_as_spam($mbox, $sorted[$i-1]) == TRUE) { + $dtemp = TWIGLink( TWIGImage( $img["spam"], $TWIGphrase["Marked as spam"] ), "mail", "unspam", "path=" . $sorted[$i-1] ); } + else { + $dtemp = TWIGLink( TWIGImage( $img["deleted"], $TWIGphrase["Deleted"] ), "mail", "undelete", "path=" . $sorted[$i-1] ); } + } + else { + $dtemp = TWIGLink( TWIGImage( $img["undeleted"], $TWIGphrase["Not deleted"] ), "mail", "delete", "path=" . $sorted[$i-1] ); + } $tablecontents[$j] = array( array( "contents"=>$itemp, "valign"=>"middle", "align"=>"center" ), - array( "contents"=>$dtemp, "valign"=>"middle", "align"=>"center" ), array( "contents"=>$atemp, "valign"=>"middle", "align"=>"center" ), + array( "contents"=>$dtemp, "valign"=>"middle", "align"=>"center" ), " ", array( "contents"=>TWIGdate($timeformat, $headers->udate ), "nowrap"=>"1" ), " ", @@ -190,7 +207,7 @@ twigLink( HTMLSpecialChars( TWIGDecodeMimeString( $headers->Subject ) ), "mail", "msgview", "path=" . $sorted[$i-1], $nwtemp ), " ", array( "contents"=>TWIGBytesToText( $headers->Size ) . " ", "align"=>"right" ), - array( "contents"=>"", "valign"=>"middle", "align"=>"center" ) + array( "contents"=>"", "valign"=>"middle", "align"=>"center" ), ); } @@ -268,6 +285,8 @@ "> "> "> + "> + "> ">
diff -r -u twig-2.7.7/features/mail/mail.mdn.inc.php3 twig-2.7.7-dev/features/mail/mail.mdn.inc.php3 --- twig-2.7.7/features/mail/mail.mdn.inc.php3 2002-12-07 06:40:52.000000000 -0800 +++ twig-2.7.7-dev/features/mail/mail.mdn.inc.php3 2003-12-13 23:30:51.000000000 -0800 @@ -77,5 +77,10 @@ $ret = TWIGMailSendMessage( $config["smtp_server"], $config["smtp_port"], $form["to"], $fromaddr, $config["fromdomain"], $mailheaders, $bodytext ); } - if( !$InMsgView ) { include( "features/mail/mail.msgview.inc.php3" ); } + if( !$InMsgView ) { + include( "features/mail/mail.msgview.inc.php3" ); + } + + + ?> diff -r -u twig-2.7.7/features/mail/mail.undelete.inc.php3 twig-2.7.7-dev/features/mail/mail.undelete.inc.php3 --- twig-2.7.7/features/mail/mail.undelete.inc.php3 2000-03-30 20:28:04.000000000 -0800 +++ twig-2.7.7-dev/features/mail/mail.undelete.inc.php3 2003-12-17 00:03:39.000000000 -0800 @@ -1,12 +1,15 @@