Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9867/src/gui

Modified Files:
        wxMsgCmdProc.cpp 
Log Message:
implemented Message|Spam submenu commands

Index: wxMsgCmdProc.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxMsgCmdProc.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -b -u -2 -r1.56 -r1.57
--- wxMsgCmdProc.cpp    29 Jun 2004 23:56:10 -0000      1.56
+++ wxMsgCmdProc.cpp    8 Jul 2004 15:23:12 -0000       1.57
@@ -56,4 +56,6 @@
 #include "MsgCmdProc.h"
 
+#include "SpamFilter.h"
+
 #include "gui/wxDialogLayout.h"
 
@@ -84,4 +86,5 @@
 extern const MPersMsgBox *M_MSGBOX_CONFIRM_RESEND;
 extern const MPersMsgBox *M_MSGBOX_CONFIRM_ZAP;
+extern const MPersMsgBox *M_MSGBOX_ZAP_SPAM;
 
 // ----------------------------------------------------------------------------
@@ -200,4 +203,10 @@
 #endif // EXPERIMENTAL_show_uid
 
+   /// Reclassify the message as [non] spam
+   void ReclassifyAsSpam(const UIdArray& uids, bool isSpam);
+
+   /// Check whether the message is spam
+   void CheckIfSpam(const UIdArray& uids);
+
    //@}
 
@@ -879,4 +888,13 @@
          break;
 
+      case WXMENU_MSG_SPAM_MARK:
+      case WXMENU_MSG_SPAM_UNMARK:
+         ReclassifyAsSpam(messages, cmd == WXMENU_MSG_SPAM_MARK);
+         break;
+
+      case WXMENU_MSG_SPAM_CHECK:
+         CheckIfSpam(messages);
+         break;
+
       default:
          // try passing it to message view
@@ -918,9 +936,8 @@
    String text;
 
-   Message *msg = GetMessage(uid);
+   Message_obj msg(GetMessage(uid));
    if ( msg )
    {
       msg->WriteToString(text, true);
-      msg->DecRef();
    }
 
@@ -966,4 +983,84 @@
 }
 
+void MsgCmdProcImpl::ReclassifyAsSpam(const UIdArray& uids, bool isSpam)
+{
+   wxString msg = isSpam ? _("Reclassifiying as spam...")
+                         : _("Reclassifiying as ham...");
+   wxLogStatus(GetFrame(), msg);
+
+   // first mark the messages as spam/ham
+   const size_t count = uids.Count();
+   for ( size_t i = 0; i < count; i++ )
+   {
+      Message_obj msg(GetMessage(uids[i]));
+      if ( !msg )
+      {
+         wxLogError(_("Failed to retrieve the message %#08x to reclassify."),
+                    uids[i]);
+         continue;
+      }
+
+      SpamFilter::ReclassifyAsSpam(*msg, isSpam);
+   }
+
+   wxLogStatus(GetFrame(), msg + _("done"));
+
+   // second, permanently delete all the spam
+   if ( isSpam && MDialog_YesNoDialog
+        (
+            String::Format
+            (
+               _("Do you want to permanently delete the %lu messages "
+                 "marked as spam now?"),
+               (unsigned long)count
+            ),
+            GetFrame(),
+            MDIALOG_YESNOTITLE,
+            M_DLG_NO_DEFAULT,
+            M_MSGBOX_ZAP_SPAM
+        ) )
+   {
+      // TODO: make this action configurable (i.e. could be moved to another
+      //       folder and it should also be possible to define an action for
+      //       ham messages, e.g. move them back to inbox)
+      DeleteAndExpungeMessages(uids);
+   }
+}
+
+void MsgCmdProcImpl::CheckIfSpam(const UIdArray& uids)
+{
+   wxString status(_("Checking message using spam filters..."));
+   wxLogStatus(GetFrame(), status);
+
+   const size_t n = uids.Count();
+   for ( size_t i = 0; i < n; i++ )
+   {
+      Message_obj msg(GetMessage(uids[i]));
+      if ( !msg )
+      {
+         wxLogError(_("Failed to retrieve the message to check in spam filter."));
+         continue;
+      }
+
+      float prob = 1.;
+      String str(_("The message with subject \"%s\" from \"%s\"\n"));
+      if ( SpamFilter::CheckIfSpam(*msg, &prob) )
+      {
+         wxLogWarning(str + _("seems to be a spam (probability: %0.3f)"),
+                      msg->Subject().c_str(),
+                      msg->From().c_str(),
+                      prob);
+      }
+      else // !spam
+      {
+         wxLogMessage(str + _("doesn't seem to be a spam"),
+                      msg->Subject().c_str(),
+                      msg->From().c_str());
+      }
+   }
+
+   wxLogStatus(GetFrame(), status + _("done"));
+}
+
 void
 MsgCmdProcImpl::OpenMessages(const UIdArray& selections)



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to