? xaa
Index: kmheaders.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmheaders.cpp,v
retrieving revision 1.489
diff -u -r1.489 kmheaders.cpp
--- kmheaders.cpp	12 Apr 2003 15:29:53 -0000	1.489
+++ kmheaders.cpp	14 Apr 2003 18:04:44 -0000
@@ -2263,6 +2263,7 @@
   menu->insertSeparator();
   mOwner->trashAction->plug(menu);
   mOwner->deleteAction->plug(menu);
+  mOwner->junkAction->plug(menu);
 
   menu->insertSeparator();
   mOwner->saveAsAction->plug(menu);
Index: kmmainwidget.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmmainwidget.cpp,v
retrieving revision 1.44
diff -u -r1.44 kmmainwidget.cpp
--- kmmainwidget.cpp	13 Apr 2003 20:12:43 -0000	1.44
+++ kmmainwidget.cpp	14 Apr 2003 18:04:50 -0000
@@ -37,6 +37,7 @@
 #include <ktip.h>
 #include <kdeversion.h>
 #include <knotifydialog.h>
+#include <kprocio.h>
 
 #include "kmbroadcaststatus.h"
 #include "kmfoldermgr.h"
@@ -1249,6 +1250,74 @@
 }
 
 //-----------------------------------------------------------------------------
+void KMMainWidget::slotJunkMsg()
+{
+  int ret;
+
+  KProcIO *io = new KProcIO();
+  *io << "bogofilter";
+  connect(io, SIGNAL(processExited(KProcess*)), SLOT(slotJunkClassified(KProcess*)));
+  ret = io->start(); // shouldn't block too long, but we need to send input
+  if(ret)
+  {
+    io->writeStdin( mHeaders->currentMsg()->asString() ); // asDwString?
+    io->closeStdin();
+  }
+  else
+  {
+    delete io;
+    KMessageBox::sorry(this, i18n("The spam tool 'bogofilter' could not be started."), i18n("Spam classification error"));
+  }
+}
+
+void KMMainWidget::slotJunkClassified(KProcess *proc)
+{
+  int isjunk = 0;
+  int ret;
+  KProcIO *io;
+
+  if(proc->normalExit())
+  {
+    if(!proc->exitStatus())
+    {
+      ret = KMessageBox::questionYesNo(this, i18n("This mail seems to be spam. Is this true?"), i18n("Spam classification"));
+      if(ret == KMessageBox::Yes) isjunk = 1;
+      else
+      {
+        io = new KProcIO();
+        *io << "bogofilter" << "-n";
+        io->start(KProcess::DontCare);
+        io->start();
+        io->writeStdin( mHeaders->currentMsg()->asString() );
+        io->closeStdin();
+      }
+    }
+    else
+    {
+      ret = KMessageBox::questionYesNo(this, i18n("This mail seems to be a normal message. Is this true?"), i18n("Spam classification"));
+      if(ret == KMessageBox::No) isjunk = 1;
+      else
+      {
+        io = new KProcIO();
+        *io << "bogofilter" << "-u";
+        io->start(KProcess::DontCare);
+        io->start();
+        io->writeStdin( mHeaders->currentMsg()->asString() );
+        io->closeStdin();
+      }
+    }
+  }
+
+  delete proc;
+
+  if(isjunk)
+  {
+    mHeaders->deleteMsg();
+    updateMessageActions();
+  }
+}
+
+//-----------------------------------------------------------------------------
 void KMMainWidget::slotDeleteMsg()
 {
   mHeaders->moveMsgToFolder(0);
@@ -1844,6 +1913,7 @@
      saveAsAction->plug(menu);
      menu->insertSeparator();
      trashAction->plug(menu);
+     junkAction->plug(menu);
      deleteAction->plug(menu);
   }
   menu->exec(aPoint, 0);
@@ -1963,6 +2033,11 @@
                              "D;Delete", this, SLOT(slotTrashMsg()),
                              actionCollection(), "move_to_trash" );
 
+  junkAction = new KAction( KGuiItem( i18n("&Toggle junk status"), "editjunk",
+                                      i18n("Classify this mail as spam or normal message") ),
+                             "T;Toggle", this, SLOT(slotJunkMsg()),
+                             actionCollection(), "junk_mail" );
+
   deleteAction = new KAction( i18n("&Delete"), "editdelete", SHIFT+Key_Delete, this,
                               SLOT(slotDeleteMsg()), actionCollection(), "delete" );
 
@@ -2586,6 +2661,7 @@
     forwardMenu()->setEnabled( mass_actions );
 
     bool single_actions = count == 1;
+    junkAction->setEnabled ( single_actions );
     filterMenu()->setEnabled( single_actions );
     editAction->setEnabled( single_actions &&
       kernel->folderIsDraftOrOutbox(mFolder));
Index: kmmainwidget.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmmainwidget.h,v
retrieving revision 1.17
diff -u -r1.17 kmmainwidget.h
--- kmmainwidget.h	12 Apr 2003 15:29:53 -0000	1.17
+++ kmmainwidget.h	14 Apr 2003 18:04:51 -0000
@@ -33,6 +33,7 @@
 class KSelectAction;
 class KRadioAction;
 class KProgressDialog;
+class KProcess;
 class KMLittleProgressDlg;
 template <typename T> class QValueList;
 template <typename T, typename S> class QMap;
@@ -102,7 +103,7 @@
   KAction *printAction() { return mMsgView->printAction(); }
 
   //FIXME: wtf? member variables in the public interface:
-  KAction *trashAction, *deleteAction, *saveAsAction, *editAction,
+  KAction *trashAction, *deleteAction, *junkAction, *saveAsAction, *editAction,
     *sendAgainAction, *mForwardAction, *mForwardAttachedAction,
     *applyFiltersAction, *findInMessageAction;
   KActionMenu *statusMenu, *threadStatusMenu,
@@ -121,6 +122,8 @@
 public slots:
   void slotMoveMsgToFolder( KMFolder *dest);
   void slotTrashMsg();   // move to trash
+  void slotJunkMsg(); // classify as spam
+  void slotJunkClassified(KProcess *proc); // classification ready
 
   virtual void show();
   virtual void hide();
Index: kmmainwin.rc
===================================================================
RCS file: /home/kde/kdepim/kmail/kmmainwin.rc,v
retrieving revision 1.55
diff -u -r1.55 kmmainwin.rc
--- kmmainwin.rc	13 Apr 2003 20:12:43 -0000	1.55
+++ kmmainwin.rc	14 Apr 2003 18:04:51 -0000
@@ -26,6 +26,7 @@
    <Separator/>
    <Action name="move_to_trash" />
    <Action name="delete" />
+   <Action name="junk_mail" />
    <Separator/>
    <Action name="find_in_messages" />
    <Separator/>
@@ -139,6 +140,7 @@
   <Separator/>
   <Action name="move_to_trash" />
   <Action name="delete" />
+  <Action name="junk_mail" />
   <Separator/>
   <Action name="search_messages" />
   <Action name="addressbook" />
