[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    [PATCH] Copy Filter Action - review please
From:       Andreas Gungl <a.gungl () gmx ! de>
Date:       2004-11-28 20:17:26
Message-ID: 200411282117.27520 () gungl-dd ! de
[Download RAW message or body]

Hi,

The attached patch introduces a Copy filter action. I've tested with 
incoming messages as well as when applying manually. Can you please have a 
look at it and tell me if you find some critical code?

TIA,
Andreas

["kmailCopyFilterAction.diff" (text/x-diff)]

Index: kmfilteraction.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfilteraction.cpp,v
retrieving revision 1.128
diff -u -3 -p -r1.128 kmfilteraction.cpp
--- kmfilteraction.cpp	25 Oct 2004 20:15:21 -0000	1.128
+++ kmfilteraction.cpp	28 Nov 2004 20:09:00 -0000
@@ -1275,6 +1275,55 @@ bool KMFilterActionMove::requiresBody(KM
     return false; //iff mFolder->folderMgr == msgBase->parent()->folderMgr;
 }
 
+
+//=============================================================================
+// KMFilterActionCopy - copy into folder
+// Copy message into another mail folder
+//=============================================================================
+class KMFilterActionCopy: public KMFilterActionWithFolder
+{
+public:
+  KMFilterActionCopy();
+  virtual ReturnCode process(KMMessage* msg) const;
+  virtual bool requiresBody(KMMsgBase*) const;
+  static KMFilterAction* newAction(void);
+};
+
+KMFilterAction* KMFilterActionCopy::newAction(void)
+{
+  return (new KMFilterActionCopy);
+}
+
+KMFilterActionCopy::KMFilterActionCopy()
+  : KMFilterActionWithFolder( "copy", i18n("Copy into Folder") )
+{
+}
+
+KMFilterAction::ReturnCode KMFilterActionCopy::process(KMMessage* msg) const
+{
+  if ( !mFolder )
+    return ErrorButGoOn;
+
+  // copy the message 1:1
+  KMMessage* msgCopy = new KMMessage;
+  msgCopy->fromDwString(msg->asDwString());
+  
+  mFolder->open();
+  int index;
+  int rc = mFolder->addMsg(msgCopy, &index);
+  if (rc == 0 && index != -1)
+    mFolder->unGetMsg( mFolder->count() - 1 );
+  mFolder->close();
+  
+  return GoOn;
+}
+
+bool KMFilterActionCopy::requiresBody(KMMsgBase*) const
+{
+    return true;
+}
+
+
 //=============================================================================
 // KMFilterActionForward - forward to
 // Forward message to another user
@@ -1713,12 +1762,13 @@ void KMFilterActionDict::init(void)
   insert( KMFilterActionAddHeader::newAction );
   insert( KMFilterActionRewriteHeader::newAction );
   insert( KMFilterActionExecSound::newAction );
+  insert( KMFilterActionCopy::newAction );
   // Register custom filter actions below this line.
 }
-// The int in the QDict constructor (23) must be a prime
+// The int in the QDict constructor (41) must be a prime
 // and should be greater than the double number of KMFilterAction types
 KMFilterActionDict::KMFilterActionDict()
-  : QDict<KMFilterActionDesc>(23)
+  : QDict<KMFilterActionDesc>(41)
 {
   mList.setAutoDelete(TRUE);
   init();


_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic