~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to mailcommon/filteraction.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include "filteractionwidget.h"
3
3
#include "filteraction.h"
4
4
 
5
 
#include "filtermanager.h"
6
5
#include "folderrequester.h"
 
6
#include "filteractionmissingcollectiondialog.h"
7
7
#include "mailutil.h"
8
8
#include "mailkernel.h"
9
9
#include "mdnadvicedialog.h"
10
 
#include "messageproperty.h"
11
10
#include "minimumcombobox.h"
12
11
#include "regexplineedit.h"
13
12
 
55
54
#include <assert.h>
56
55
#include <string.h>
57
56
 
58
 
using MailCommon::MessageProperty;
59
57
using MailCommon::RegExpLineEdit;
60
58
using MessageComposer::MessageFactory;
61
59
 
62
60
using namespace MailCommon;
63
61
 
 
62
ItemContext::ItemContext( const Akonadi::Item &item )
 
63
  : mItem( item ), mNeedsPayloadStore( false ), mNeedsFlagStore( false )
 
64
{
 
65
}
 
66
 
 
67
Akonadi::Item& ItemContext::item()
 
68
{
 
69
  return mItem;
 
70
}
 
71
 
 
72
void ItemContext::setMoveTargetCollection( const Akonadi::Collection &collection )
 
73
{
 
74
  mMoveTargetCollection = collection;
 
75
}
 
76
 
 
77
Akonadi::Collection ItemContext::moveTargetCollection() const
 
78
{
 
79
  return mMoveTargetCollection;
 
80
}
 
81
 
 
82
void ItemContext::setNeedsPayloadStore()
 
83
{
 
84
  mNeedsPayloadStore = true;
 
85
}
 
86
 
 
87
bool ItemContext::needsPayloadStore() const
 
88
{
 
89
  return mNeedsPayloadStore;
 
90
}
 
91
 
 
92
void ItemContext::setNeedsFlagStore()
 
93
{
 
94
  mNeedsFlagStore = true;
 
95
}
 
96
 
 
97
bool ItemContext::needsFlagStore() const
 
98
{
 
99
  return mNeedsFlagStore;
 
100
}
 
101
 
 
102
 
64
103
FilterAction::FilterAction( const char *name, const QString &label, QObject *parent )
65
104
  : QObject( parent ), mName( name ), mLabel( label )
66
105
{
100
139
  return new QWidget( parent );
101
140
}
102
141
 
103
 
void FilterAction::applyParamWidgetValue( QWidget* )
104
 
{
105
 
}
106
 
 
107
 
void FilterAction::setParamWidgetValue( QWidget* ) const
108
 
{
109
 
}
110
 
 
111
 
void FilterAction::clearParamWidget( QWidget* ) const
112
 
{
 
142
void FilterAction::applyParamWidgetValue( QWidget * )
 
143
{
 
144
}
 
145
 
 
146
void FilterAction::setParamWidgetValue( QWidget * ) const
 
147
{
 
148
}
 
149
 
 
150
void FilterAction::clearParamWidget( QWidget * ) const
 
151
{
 
152
}
 
153
 
 
154
void FilterAction::argsFromStringInteractive( const QString &argsStr, const QString & filterName )
 
155
{
 
156
  Q_UNUSED( filterName );
 
157
  argsFromString(argsStr);
 
158
}
 
159
 
 
160
QString FilterAction::argsAsStringReal() const
 
161
{
 
162
  return argsAsString();
113
163
}
114
164
 
115
165
bool FilterAction::folderRemoved( const Akonadi::Collection&, const Akonadi::Collection& )
218
268
  lineEdit->setClearButtonShown( true );
219
269
  lineEdit->setText( mParameter );
220
270
 
221
 
  connect( lineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( filterActionModified() ) );
 
271
  connect( lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(filterActionModified()) );
222
272
 
223
273
  return lineEdit;
224
274
}
271
321
  comboBox->addItems( mParameterList );
272
322
  setParamWidgetValue( comboBox );
273
323
 
274
 
  connect( comboBox, SIGNAL( currentIndexChanged( int ) ),
275
 
           this, SIGNAL( filterActionModified() ) );
 
324
  connect( comboBox, SIGNAL(currentIndexChanged(int)),
 
325
           this, SIGNAL(filterActionModified()) );
276
326
 
277
327
  return comboBox;
278
328
}
318
368
 
319
369
bool FilterActionWithFolder::isEmpty() const
320
370
{
321
 
  return (!mFolder.isValid() && mFolderName.isEmpty());
 
371
  return !mFolder.isValid();
322
372
}
323
373
 
324
374
QWidget* FilterActionWithFolder::createParamWidget( QWidget *parent ) const
327
377
  requester->setShowOutbox( false );
328
378
  setParamWidgetValue( requester );
329
379
 
330
 
  connect( requester, SIGNAL( folderChanged( Akonadi::Collection )),
331
 
           this, SIGNAL( filterActionModified()) );
 
380
  connect( requester, SIGNAL(folderChanged(Akonadi::Collection)),
 
381
           this, SIGNAL(filterActionModified()) );
332
382
 
333
383
  return requester;
334
384
}
335
385
 
336
386
void FilterActionWithFolder::applyParamWidgetValue( QWidget *paramWidget )
337
387
{
338
 
  mFolder = static_cast<FolderRequester*>( paramWidget )->folderCollection();
339
 
  mFolderName = static_cast<FolderRequester*>( paramWidget )->folderId();
 
388
  mFolder = static_cast<FolderRequester*>( paramWidget )->collection();
340
389
}
341
390
 
342
391
void FilterActionWithFolder::setParamWidgetValue( QWidget *paramWidget ) const
343
392
{
344
 
  if ( mFolder.isValid() )
345
 
    static_cast<FolderRequester*>( paramWidget )->setFolder( mFolder );
346
 
  else
347
 
    static_cast<FolderRequester*>( paramWidget )->setFolder( mFolderName );
 
393
  static_cast<FolderRequester*>( paramWidget )->setCollection( mFolder );
348
394
}
349
395
 
350
396
void FilterActionWithFolder::clearParamWidget( QWidget *paramWidget ) const
351
397
{
352
 
  static_cast<FolderRequester*>( paramWidget )->setFolder( CommonKernel->draftsCollectionFolder() );
 
398
  static_cast<FolderRequester*>( paramWidget )->setCollection( CommonKernel->draftsCollectionFolder() );
 
399
}
 
400
 
 
401
void FilterActionWithFolder::argsFromStringInteractive( const QString &argsStr , const QString& name)
 
402
{
 
403
  argsFromString( argsStr );
 
404
  if ( !mFolder.isValid() ) {
 
405
    bool exactPath = false;
 
406
    Akonadi::Collection::List lst = FilterActionMissingCollectionDialog::potentialCorrectFolders( argsStr, exactPath );
 
407
    if ( lst.count() == 1 && exactPath )
 
408
      mFolder = lst.at( 0 );
 
409
    else {
 
410
      FilterActionMissingCollectionDialog *dlg = new FilterActionMissingCollectionDialog( lst, name );
 
411
      if ( dlg->exec() )
 
412
        mFolder = dlg->selectedCollection();
 
413
      delete dlg;
 
414
    }
 
415
  }
 
416
}
 
417
 
 
418
QString FilterActionWithFolder::argsAsStringReal() const
 
419
{
 
420
  if ( KernelIf->collectionModel() )
 
421
    return MailCommon::Util::fullCollectionPath( mFolder );
 
422
  return FilterActionWithFolder::argsAsString();
353
423
}
354
424
 
355
425
void FilterActionWithFolder::argsFromString( const QString &argsStr )
358
428
  const Akonadi::Collection::Id id = argsStr.toLongLong( &ok );
359
429
  if ( ok ) {
360
430
    mFolder = Akonadi::Collection( id );
361
 
    mFolderName= QString::number( mFolder.id() );
362
431
  } else {
363
 
    mFolderName = argsStr;
 
432
    mFolder = Akonadi::Collection();
364
433
  }
365
434
}
366
435
 
369
438
  QString result;
370
439
  if ( mFolder.isValid() )
371
440
    result = QString::number( mFolder.id() );
372
 
  else
373
 
    result = mFolderName;
374
441
 
375
442
  return result;
376
443
}
379
446
{
380
447
  QString result;
381
448
  if ( mFolder.isValid() )
382
 
    result = mFolder.url().path();
383
 
  else
384
 
    result = mFolderName;
 
449
    result = QString::number( mFolder.id() );
385
450
 
386
451
  return label() + QLatin1String( " \"" ) + Qt::escape( result ) + QLatin1String( "\"" );
387
452
}
390
455
{
391
456
  if ( oldFolder == mFolder ) {
392
457
    mFolder = newFolder;
393
 
    if ( newFolder.isValid() )
394
 
      mFolderName = mFolder.id();
395
458
    return true;
396
459
  } else
397
460
    return false;
413
476
  MessageCore::EmailAddressRequester *requester = new MessageCore::EmailAddressRequester( parent );
414
477
  requester->setText( mParameter );
415
478
 
416
 
  connect( requester, SIGNAL( textChanged() ), this, SIGNAL( filterActionModified() ) );
 
479
  connect( requester, SIGNAL(textChanged()), this, SIGNAL(filterActionModified()) );
417
480
 
418
481
  return requester;
419
482
}
502
565
  // and use QString::arg to substitute filenames for the %n's.
503
566
  int lastSeen = -2;
504
567
  QString tempFileName;
505
 
  for ( QList<int>::Iterator it = argList.begin() ; it != argList.end() ; ++it ) {
 
568
  QList<int>::ConstIterator end( argList.constEnd() );
 
569
  for ( QList<int>::ConstIterator it = argList.constBegin() ; it != end ; ++it ) {
506
570
    // setup temp files with check for duplicate %n's
507
571
    if ( (*it) != lastSeen ) {
508
572
      KTemporaryFile *tempFile = new KTemporaryFile();
580
644
 
581
645
}
582
646
 
583
 
FilterAction::ReturnCode FilterActionWithCommand::genericProcess( const Akonadi::Item &item, bool withOutput ) const
 
647
FilterAction::ReturnCode FilterActionWithCommand::genericProcess( ItemContext &context, bool withOutput ) const
584
648
{
585
 
  const KMime::Message::Ptr aMsg = item.payload<KMime::Message::Ptr>();
 
649
  const KMime::Message::Ptr aMsg = context.item().payload<KMime::Message::Ptr>();
586
650
  Q_ASSERT( aMsg );
587
651
 
588
652
  if ( mParameter.isEmpty() )
600
664
  atmList.append( inFile );
601
665
 
602
666
  QString commandLine = substituteCommandLineArgsFor( aMsg, atmList );
603
 
  substituteCommandLineArgsForItem( item, commandLine );
 
667
  substituteCommandLineArgsForItem( context.item(), commandLine );
604
668
  substituteMessageHeaders( aMsg, commandLine );
605
669
 
606
670
  if ( commandLine.isEmpty() ) {
655
719
      KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-UID", aMsg.get(), uid, "utf-8" );
656
720
      aMsg->setHeader( header );
657
721
 
658
 
      new Akonadi::ItemModifyJob( item, FilterIf->filterManager() ); //TODO: check for errors
 
722
      context.setNeedsPayloadStore();
659
723
    } else {
660
724
      qDeleteAll( atmList );
661
725
      atmList.clear();
684
748
{
685
749
  public:
686
750
    FilterActionSendReceipt( QObject *parent = 0 );
687
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
751
    virtual ReturnCode process( ItemContext &context ) const;
688
752
    static FilterAction* newAction();
689
753
};
690
754
 
698
762
{
699
763
}
700
764
 
701
 
FilterAction::ReturnCode FilterActionSendReceipt::process( const Akonadi::Item &item ) const
 
765
FilterAction::ReturnCode FilterActionSendReceipt::process( ItemContext &context ) const
702
766
{
703
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
767
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
704
768
 
705
 
  MessageFactory factory( msg, item.id() );
706
 
  factory.setFolderIdentity( Util::folderIdentity( item ) );
 
769
  MessageFactory factory( msg, context.item().id() );
 
770
  factory.setFolderIdentity( Util::folderIdentity( context.item() ) );
707
771
  factory.setIdentityManager( KernelIf->identityManager() );
708
772
 
709
773
  const KMime::Message::Ptr receipt = factory.createDeliveryReceipt();
727
791
{
728
792
  public:
729
793
    FilterActionTransport( QObject *parent = 0 );
730
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
794
    virtual ReturnCode process( ItemContext &context ) const;
731
795
    static FilterAction* newAction();
732
796
};
733
797
 
741
805
{
742
806
}
743
807
 
744
 
FilterAction::ReturnCode FilterActionTransport::process( const Akonadi::Item &item ) const
 
808
FilterAction::ReturnCode FilterActionTransport::process( ItemContext &context ) const
745
809
{
746
810
  if ( mParameter.isEmpty() )
747
811
    return ErrorButGoOn;
748
812
 
749
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
813
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
750
814
  KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-KMail-Transport", msg.get(), mParameter, "utf-8" );
751
815
  msg->setHeader( header );
752
816
  msg->assemble();
753
817
 
754
 
  new Akonadi::ItemModifyJob( item, FilterIf->filterManager() );
 
818
  context.setNeedsPayloadStore();
755
819
 
756
820
  return GoOn;
757
821
}
765
829
{
766
830
  public:
767
831
    FilterActionReplyTo( QObject *parent = 0 );
768
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
832
    virtual ReturnCode process( ItemContext &context ) const;
769
833
    static FilterAction* newAction();
770
834
};
771
835
 
777
841
FilterActionReplyTo::FilterActionReplyTo( QObject *parent )
778
842
  : FilterActionWithString( "set Reply-To", i18n( "Set Reply-To To" ), parent )
779
843
{
780
 
  mParameter = "";
 
844
  mParameter.clear();
781
845
}
782
846
 
783
 
FilterAction::ReturnCode FilterActionReplyTo::process( const Akonadi::Item &item ) const
 
847
FilterAction::ReturnCode FilterActionReplyTo::process( ItemContext &context ) const
784
848
{
785
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
849
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
786
850
  KMime::Headers::Generic *header = new KMime::Headers::Generic( "Reply-To", msg.get(), mParameter, "utf-8" );
787
851
  msg->setHeader( header );
788
852
  msg->assemble();
789
853
 
790
 
  new Akonadi::ItemModifyJob( item, FilterIf->filterManager() );
 
854
  context.setNeedsPayloadStore();
791
855
 
792
856
  return GoOn;
793
857
}
801
865
{
802
866
  public:
803
867
    FilterActionIdentity( QObject *parent = 0 );
804
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
868
    virtual ReturnCode process( ItemContext &context ) const;
805
869
    static FilterAction* newAction();
806
870
 
807
871
    QWidget * createParamWidget( QWidget *parent ) const;
821
885
  mParameter = KernelIf->identityManager()->defaultIdentity().uoid();
822
886
}
823
887
 
824
 
FilterAction::ReturnCode FilterActionIdentity::process( const Akonadi::Item &item ) const
 
888
FilterAction::ReturnCode FilterActionIdentity::process( ItemContext &context ) const
825
889
{
826
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
890
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
827
891
  KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-KMail-Identity", msg.get(), QString::number( mParameter ), "utf-8" );
828
892
  msg->setHeader( header );
829
893
  msg->assemble();
830
894
 
831
 
  new Akonadi::ItemModifyJob( item, FilterIf->filterManager() );
 
895
  context.setNeedsPayloadStore();
832
896
 
833
897
  return GoOn;
834
898
}
838
902
  KPIMIdentities::IdentityCombo *comboBox = new KPIMIdentities::IdentityCombo( KernelIf->identityManager(), parent );
839
903
  comboBox->setCurrentIdentity( mParameter );
840
904
 
841
 
  connect( comboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( filterActionModified() ) );
 
905
  connect( comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filterActionModified()) );
842
906
 
843
907
  return comboBox;
844
908
}
876
940
{
877
941
  public:
878
942
    FilterActionSetStatus( QObject *parent = 0 );
879
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
943
    virtual ReturnCode process( ItemContext &context ) const;
880
944
    virtual bool requiresBody() const;
881
945
 
882
946
    static FilterAction* newAction();
929
993
  mParameter = mParameterList.at( 0 );
930
994
}
931
995
 
932
 
FilterAction::ReturnCode FilterActionSetStatus::process( const Akonadi::Item &item ) const
 
996
FilterAction::ReturnCode FilterActionSetStatus::process( ItemContext &context ) const
933
997
{
934
998
  const int index = mParameterList.indexOf( mParameter );
935
999
  if ( index < 1 )
936
1000
    return ErrorButGoOn;
937
1001
 
938
1002
  Akonadi::MessageStatus status;
939
 
  status.setStatusFromFlags( item.flags() );
 
1003
  status.setStatusFromFlags( context.item().flags() );
940
1004
 
941
1005
  const Akonadi::MessageStatus newStatus = stati[ index - 1 ];
942
1006
  if ( newStatus == Akonadi::MessageStatus::statusUnread() )
944
1008
  else
945
1009
    status.set( newStatus );
946
1010
 
947
 
  Akonadi::Item newItem( item.id() );
948
 
  newItem.setRevision( item.revision() );
949
 
  newItem.setFlags( status.statusFlags() );
950
 
  new Akonadi::ItemModifyJob( newItem, FilterIf->filterManager() ); // TODO handle error
 
1011
  context.item().setFlags( status.statusFlags() );
 
1012
  context.setNeedsFlagStore();
951
1013
 
952
1014
  return GoOn;
953
1015
}
1007
1069
{
1008
1070
  public:
1009
1071
    FilterActionAddTag( QObject *parent = 0 );
1010
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1072
    virtual ReturnCode process( ItemContext &context ) const;
1011
1073
    virtual bool requiresBody() const;
1012
1074
 
1013
1075
    static FilterAction* newAction();
1038
1100
#endif
1039
1101
}
1040
1102
 
1041
 
FilterAction::ReturnCode FilterActionAddTag::process( const Akonadi::Item &item ) const
 
1103
FilterAction::ReturnCode FilterActionAddTag::process( ItemContext &context ) const
1042
1104
{
1043
1105
#ifndef KDEPIM_NO_NEPOMUK
1044
1106
  const int index = mParameterList.indexOf( mParameter );
1045
1107
  if ( index == -1 )
1046
1108
    return ErrorButGoOn;
1047
1109
 
1048
 
  Nepomuk::Resource resource( item.url() );
 
1110
  Nepomuk::Resource resource( context.item().url() );
1049
1111
  resource.addTag( mParameter );
1050
1112
#endif
1051
1113
 
1066
1128
    }
1067
1129
  }
1068
1130
 
1069
 
  if ( mParameterList.size() > 0 )
 
1131
  if ( !mParameterList.isEmpty() )
1070
1132
    mParameter = mParameterList.at( 0 );
1071
1133
}
1072
1134
 
1093
1155
{
1094
1156
  public:
1095
1157
    FilterActionFakeDisposition( QObject *parent = 0 );
1096
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1158
    virtual ReturnCode process( ItemContext &context ) const;
1097
1159
    static FilterAction* newAction()
1098
1160
    {
1099
1161
      return new FilterActionFakeDisposition;
1138
1200
  mParameter = mParameterList.at( 0 );
1139
1201
}
1140
1202
 
1141
 
FilterAction::ReturnCode FilterActionFakeDisposition::process( const Akonadi::Item &item ) const
 
1203
FilterAction::ReturnCode FilterActionFakeDisposition::process( ItemContext &context ) const
1142
1204
{
1143
1205
  const int index = mParameterList.indexOf( mParameter );
1144
1206
  if ( index < 1 )
1145
1207
    return ErrorButGoOn;
1146
1208
 
1147
1209
  if ( index == 1 ) { // ignore
1148
 
    if ( item.hasAttribute<MessageCore::MDNStateAttribute>() ) {
1149
 
      item.attribute<MessageCore::MDNStateAttribute>()->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
1150
 
      Akonadi::ItemModifyJob* modifyJob = new Akonadi::ItemModifyJob( item );
1151
 
      modifyJob->setIgnorePayload( true );
 
1210
    if ( context.item().hasAttribute<MessageCore::MDNStateAttribute>() ) {
 
1211
      context.item().attribute<MessageCore::MDNStateAttribute>()->setMDNState( MessageCore::MDNStateAttribute::MDNIgnore );
 
1212
      context.setNeedsFlagStore();
1152
1213
    }
1153
1214
  } else // send
1154
 
    sendMDN( item, mdns[ index - 2 ] ); // skip first two entries: "" and "ignore"
 
1215
    sendMDN( context.item(), mdns[ index - 2 ] ); // skip first two entries: "" and "ignore"
1155
1216
 
1156
1217
  return GoOn;
1157
1218
}
1198
1259
{
1199
1260
  public:
1200
1261
    FilterActionRemoveHeader( QObject *parent = 0 );
1201
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1262
    virtual ReturnCode process( ItemContext &context ) const;
1202
1263
    virtual QWidget* createParamWidget( QWidget *parent ) const;
1203
1264
    virtual void setParamWidgetValue( QWidget *paramWidget ) const;
1204
1265
 
1230
1291
  comboBox->setInsertPolicy( QComboBox::InsertAtBottom );
1231
1292
  setParamWidgetValue( comboBox );
1232
1293
 
1233
 
  connect( comboBox, SIGNAL( currentIndexChanged( int ) ),
1234
 
           this, SIGNAL( filterActionModified() ) );
 
1294
  connect( comboBox, SIGNAL(currentIndexChanged(int)),
 
1295
           this, SIGNAL(filterActionModified()) );
1235
1296
 
1236
1297
  return comboBox;
1237
1298
}
1238
1299
 
1239
 
FilterAction::ReturnCode FilterActionRemoveHeader::process( const Akonadi::Item &item ) const
 
1300
FilterAction::ReturnCode FilterActionRemoveHeader::process( ItemContext &context ) const
1240
1301
{
1241
1302
  if ( mParameter.isEmpty() )
1242
1303
    return ErrorButGoOn;
1243
1304
 
1244
 
  KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
1305
  KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
1245
1306
  while ( msg->headerByType( mParameter.toLatin1() ) )
1246
1307
    msg->removeHeader( mParameter.toLatin1() );
1247
1308
 
1248
1309
  msg->assemble();
1249
1310
 
1250
 
  new Akonadi::ItemModifyJob( item, FilterIf->filterManager() );
 
1311
  context.setNeedsPayloadStore();
1251
1312
 
1252
1313
  return GoOn;
1253
1314
}
1277
1338
{
1278
1339
  public:
1279
1340
    FilterActionAddHeader( QObject *parent = 0 );
1280
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1341
    virtual ReturnCode process( ItemContext &context ) const;
1281
1342
    virtual QWidget* createParamWidget( QWidget *parent ) const;
1282
1343
    virtual void setParamWidgetValue( QWidget *paramWidget ) const;
1283
1344
    virtual void applyParamWidgetValue( QWidget *paramWidget );
1310
1371
  mParameter = mParameterList.at( 0 );
1311
1372
}
1312
1373
 
1313
 
FilterAction::ReturnCode FilterActionAddHeader::process( const Akonadi::Item &item ) const
 
1374
FilterAction::ReturnCode FilterActionAddHeader::process( ItemContext &context ) const
1314
1375
{
1315
1376
  if ( mParameter.isEmpty() )
1316
1377
    return ErrorButGoOn;
1317
1378
 
1318
 
  KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
1379
  KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
1319
1380
 
1320
1381
  KMime::Headers::Base *header = KMime::Headers::createHeader( mParameter.toLatin1() );
1321
1382
  if ( !header ) {
1327
1388
  msg->setHeader( header );
1328
1389
  msg->assemble();
1329
1390
 
1330
 
  new Akonadi::ItemModifyJob( item, FilterIf->filterManager() );
 
1391
  context.setNeedsPayloadStore();
1331
1392
 
1332
1393
  return GoOn;
1333
1394
}
1356
1417
 
1357
1418
  setParamWidgetValue( widget );
1358
1419
 
1359
 
  connect( comboBox, SIGNAL( currentIndexChanged( int ) ),
1360
 
           this, SIGNAL( filterActionModified() ) );
1361
 
  connect( lineEdit, SIGNAL( textChanged( QString ) ),
1362
 
           this, SIGNAL( filterActionModified() ) );
 
1420
  connect( comboBox, SIGNAL(currentIndexChanged(int)),
 
1421
           this, SIGNAL(filterActionModified()) );
 
1422
  connect( lineEdit, SIGNAL(textChanged(QString)),
 
1423
           this, SIGNAL(filterActionModified()) );
1363
1424
 
1364
1425
  return widget;
1365
1426
}
1428
1489
  QString result;
1429
1490
  if ( list.count() < 2 ) {
1430
1491
    result = list[ 0 ];
1431
 
    mValue = "";
 
1492
    mValue.clear();
1432
1493
  } else {
1433
1494
    result = list[ 0 ];
1434
1495
    mValue = list[ 1 ];
1452
1513
{
1453
1514
  public:
1454
1515
    FilterActionRewriteHeader( QObject *parent = 0 );
1455
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1516
    virtual ReturnCode process( ItemContext &context ) const;
1456
1517
    virtual QWidget* createParamWidget( QWidget *parent ) const;
1457
1518
    virtual void setParamWidgetValue( QWidget *paramWidget ) const;
1458
1519
    virtual void applyParamWidgetValue( QWidget *paramWidget );
1487
1548
  mParameter = mParameterList.at( 0 );
1488
1549
}
1489
1550
 
1490
 
FilterAction::ReturnCode FilterActionRewriteHeader::process( const Akonadi::Item &item ) const
 
1551
FilterAction::ReturnCode FilterActionRewriteHeader::process( ItemContext &context ) const
1491
1552
{
1492
1553
  if ( mParameter.isEmpty() || !mRegExp.isValid() )
1493
1554
    return ErrorButGoOn;
1494
1555
 
1495
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
1556
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
1496
1557
 
1497
1558
  KMime::Headers::Base *header = msg->headerByType( mParameter.toLatin1() );
1498
1559
  QString value = header ? header->asUnicodeString(): "";
1506
1567
  header->fromUnicodeString( newValue, "utf-8" );
1507
1568
  msg->assemble();
1508
1569
 
1509
 
  new Akonadi::ItemModifyJob( item, FilterIf->filterManager() );
 
1570
  context.setNeedsPayloadStore();
1510
1571
 
1511
1572
  return GoOn;
1512
1573
}
1543
1604
 
1544
1605
  setParamWidgetValue( widget );
1545
1606
 
1546
 
  connect( comboBox, SIGNAL( currentIndexChanged( int ) ),
1547
 
           this, SIGNAL( filterActionModified() ) );
1548
 
  connect( regExpLineEdit, SIGNAL( textChanged( QString ) ),
1549
 
           this, SIGNAL( filterActionModified() ) );
1550
 
  connect( lineEdit, SIGNAL( textChanged( QString ) ),
1551
 
           this, SIGNAL( filterActionModified() ) );
 
1607
  connect( comboBox, SIGNAL(currentIndexChanged(int)),
 
1608
           this, SIGNAL(filterActionModified()) );
 
1609
  connect( regExpLineEdit, SIGNAL(textChanged(QString)),
 
1610
           this, SIGNAL(filterActionModified()) );
 
1611
  connect( lineEdit, SIGNAL(textChanged(QString)),
 
1612
           this, SIGNAL(filterActionModified()) );
1552
1613
 
1553
1614
  return widget;
1554
1615
}
1650
1711
{
1651
1712
  public:
1652
1713
    FilterActionMove( QObject *parent = 0 );
1653
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1714
    virtual ReturnCode process( ItemContext &context ) const;
1654
1715
    virtual bool requiresBody() const;
1655
1716
    static FilterAction* newAction();
1656
1717
};
1665
1726
{
1666
1727
}
1667
1728
 
1668
 
FilterAction::ReturnCode FilterActionMove::process( const Akonadi::Item &item ) const
 
1729
FilterAction::ReturnCode FilterActionMove::process( ItemContext &context ) const
1669
1730
{
1670
1731
  if ( !mFolder.isValid() ) {
1671
 
    const Akonadi::Collection targetFolder = CommonKernel->collectionFromId( mFolderName );
 
1732
    const Akonadi::Collection targetFolder = CommonKernel->collectionFromId( mFolder.id() );
1672
1733
    if ( !targetFolder.isValid() )
1673
1734
      return ErrorButGoOn;
1674
1735
 
1675
 
    MessageProperty::setFilterFolder( item, targetFolder );
 
1736
    context.setMoveTargetCollection( targetFolder );
1676
1737
    return GoOn;
1677
1738
  }
1678
 
 
1679
 
  MessageProperty::setFilterFolder( item, mFolder );
 
1739
  context.setMoveTargetCollection( mFolder );
1680
1740
  return GoOn;
1681
1741
}
1682
1742
 
1694
1754
{
1695
1755
  public:
1696
1756
    FilterActionCopy( QObject *parent = 0 );
1697
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1757
    virtual ReturnCode process( ItemContext &context ) const;
1698
1758
    virtual bool requiresBody() const;
1699
1759
    static FilterAction* newAction();
1700
1760
};
1709
1769
{
1710
1770
}
1711
1771
 
1712
 
FilterAction::ReturnCode FilterActionCopy::process( const Akonadi::Item &item ) const
 
1772
FilterAction::ReturnCode FilterActionCopy::process( ItemContext &context ) const
1713
1773
{
1714
1774
  // copy the message 1:1
1715
 
  new Akonadi::ItemCopyJob( item, mFolder, FilterIf->filterManager() ); // TODO handle error
 
1775
  new Akonadi::ItemCopyJob( context.item(), mFolder, 0 ); // TODO handle error
1716
1776
 
1717
1777
  return GoOn;
1718
1778
}
1732
1792
  public:
1733
1793
    FilterActionForward( QObject *parent = 0 );
1734
1794
    static FilterAction* newAction();
1735
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1795
    virtual ReturnCode process( ItemContext &context ) const;
1736
1796
    virtual QWidget* createParamWidget( QWidget *parent ) const;
1737
1797
    virtual void applyParamWidgetValue( QWidget *paramWidget );
1738
1798
    virtual void setParamWidgetValue( QWidget *paramWidget ) const;
1755
1815
{
1756
1816
}
1757
1817
 
1758
 
FilterAction::ReturnCode FilterActionForward::process( const Akonadi::Item &item ) const
 
1818
FilterAction::ReturnCode FilterActionForward::process( ItemContext &context ) const
1759
1819
{
1760
1820
  if ( mParameter.isEmpty() )
1761
1821
    return ErrorButGoOn;
1762
1822
 
1763
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
1823
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
1764
1824
  // avoid endless loops when this action is used in a filter
1765
1825
  // which applies to sent messages
1766
1826
  if ( MessageCore::StringUtil::addressIsInAddressList( mParameter,
1769
1829
    return ErrorButGoOn;
1770
1830
  }
1771
1831
 
1772
 
  MessageFactory factory( msg, item.id() );
 
1832
  MessageFactory factory( msg, context.item().id() );
1773
1833
  factory.setIdentityManager( KernelIf->identityManager() );
1774
 
  factory.setFolderIdentity( Util::folderIdentity( item ) );
 
1834
  factory.setFolderIdentity( Util::folderIdentity( context.item() ) );
1775
1835
  factory.setTemplate( mTemplate );
1776
1836
 
1777
1837
  KMime::Message::Ptr fwdMsg = factory.createForward();
1780
1840
    kWarning() << "FilterAction: could not forward message (sending failed)";
1781
1841
    return ErrorButGoOn; // error: couldn't send
1782
1842
  } else
1783
 
    sendMDN( item, KMime::MDN::Dispatched );
 
1843
    sendMDN( context.item(), KMime::MDN::Dispatched );
1784
1844
 
1785
1845
  // (the msgSender takes ownership of the message, so don't delete it here)
1786
1846
  return GoOn;
1820
1880
  templateCombo->setToolTip( i18n( "The template used when forwarding" ) );
1821
1881
  templateCombo->setWhatsThis( i18n( "Set the forwarding template that will be used with this filter." ) );
1822
1882
 
1823
 
  connect( templateCombo, SIGNAL( currentIndexChanged( int ) ),
1824
 
           this, SIGNAL( filterActionModified() ) );
1825
 
  connect( addressRequester, SIGNAL( textChanged() ),
1826
 
           this, SIGNAL( filterActionModified() ) );
 
1883
  connect( templateCombo, SIGNAL(currentIndexChanged(int)),
 
1884
           this, SIGNAL(filterActionModified()) );
 
1885
  connect( addressRequester, SIGNAL(textChanged()),
 
1886
           this, SIGNAL(filterActionModified()) );
1827
1887
 
1828
1888
  return addressAndTemplate;
1829
1889
}
1918
1978
{
1919
1979
  public:
1920
1980
    FilterActionRedirect( QObject *parent = 0 );
1921
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
1981
    virtual ReturnCode process( ItemContext &context ) const;
1922
1982
    static FilterAction* newAction();
1923
1983
};
1924
1984
 
1932
1992
{
1933
1993
}
1934
1994
 
1935
 
FilterAction::ReturnCode FilterActionRedirect::process( const Akonadi::Item &item ) const
 
1995
FilterAction::ReturnCode FilterActionRedirect::process( ItemContext &context ) const
1936
1996
{
1937
1997
  if ( mParameter.isEmpty() )
1938
1998
    return ErrorButGoOn;
1939
1999
 
1940
 
  KMime::Message::Ptr msg = MessageCore::Util::message( item );
 
2000
  KMime::Message::Ptr msg = MessageCore::Util::message( context.item() );
1941
2001
 
1942
 
  MessageFactory factory( msg, item.id() );
1943
 
  factory.setFolderIdentity( Util::folderIdentity( item ) );
 
2002
  MessageFactory factory( msg, context.item().id() );
 
2003
  factory.setFolderIdentity( Util::folderIdentity( context.item() ) );
1944
2004
  factory.setIdentityManager( KernelIf->identityManager() );
1945
2005
 
1946
2006
  KMime::Message::Ptr rmsg = factory.createRedirect( mParameter );
1947
2007
  if ( !rmsg )
1948
2008
    return ErrorButGoOn;
1949
2009
 
1950
 
  sendMDN( item, KMime::MDN::Dispatched );
 
2010
  sendMDN( context.item(), KMime::MDN::Dispatched );
1951
2011
 
1952
2012
  if ( !KernelIf->msgSender()->send( rmsg, MessageSender::SendLater ) ) {
1953
2013
    kDebug() << "FilterAction: could not redirect message (sending failed)";
1966
2026
{
1967
2027
  public:
1968
2028
    FilterActionExec( QObject *parent = 0 );
1969
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
2029
    virtual ReturnCode process( ItemContext &context ) const;
1970
2030
    static FilterAction* newAction();
1971
2031
};
1972
2032
 
1980
2040
{
1981
2041
}
1982
2042
 
1983
 
FilterAction::ReturnCode FilterActionExec::process( const Akonadi::Item &item ) const
 
2043
FilterAction::ReturnCode FilterActionExec::process( ItemContext &context ) const
1984
2044
{
1985
 
  return FilterActionWithCommand::genericProcess( item, false ); // ignore output
 
2045
  return FilterActionWithCommand::genericProcess( context, false ); // ignore output
1986
2046
}
1987
2047
 
1988
2048
 
1995
2055
{
1996
2056
  public:
1997
2057
    FilterActionExtFilter( QObject *parent = 0 );
1998
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
2058
    virtual ReturnCode process( ItemContext &context ) const;
1999
2059
    static FilterAction* newAction();
2000
2060
};
2001
2061
 
2009
2069
{
2010
2070
}
2011
2071
 
2012
 
FilterAction::ReturnCode FilterActionExtFilter::process( const Akonadi::Item &item ) const
 
2072
FilterAction::ReturnCode FilterActionExtFilter::process( ItemContext &context ) const
2013
2073
{
2014
 
  return FilterActionWithCommand::genericProcess( item, true ); // use output
 
2074
  return FilterActionWithCommand::genericProcess( context, true ); // use output
2015
2075
}
2016
2076
 
2017
2077
 
2023
2083
class FilterActionExecSound : public FilterActionWithTest
2024
2084
{
2025
2085
  public:
2026
 
    FilterActionExecSound( QObject *parent = 0 );
 
2086
    FilterActionExecSound(  );
2027
2087
    ~FilterActionExecSound();
2028
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
2088
    virtual ReturnCode process( ItemContext &context ) const;
2029
2089
    virtual bool requiresBody() const;
2030
2090
    static FilterAction* newAction();
2031
2091
 
2052
2112
  SoundTestWidget *soundWidget = new SoundTestWidget( parent );
2053
2113
  soundWidget->setUrl( mParameter );
2054
2114
 
2055
 
  connect( soundWidget, SIGNAL( textChanged( QString ) ),
2056
 
           this, SIGNAL( filterActionModified() ) );
 
2115
  connect( soundWidget, SIGNAL(textChanged(QString)),
 
2116
           this, SIGNAL(filterActionModified()) );
2057
2117
 
2058
2118
  return soundWidget;
2059
2119
}
2089
2149
  return label() + QLatin1String( " \"" ) + Qt::escape( argsAsString() ) + QLatin1String( "\"" );
2090
2150
}
2091
2151
 
2092
 
FilterActionExecSound::FilterActionExecSound( QObject *parent )
 
2152
FilterActionExecSound::FilterActionExecSound( )
2093
2153
  : FilterActionWithTest( "play sound", i18n( "Play Sound" ) ),
2094
2154
    mPlayer( 0 )
2095
2155
{
2105
2165
  return new FilterActionExecSound();
2106
2166
}
2107
2167
 
2108
 
FilterAction::ReturnCode FilterActionExecSound::process( const Akonadi::Item& ) const
 
2168
FilterAction::ReturnCode FilterActionExecSound::process( ItemContext& ) const
2109
2169
{
2110
2170
  if ( mParameter.isEmpty() )
2111
2171
    return ErrorButGoOn;
2145
2205
  KUrlRequester *requester = new KUrlRequester( parent );
2146
2206
  requester->setUrl( KUrl( mParameter ) );
2147
2207
 
2148
 
  connect( requester, SIGNAL( textChanged( QString ) ), this, SIGNAL( filterActionModified() ) );
 
2208
  connect( requester, SIGNAL(textChanged(QString)), this, SIGNAL(filterActionModified()) );
2149
2209
 
2150
2210
  return requester;
2151
2211
}
2192
2252
{
2193
2253
  public:
2194
2254
    FilterActionAddToAddressBook( QObject *parent = 0 );
2195
 
    virtual ReturnCode process( const Akonadi::Item &item ) const;
 
2255
    virtual ReturnCode process( ItemContext &context ) const;
2196
2256
    static FilterAction* newAction();
2197
2257
 
2198
2258
    virtual bool isEmpty() const { return false; }
2237
2297
{
2238
2298
}
2239
2299
 
2240
 
FilterAction::ReturnCode FilterActionAddToAddressBook::process( const Akonadi::Item &item ) const
 
2300
FilterAction::ReturnCode FilterActionAddToAddressBook::process( ItemContext &context ) const
2241
2301
{
2242
 
  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
 
2302
  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
2243
2303
 
2244
2304
  QString headerLine;
2245
2305
  switch ( mHeaderType ) {
2296
2356
        "If it is not accessible, the filter will fallback to the default address book.</p>" ) );
2297
2357
  layout->addWidget( collectionComboBox, 1, 2 );
2298
2358
 
2299
 
  connect( categoryEdit, SIGNAL( textChanged( QString ) ),
2300
 
           this, SIGNAL( filterActionModified() ) );
2301
 
  connect( headerCombo, SIGNAL( currentIndexChanged( int ) ),
2302
 
           this, SIGNAL( filterActionModified() ) );
2303
 
  
 
2359
  connect( categoryEdit, SIGNAL(textChanged(QString)),
 
2360
           this, SIGNAL(filterActionModified()) );
 
2361
  connect( headerCombo, SIGNAL(currentIndexChanged(int)),
 
2362
           this, SIGNAL(filterActionModified()) );
 
2363
 
2304
2364
  setParamWidgetValue( widget );
2305
2365
 
2306
2366
  return widget;
2346
2406
  // we use the previously 'stored' value from the 'collectionId' property
2347
2407
  if ( collection.isValid() ) {
2348
2408
    mCollectionId = collection.id();
2349
 
    connect( collectionComboBox, SIGNAL( currentIndexChanged( int ) ),
2350
 
             this, SIGNAL( filterActionModified() ) );
 
2409
    connect( collectionComboBox, SIGNAL(currentIndexChanged(int)),
 
2410
             this, SIGNAL(filterActionModified()) );
2351
2411
  } else {
2352
2412
    const QVariant value = collectionComboBox->property( "collectionId" );
2353
2413
    if ( value.isValid() )