10 #include "kmfilteraction.h"
12 #include "customtemplates.h"
13 #include "customtemplates_kfg.h"
14 #include "kmcommands.h"
15 #include "kmmsgpart.h"
16 #include "kmfiltermgr.h"
17 #include "kmfolderindex.h"
18 #include "kmfoldermgr.h"
19 #include "messagesender.h"
20 #include "kmmainwidget.h"
21 #include <libkpimidentities/identity.h>
22 #include <libkpimidentities/identitymanager.h>
23 #include <libkpimidentities/identitycombo.h>
24 #include <libtdepim/tdefileio.h>
25 #include <libtdepim/collectingprocess.h>
26 using KPIM::CollectingProcess;
27 #include <mimelib/message.h>
28 #include "kmfawidgets.h"
29 #include "folderrequester.h"
31 #include "kmmsgbase.h"
32 #include "messageproperty.h"
33 #include "actionscheduler.h"
34 using KMail::MessageProperty;
35 using KMail::ActionScheduler;
36 #include "regexplineedit.h"
37 using KMail::RegExpLineEdit;
39 #include <tdetempfile.h>
41 #include <tdelocale.h>
43 #include <kaudioplayer.h>
44 #include <kurlrequester.h>
48 #include <tqtextcodec.h>
51 #include <tqstylesheet.h>
52 #include <tqtooltip.h>
53 #include <tqwhatsthis.h>
69 KMFilterAction::~KMFilterAction()
75 ActionScheduler *handler = MessageProperty::filterHandler( msg );
78 handler->actionMessage( result );
93 return new TQWidget(parent);
115 return kmkernel->filterMgr()->tempOpenFolder(aFolder);
119 const TQValueList<KMime::MDN::DispositionModifier> & m ) {
126 const TQString returnPath = msg->
headerField(
"Return-Path" );
127 const TQString dispNoteTo = msg->
headerField(
"Disposition-Notification-To" );
128 if ( returnPath.isEmpty() )
130 if ( dispNoteTo.isEmpty() )
134 if ( mdn && !kmkernel->msgSender()->send( mdn, KMail::MessageSender::SendLater ) ) {
135 kdDebug(5006) <<
"KMFilterAction::sendMDN(): sending failed." << endl;
140 if ( returnPath.isEmpty() )
142 if ( dispNoteTo.isEmpty() )
177 mParameter = argsStr.stripWhiteSpace().toUInt();
182 return TQString::number( mParameter );
206 TQLineEdit *le =
new KLineEdit(parent);
207 le->setText( mParameter );
213 mParameter = ((TQLineEdit*)paramWidget)->text();
218 ((TQLineEdit*)paramWidget)->setText( mParameter );
223 ((TQLineEdit*)paramWidget)->clear();
228 mParameter = argsStr;
256 TQComboBox *cb =
new TQComboBox(
false, parent );
257 cb->insertStringList( mParameterList );
264 mParameter = ((TQComboBox*)paramWidget)->currentText();
269 int idx = mParameterList.findIndex( mParameter );
270 ((TQComboBox*)paramWidget)->setCurrentItem( idx >= 0 ? idx : 0 );
275 ((TQComboBox*)paramWidget)->setCurrentItem(0);
280 int idx = mParameterList.findIndex( argsStr );
282 mParameterList.append( argsStr );
283 idx = mParameterList.count() - 1;
285 mParameter = *mParameterList.at( idx );
304 kmkernel->getKMMainWidget()->folderTree() );
325 ((
FolderRequester *)paramWidget)->setFolder( kmkernel->draftsFolder() );
330 mFolder = kmkernel->folderMgr()->findIdString( argsStr );
332 mFolder = kmkernel->dimapFolderMgr()->findIdString( argsStr );
334 mFolder = kmkernel->imapFolderMgr()->findIdString( argsStr );
336 mFolderName = mFolder->idString();
338 mFolderName = argsStr;
345 result = mFolder->idString();
347 result = mFolderName;
355 result = mFolder->prettyURL();
357 result = mFolderName;
358 return label() +
" \"" + TQStyleSheet::escape( result ) +
"\"";
363 if ( aFolder == mFolder ) {
364 mFolder = aNewFolder;
366 mFolderName = mFolder->idString();
385 KMFilterActionWithAddressWidget *w =
new KMFilterActionWithAddressWidget(parent);
386 w->setText( mParameter );
392 mParameter = ((KMFilterActionWithAddressWidget*)paramWidget)->text();
397 ((KMFilterActionWithAddressWidget*)paramWidget)->setText( mParameter );
402 ((KMFilterActionWithAddressWidget*)paramWidget)->clear();
411 KMFilterActionWithCommand::KMFilterActionWithCommand(
const char* aName,
const TQString aLabel )
416 TQWidget* KMFilterActionWithCommand::createParamWidget( TQWidget* parent )
const
421 void KMFilterActionWithCommand::applyParamWidgetValue( TQWidget* paramWidget )
426 void KMFilterActionWithCommand::setParamWidgetValue( TQWidget* paramWidget )
const
431 void KMFilterActionWithCommand::clearParamWidget( TQWidget* paramWidget )
const
436 TQString KMFilterActionWithCommand::substituteCommandLineArgsFor(
KMMessage *aMsg, TQPtrList<KTempFile> & aTempFileList )
const
438 TQString result = mParameter;
439 TQValueList<int> argList;
440 TQRegExp r(
"%[0-9-]+" );
444 while ( ( start = r.search( result, start + 1 ) ) > 0 ) {
445 int len = r.matchedLength();
448 int n = result.mid( start + 1, len - 1 ).toInt( &OK );
454 qHeapSort( argList );
458 TQString tempFileName;
459 for ( TQValueList<int>::Iterator it = argList.begin() ; it != argList.end() ; ++it ) {
461 if ( (*it) != lastSeen ) {
462 KTempFile *tf =
new KTempFile();
463 if ( tf->status() != 0 ) {
466 kdDebug(5006) <<
"KMFilterActionWithCommand: Could not create temp file!" << endl;
469 tf->setAutoDelete(
true);
470 aTempFileList.append( tf );
471 tempFileName = tf->name();
473 KPIM::kCStringToFile( aMsg->
asString(), tempFileName,
474 false,
false,
false );
476 KPIM::kByteArrayToFile( aMsg->bodyDecodedBinary(), tempFileName,
477 false,
false,
false );
479 KMMessagePart msgPart;
481 KPIM::kByteArrayToFile( msgPart.bodyDecodedBinary(), tempFileName,
482 false,
false,
false );
489 if ((*it) == -1) result.replace(
"%-1", tempFileName );
490 else result = result.arg( tempFileName );
495 TQRegExp header_rx(
"%\\{([a-z0-9-]+)\\}",
false );
497 while ( ( idx = header_rx.search( result, idx ) ) != -1 ) {
498 TQString replacement = TDEProcess::quote( aMsg->
headerField( TQString(header_rx.cap(1)).latin1() ) );
499 result.replace( idx, header_rx.matchedLength(), replacement );
500 idx += replacement.length();
511 if ( mParameter.isEmpty() )
516 KTempFile * inFile =
new KTempFile;
517 inFile->setAutoDelete(
true);
519 TQPtrList<KTempFile> atmList;
520 atmList.setAutoDelete(
true);
521 atmList.append( inFile );
523 TQString commandLine = substituteCommandLineArgsFor( aMsg , atmList );
524 if ( commandLine.isEmpty() )
534 commandLine =
"(" + commandLine +
") <" + inFile->name();
537 TQString tempFileName = inFile->name();
538 KPIM::kCStringToFile( aMsg->
asString(), tempFileName,
539 false,
false,
false );
542 CollectingProcess shProc;
543 shProc.setUseShell(
true);
544 shProc << commandLine;
547 if ( !shProc.start( TDEProcess::Block,
548 withOutput ? TDEProcess::Stdout
549 : TDEProcess::NoCommunication ) )
552 if ( !shProc.normalExit() || shProc.exitStatus() != 0 ) {
558 TQByteArray msgText = shProc.collectedStdout();
560 if ( !msgText.isEmpty() ) {
567 aMsg->fromByteArray( msgText );
590 KMFilterActionSendReceipt();
597 return (
new KMFilterActionSendReceipt);
600 KMFilterActionSendReceipt::KMFilterActionSendReceipt()
608 if ( !receipt )
return ErrorButGoOn;
612 kmkernel->msgSender()->send( receipt, KMail::MessageSender::SendLater );
626 KMFilterActionTransport();
633 return (
new KMFilterActionTransport);
636 KMFilterActionTransport::KMFilterActionTransport()
643 if ( mParameter.isEmpty() )
657 KMFilterActionReplyTo();
664 return (
new KMFilterActionReplyTo);
667 KMFilterActionReplyTo::KMFilterActionReplyTo()
688 KMFilterActionIdentity();
700 return (
new KMFilterActionIdentity);
703 KMFilterActionIdentity::KMFilterActionIdentity()
706 mParameter = kmkernel->identityManager()->defaultIdentity().uoid();
711 msg->
setHeaderField(
"X-KMail-Identity", TQString::number( mParameter ) );
715 TQWidget * KMFilterActionIdentity::createParamWidget( TQWidget * parent )
const
717 KPIM::IdentityCombo * ic =
new KPIM::IdentityCombo( kmkernel->identityManager(), parent );
718 ic->setCurrentIdentity( mParameter );
722 void KMFilterActionIdentity::applyParamWidgetValue( TQWidget * paramWidget )
724 KPIM::IdentityCombo * ic =
dynamic_cast<KPIM::IdentityCombo*
>( paramWidget );
726 mParameter = ic->currentIdentity();
729 void KMFilterActionIdentity::clearParamWidget( TQWidget * paramWidget )
const
731 KPIM::IdentityCombo * ic =
dynamic_cast<KPIM::IdentityCombo*
>( paramWidget );
733 ic->setCurrentItem( 0 );
737 void KMFilterActionIdentity::setParamWidgetValue( TQWidget * paramWidget )
const
739 KPIM::IdentityCombo * ic =
dynamic_cast<KPIM::IdentityCombo*
>( paramWidget );
741 ic->setCurrentIdentity( mParameter );
751 KMFilterActionSeStatus();
757 virtual bool isEmpty()
const {
return false; }
765 static const KMMsgStatus stati[] =
771 KMMsgStatusForwarded,
779 static const int StatiCount =
sizeof( stati ) /
sizeof( KMMsgStatus );
783 return (
new KMFilterActionSeStatus);
786 KMFilterActionSeStatus::KMFilterActionSeStatus()
791 mParameterList.append(
"" );
792 mParameterList.append( i18n(
"msg status",
"Important") );
793 mParameterList.append( i18n(
"msg status",
"Read") );
794 mParameterList.append( i18n(
"msg status",
"Unread") );
795 mParameterList.append( i18n(
"msg status",
"Replied") );
796 mParameterList.append( i18n(
"msg status",
"Forwarded") );
797 mParameterList.append( i18n(
"msg status",
"Old") );
798 mParameterList.append( i18n(
"msg status",
"New") );
799 mParameterList.append( i18n(
"msg status",
"Watched") );
800 mParameterList.append( i18n(
"msg status",
"Ignored") );
801 mParameterList.append( i18n(
"msg status",
"Spam") );
802 mParameterList.append( i18n(
"msg status",
"Ham") );
804 mParameter = *mParameterList.at(0);
809 int idx = mParameterList.findIndex( mParameter );
810 if ( idx < 1 )
return ErrorButGoOn;
812 KMMsgStatus status = stati[idx-1] ;
817 bool KMFilterActionSeStatus::requiresBody(KMMsgBase*)
const
822 void KMFilterActionSeStatus::argsFromString(
const TQString argsStr )
824 if ( argsStr.length() == 1 ) {
825 for (
int i = 0 ; i < StatiCount ; i++ )
826 if ( KMMsgBase::statusToStr(stati[i])[0] == argsStr[0] ) {
827 mParameter = *mParameterList.at(i+1);
831 mParameter = *mParameterList.at(0);
834 const TQString KMFilterActionSeStatus::argsAsString()
const
836 int idx = mParameterList.findIndex( mParameter );
837 if ( idx < 1 )
return TQString();
839 KMMsgStatus status = stati[idx-1];
840 return KMMsgBase::statusToStr(status);
843 const TQString KMFilterActionSeStatus::displayString()
const
847 return label() +
" \"" + TQStyleSheet::escape( argsAsString() ) +
"\"";
857 KMFilterActionFakeDisposition();
860 return (
new KMFilterActionFakeDisposition);
863 virtual bool isEmpty()
const {
return false; }
873 static const KMime::MDN::DispositionType mdns[] =
875 KMime::MDN::Displayed,
877 KMime::MDN::Dispatched,
878 KMime::MDN::Processed,
882 static const int numMDNs =
sizeof mdns /
sizeof *mdns;
885 KMFilterActionFakeDisposition::KMFilterActionFakeDisposition()
890 mParameterList.append(
"" );
891 mParameterList.append( i18n(
"MDN type",
"Ignore") );
892 mParameterList.append( i18n(
"MDN type",
"Displayed") );
893 mParameterList.append( i18n(
"MDN type",
"Deleted") );
894 mParameterList.append( i18n(
"MDN type",
"Dispatched") );
895 mParameterList.append( i18n(
"MDN type",
"Processed") );
896 mParameterList.append( i18n(
"MDN type",
"Denied") );
897 mParameterList.append( i18n(
"MDN type",
"Failed") );
899 mParameter = *mParameterList.at(0);
904 int idx = mParameterList.findIndex( mParameter );
905 if ( idx < 1 )
return ErrorButGoOn;
908 msg->setMDNSentState( KMMsgMDNIgnore );
910 sendMDN( msg, mdns[idx-2] );
914 void KMFilterActionFakeDisposition::argsFromString(
const TQString argsStr )
916 if ( argsStr.length() == 1 ) {
917 if ( argsStr[0] ==
'I' ) {
918 mParameter = *mParameterList.at(1);
921 for (
int i = 0 ; i < numMDNs ; i++ )
922 if (
char(mdns[i]) == argsStr[0] ) {
923 mParameter = *mParameterList.at(i+2);
927 mParameter = *mParameterList.at(0);
930 const TQString KMFilterActionFakeDisposition::argsAsString()
const
932 int idx = mParameterList.findIndex( mParameter );
933 if ( idx < 1 )
return TQString();
935 return TQString( TQChar( idx < 2 ?
'I' :
char(mdns[idx-2]) ) );
938 const TQString KMFilterActionFakeDisposition::displayString()
const
942 return label() +
" \"" + TQStyleSheet::escape( argsAsString() ) +
"\"";
952 KMFilterActionRemoveHeader();
962 return (
new KMFilterActionRemoveHeader);
965 KMFilterActionRemoveHeader::KMFilterActionRemoveHeader()
971 <<
"X-TDE-PR-Message"
972 <<
"X-TDE-PR-Package"
973 <<
"X-TDE-PR-Keywords";
974 mParameter = *mParameterList.at(0);
977 TQWidget* KMFilterActionRemoveHeader::createParamWidget( TQWidget* parent )
const
979 TQComboBox *cb =
new TQComboBox(
true, parent );
980 cb->setInsertionPolicy( TQComboBox::AtBottom );
981 setParamWidgetValue( cb );
987 if ( mParameter.isEmpty() )
return ErrorButGoOn;
989 while ( !msg->
headerField( mParameter.latin1() ).isEmpty() )
994 void KMFilterActionRemoveHeader::setParamWidgetValue( TQWidget* paramWidget )
const
996 TQComboBox * cb =
dynamic_cast<TQComboBox*
>(paramWidget);
999 int idx = mParameterList.findIndex( mParameter );
1001 cb->insertStringList( mParameterList );
1003 cb->insertItem( mParameter );
1004 cb->setCurrentItem( cb->count() - 1 );
1006 cb->setCurrentItem( idx );
1018 KMFilterActionAddHeader();
1032 return (
new KMFilterActionAddHeader);
1038 KMFilterActionAddHeader::KMFilterActionAddHeader()
1041 mParameterList <<
""
1044 <<
"X-TDE-PR-Message"
1045 <<
"X-TDE-PR-Package"
1046 <<
"X-TDE-PR-Keywords";
1047 mParameter = *mParameterList.at(0);
1052 if ( mParameter.isEmpty() )
return ErrorButGoOn;
1058 TQWidget* KMFilterActionAddHeader::createParamWidget( TQWidget* parent )
const
1060 TQWidget *w =
new TQWidget( parent );
1061 TQHBoxLayout *hbl =
new TQHBoxLayout( w );
1062 hbl->setSpacing( 4 );
1063 TQComboBox *cb =
new TQComboBox(
true, w,
"combo" );
1064 cb->setInsertionPolicy( TQComboBox::AtBottom );
1065 hbl->addWidget( cb, 0 );
1066 TQLabel *l =
new TQLabel( i18n(
"With value:"), w );
1067 l->setFixedWidth( l->sizeHint().width() );
1068 hbl->addWidget( l, 0 );
1069 TQLineEdit *le =
new KLineEdit( w,
"ledit" );
1070 hbl->addWidget( le, 1 );
1071 setParamWidgetValue( w );
1075 void KMFilterActionAddHeader::setParamWidgetValue( TQWidget* paramWidget )
const
1077 int idx = mParameterList.findIndex( mParameter );
1078 TQComboBox *cb = (TQComboBox*)paramWidget->child(
"combo");
1081 cb->insertStringList( mParameterList );
1083 cb->insertItem( mParameter );
1084 cb->setCurrentItem( cb->count() - 1 );
1086 cb->setCurrentItem( idx );
1088 TQLineEdit *le = (TQLineEdit*)paramWidget->child(
"ledit");
1090 le->setText( mValue );
1093 void KMFilterActionAddHeader::applyParamWidgetValue( TQWidget* paramWidget )
1095 TQComboBox *cb = (TQComboBox*)paramWidget->child(
"combo");
1097 mParameter = cb->currentText();
1099 TQLineEdit *le = (TQLineEdit*)paramWidget->child(
"ledit");
1101 mValue = le->text();
1104 void KMFilterActionAddHeader::clearParamWidget( TQWidget* paramWidget )
const
1106 TQComboBox *cb = (TQComboBox*)paramWidget->child(
"combo");
1108 cb->setCurrentItem(0);
1109 TQLineEdit *le = (TQLineEdit*)paramWidget->child(
"ledit");
1114 const TQString KMFilterActionAddHeader::argsAsString()
const
1116 TQString result = mParameter;
1123 const TQString KMFilterActionAddHeader::displayString()
const
1127 return label() +
" \"" + TQStyleSheet::escape( argsAsString() ) +
"\"";
1130 void KMFilterActionAddHeader::argsFromString(
const TQString argsStr )
1132 TQStringList l = TQStringList::split(
'\t', argsStr,
true );
1134 if ( l.count() < 2 ) {
1142 int idx = mParameterList.findIndex( s );
1144 mParameterList.append( s );
1145 idx = mParameterList.count() - 1;
1147 mParameter = *mParameterList.at( idx );
1158 KMFilterActionRewriteHeader();
1172 return (
new KMFilterActionRewriteHeader);
1176 TQString mReplacementString;
1179 KMFilterActionRewriteHeader::KMFilterActionRewriteHeader()
1182 mParameterList <<
""
1186 <<
"X-TDE-PR-Message"
1187 <<
"X-TDE-PR-Package"
1188 <<
"X-TDE-PR-Keywords";
1189 mParameter = *mParameterList.at(0);
1194 if ( mParameter.isEmpty() || !mRegExp.isValid() )
1195 return ErrorButGoOn;
1197 KRegExp3 rx = mRegExp;
1199 TQString newValue = rx.replace( msg->
headerField( mParameter.latin1() ),
1200 mReplacementString );
1206 TQWidget* KMFilterActionRewriteHeader::createParamWidget( TQWidget* parent )
const
1208 TQWidget *w =
new TQWidget( parent );
1209 TQHBoxLayout *hbl =
new TQHBoxLayout( w );
1210 hbl->setSpacing( 4 );
1212 TQComboBox *cb =
new TQComboBox(
true, w,
"combo" );
1213 cb->setInsertionPolicy( TQComboBox::AtBottom );
1214 hbl->addWidget( cb, 0 );
1216 TQLabel *l =
new TQLabel( i18n(
"Replace:"), w );
1217 l->setFixedWidth( l->sizeHint().width() );
1218 hbl->addWidget( l, 0 );
1220 RegExpLineEdit *rele =
new RegExpLineEdit( w,
"search" );
1221 hbl->addWidget( rele, 1 );
1223 l =
new TQLabel( i18n(
"With:"), w );
1224 l->setFixedWidth( l->sizeHint().width() );
1225 hbl->addWidget( l, 0 );
1227 TQLineEdit *le =
new KLineEdit( w,
"replace" );
1228 hbl->addWidget( le, 1 );
1230 setParamWidgetValue( w );
1234 void KMFilterActionRewriteHeader::setParamWidgetValue( TQWidget* paramWidget )
const
1236 int idx = mParameterList.findIndex( mParameter );
1237 TQComboBox *cb = (TQComboBox*)paramWidget->child(
"combo");
1241 cb->insertStringList( mParameterList );
1243 cb->insertItem( mParameter );
1244 cb->setCurrentItem( cb->count() - 1 );
1246 cb->setCurrentItem( idx );
1249 RegExpLineEdit *rele = (RegExpLineEdit*)paramWidget->child(
"search");
1251 rele->setText( mRegExp.pattern() );
1253 TQLineEdit *le = (TQLineEdit*)paramWidget->child(
"replace");
1255 le->setText( mReplacementString );
1258 void KMFilterActionRewriteHeader::applyParamWidgetValue( TQWidget* paramWidget )
1260 TQComboBox *cb = (TQComboBox*)paramWidget->child(
"combo");
1262 mParameter = cb->currentText();
1264 RegExpLineEdit *rele = (RegExpLineEdit*)paramWidget->child(
"search");
1266 mRegExp.setPattern( rele->text() );
1268 TQLineEdit *le = (TQLineEdit*)paramWidget->child(
"replace");
1270 mReplacementString = le->text();
1273 void KMFilterActionRewriteHeader::clearParamWidget( TQWidget* paramWidget )
const
1275 TQComboBox *cb = (TQComboBox*)paramWidget->child(
"combo");
1277 cb->setCurrentItem(0);
1279 RegExpLineEdit *rele = (RegExpLineEdit*)paramWidget->child(
"search");
1283 TQLineEdit *le = (TQLineEdit*)paramWidget->child(
"replace");
1288 const TQString KMFilterActionRewriteHeader::argsAsString()
const
1290 TQString result = mParameter;
1292 result += mRegExp.pattern();
1294 result += mReplacementString;
1299 const TQString KMFilterActionRewriteHeader::displayString()
const
1303 return label() +
" \"" + TQStyleSheet::escape( argsAsString() ) +
"\"";
1306 void KMFilterActionRewriteHeader::argsFromString(
const TQString argsStr )
1308 TQStringList l = TQStringList::split(
'\t', argsStr,
true );
1312 mRegExp.setPattern( l[1] );
1313 mReplacementString = l[2];
1315 int idx = mParameterList.findIndex( s );
1317 mParameterList.append( s );
1318 idx = mParameterList.count() - 1;
1320 mParameter = *mParameterList.at( idx );
1331 KMFilterActionMove();
1339 return (
new KMFilterActionMove);
1342 KMFilterActionMove::KMFilterActionMove()
1350 return ErrorButGoOn;
1352 ActionScheduler *handler = MessageProperty::filterHandler( msg );
1354 MessageProperty::setFilterFolder( msg, mFolder );
1359 check = kmkernel->imapFolderMgr()->findIdString( argsAsString() );
1360 if (mFolder && (check != mFolder)) {
1361 MessageProperty::setFilterFolder( msg, mFolder );
1367 bool KMFilterActionMove::requiresBody(KMMsgBase*)
const
1380 KMFilterActionCopy();
1389 return (
new KMFilterActionCopy);
1392 KMFilterActionCopy::KMFilterActionCopy()
1403 return ErrorButGoOn;
1404 if ( mFolder && mFolder->open(
"filtercopy" ) != 0 )
1405 return ErrorButGoOn;
1411 int rc = mFolder->addMsg(msgCopy, &index);
1412 if (rc == 0 && index != -1)
1413 mFolder->unGetMsg( index );
1414 mFolder->close(
"filtercopy");
1419 void KMFilterActionCopy::processAsync(
KMMessage* msg)
const
1422 kdDebug(5006) <<
"##### KMFilterActionCopy::processAsync(KMMessage* msg)" << endl;
1423 ActionScheduler *handler = MessageProperty::filterHandler( msg );
1425 KMCommand *cmd =
new KMCopyCommand( mFolder, msg );
1426 TQObject::connect( cmd, TQ_SIGNAL( completed( KMCommand * ) ),
1427 handler, TQ_SLOT( copyMessageFinished( KMCommand * ) ) );
1431 bool KMFilterActionCopy::requiresBody(KMMsgBase*)
const
1444 KMFilterActionForward();
1458 mutable TQString mTemplate;
1463 return (
new KMFilterActionForward);
1466 KMFilterActionForward::KMFilterActionForward()
1473 if ( mParameter.isEmpty() )
1474 return ErrorButGoOn;
1479 kdWarning(5006) <<
"Attempt to forward to receipient of original message, ignoring." << endl;
1480 return ErrorButGoOn;
1484 fwdMsg->setTo( fwdMsg->
to() +
',' + mParameter );
1486 if ( !kmkernel->msgSender()->send( fwdMsg, KMail::MessageSender::SendDefault ) ) {
1487 kdWarning(5006) <<
"KMFilterAction: could not forward message (sending failed)" << endl;
1488 return ErrorButGoOn;
1491 sendMDN( aMsg, KMime::MDN::Dispatched );
1498 TQWidget* KMFilterActionForward::createParamWidget( TQWidget* parent )
const
1500 TQWidget *addressAndTemplate =
new TQWidget( parent );
1501 TQHBoxLayout *hBox =
new TQHBoxLayout( addressAndTemplate );
1503 addressEdit->setName(
"addressEdit" );
1504 hBox->addWidget( addressEdit );
1506 KLineEdit *lineEdit =
dynamic_cast<KLineEdit*
>( addressEdit->child(
"addressEdit" ) );
1507 Q_ASSERT( lineEdit );
1508 TQToolTip::add( lineEdit, i18n(
"The addressee the message will be forwarded to" ) );
1509 TQWhatsThis::add( lineEdit, i18n(
"The filter will forward the message to the addressee entered here." ) );
1511 TQComboBox *templateCombo =
new TQComboBox( addressAndTemplate );
1512 templateCombo->setName(
"templateCombo" );
1513 hBox->addWidget( templateCombo );
1515 templateCombo->insertItem( i18n(
"Default Template" ) );
1516 TQStringList templateNames = GlobalSettingsBase::self()->customTemplates();
1517 for ( TQStringList::const_iterator it = templateNames.begin(); it != templateNames.end();
1519 CTemplates templat( *it );
1520 if ( templat.type() == CustomTemplates::TForward ||
1521 templat.type() == CustomTemplates::TUniversal )
1522 templateCombo->insertItem( *it );
1524 templateCombo->setEnabled( templateCombo->count() > 1 );
1525 TQToolTip::add( templateCombo, i18n(
"The template used when forwarding" ) );
1526 TQWhatsThis::add( templateCombo, i18n(
"Set the forwarding template that will be used with this filter." ) );
1528 return addressAndTemplate;
1531 void KMFilterActionForward::applyParamWidgetValue( TQWidget* paramWidget )
1534 TQWidget *addressEdit =
dynamic_cast<TQWidget*
>( paramWidget->child(
"addressEdit" ) );
1535 Q_ASSERT( addressEdit );
1538 TQComboBox *templateCombo =
dynamic_cast<TQComboBox*
>( paramWidget->child(
"templateCombo" ) );
1539 Q_ASSERT( templateCombo );
1541 if ( templateCombo->currentItem() == 0 ) {
1543 mTemplate = TQString();
1546 mTemplate = templateCombo->currentText();
1550 void KMFilterActionForward::setParamWidgetValue( TQWidget* paramWidget )
const
1552 TQWidget *addressEdit =
dynamic_cast<TQWidget*
>( paramWidget->child(
"addressEdit" ) );
1553 Q_ASSERT( addressEdit );
1556 TQComboBox *templateCombo =
dynamic_cast<TQComboBox*
>( paramWidget->child(
"templateCombo" ) );
1557 Q_ASSERT( templateCombo );
1559 if ( mTemplate.isEmpty() ) {
1560 templateCombo->setCurrentItem( 0 );
1564 int templateIndex = -1;
1565 for (
int i = 1; i < templateCombo->count(); i++ ) {
1566 if ( templateCombo->text( i ) == mTemplate ) {
1572 if ( templateIndex != -1 ) {
1573 templateCombo->setCurrentItem( templateIndex );
1576 mTemplate = TQString();
1581 void KMFilterActionForward::clearParamWidget( TQWidget* paramWidget )
const
1583 TQWidget *addressEdit =
dynamic_cast<TQWidget*
>( paramWidget->child(
"addressEdit" ) );
1584 Q_ASSERT( addressEdit );
1587 TQComboBox *templateCombo =
dynamic_cast<TQComboBox*
>( paramWidget->child(
"templateCombo" ) );
1588 Q_ASSERT( templateCombo );
1590 templateCombo->setCurrentItem( 0 );
1595 static const TQString forwardFilterArgsSeperator =
"@$$@";
1597 void KMFilterActionForward::argsFromString(
const TQString argsStr )
1599 int seperatorPos = argsStr.find( forwardFilterArgsSeperator );
1601 if ( seperatorPos == - 1 ) {
1606 TQString addressee = argsStr.left( seperatorPos );
1607 mTemplate = argsStr.mid( seperatorPos + forwardFilterArgsSeperator.length() );
1612 const TQString KMFilterActionForward::argsAsString()
const
1617 const TQString KMFilterActionForward::displayString()
const
1619 if ( mTemplate.isEmpty() )
1620 return i18n(
"Forward to %1 with default template " ).arg( mParameter );
1622 return i18n(
"Forward to %1 with template %2" ).arg( mParameter, mTemplate );
1632 KMFilterActionRedirect();
1639 return (
new KMFilterActionRedirect);
1642 KMFilterActionRedirect::KMFilterActionRedirect()
1650 if ( mParameter.isEmpty() )
1651 return ErrorButGoOn;
1655 sendMDN( aMsg, KMime::MDN::Dispatched );
1657 if ( !kmkernel->msgSender()->send( msg, KMail::MessageSender::SendLater ) ) {
1658 kdDebug(5006) <<
"KMFilterAction: could not redirect message (sending failed)" << endl;
1659 return ErrorButGoOn;
1669 class KMFilterActionExec :
public KMFilterActionWithCommand
1672 KMFilterActionExec();
1679 return (
new KMFilterActionExec());
1682 KMFilterActionExec::KMFilterActionExec()
1683 : KMFilterActionWithCommand(
"execute", i18n(
"Execute Command") )
1689 return KMFilterActionWithCommand::genericProcess( aMsg,
false );
1699 class PipeJob :
public KPIM::ThreadWeaver::Job
1702 PipeJob(TQObject* parent = 0 ,
const char* name = 0,
KMMessage* aMsg = 0, TQString cmd = 0, TQString tempFileName = 0 )
1703 : Job (parent, name),
1704 mTempFileName(tempFileName),
1711 virtual void processEvent( KPIM::ThreadWeaver::Event *ev )
1713 KPIM::ThreadWeaver::Job::processEvent( ev );
1714 if ( ev->action() == KPIM::ThreadWeaver::Event::JobFinished )
1720 KPIM::ThreadWeaver::debug (1,
"PipeJob::run: doing it .\n");
1725 TQString origSerNum = mMsg->headerField(
"X-KMail-Filtered" );
1727 p = popen(TQFile::encodeName(mCmd),
"r");
1732 if (! fgets( buffer, len, p ) )
break;
1733 int oldsize = ba.size();
1734 ba.resize( oldsize + strlen(buffer) );
1735 tqmemmove( ba.begin() + oldsize, buffer, strlen(buffer) );
1738 if ( !ba.isEmpty() ) {
1739 KPIM::ThreadWeaver::debug (1,
"PipeJob::run: %s", TQString(ba).latin1() );
1740 KMFolder *filterFolder = mMsg->parent();
1741 ActionScheduler *handler = MessageProperty::filterHandler( mMsg->getMsgSerNum() );
1743 mMsg->fromByteArray( ba );
1744 if ( !origSerNum.isEmpty() )
1745 mMsg->setHeaderField(
"X-KMail-Filtered", origSerNum );
1746 if ( filterFolder && handler ) {
1747 bool oldStatus = handler->ignoreChanges(
true );
1748 filterFolder->
take( filterFolder->
find( mMsg ) );
1749 filterFolder->
addMsg( mMsg );
1750 handler->ignoreChanges( oldStatus );
1752 kdDebug(5006) <<
"Warning: Cannot refresh the message from the external filter." << endl;
1756 KPIM::ThreadWeaver::debug (1,
"PipeJob::run: done.\n" );
1758 TQFile::remove(mTempFileName);
1760 TQString mTempFileName;
1765 class KMFilterActionExtFilter:
public KMFilterActionWithCommand
1768 KMFilterActionExtFilter();
1770 virtual void processAsync(
KMMessage* msg)
const;
1776 return (
new KMFilterActionExtFilter);
1779 KMFilterActionExtFilter::KMFilterActionExtFilter()
1780 : KMFilterActionWithCommand(
"filter app", i18n(
"Pipe Through") )
1785 return KMFilterActionWithCommand::genericProcess( aMsg,
true );
1788 void KMFilterActionExtFilter::processAsync(
KMMessage* aMsg)
const
1791 ActionScheduler *handler = MessageProperty::filterHandler( aMsg->getMsgSerNum() );
1792 KTempFile * inFile =
new KTempFile;
1793 inFile->setAutoDelete(
false);
1795 TQPtrList<KTempFile> atmList;
1796 atmList.setAutoDelete(
true);
1797 atmList.append( inFile );
1799 TQString commandLine = substituteCommandLineArgsFor( aMsg , atmList );
1800 if ( commandLine.isEmpty() )
1801 handler->actionMessage( ErrorButGoOn );
1810 commandLine =
"(" + commandLine +
") <" + inFile->name();
1813 TQString tempFileName = inFile->name();
1814 KPIM::kCStringToFile( aMsg->
asString(), tempFileName,
1815 false,
false,
false );
1818 PipeJob *job =
new PipeJob(0, 0, aMsg, commandLine, tempFileName);
1819 TQObject::connect ( job, TQ_SIGNAL( done() ), handler, TQ_SLOT( actionMessage() ) );
1820 kmkernel->weaver()->enqueue(job);
1827 class KMFilterActionExecSound :
public KMFilterActionWithTest
1830 KMFilterActionExecSound();
1832 virtual bool requiresBody(KMMsgBase*)
const;
1836 KMFilterActionWithTest::KMFilterActionWithTest(
const char* aName,
const TQString aLabel )
1841 KMFilterActionWithTest::~KMFilterActionWithTest()
1845 TQWidget* KMFilterActionWithTest::createParamWidget( TQWidget* parent )
const
1847 KMSoundTestWidget *le =
new KMSoundTestWidget(parent);
1848 le->setUrl( mParameter );
1853 void KMFilterActionWithTest::applyParamWidgetValue( TQWidget* paramWidget )
1855 mParameter = ((KMSoundTestWidget*)paramWidget)->url();
1858 void KMFilterActionWithTest::setParamWidgetValue( TQWidget* paramWidget )
const
1860 ((KMSoundTestWidget*)paramWidget)->setUrl( mParameter );
1863 void KMFilterActionWithTest::clearParamWidget( TQWidget* paramWidget )
const
1865 ((KMSoundTestWidget*)paramWidget)->clear();
1868 void KMFilterActionWithTest::argsFromString(
const TQString argsStr )
1870 mParameter = argsStr;
1873 const TQString KMFilterActionWithTest::argsAsString()
const
1878 const TQString KMFilterActionWithTest::displayString()
const
1882 return label() +
" \"" + TQStyleSheet::escape( argsAsString() ) +
"\"";
1886 KMFilterActionExecSound::KMFilterActionExecSound()
1887 : KMFilterActionWithTest(
"play sound", i18n(
"Play Sound") )
1893 return (
new KMFilterActionExecSound());
1898 if ( mParameter.isEmpty() )
1899 return ErrorButGoOn;
1900 TQString play = mParameter;
1901 TQString file = TQString::fromLatin1(
"file:");
1902 if (mParameter.startsWith(file))
1903 play = mParameter.mid(file.length());
1904 KAudioPlayer::play(TQFile::encodeName(play));
1908 bool KMFilterActionExecSound::requiresBody(KMMsgBase*)
const
1918 KMFilterActionWithUrl::~KMFilterActionWithUrl()
1924 KURLRequester *le =
new KURLRequester(parent);
1925 le->setURL( mParameter );
1932 mParameter = ((KURLRequester*)paramWidget)->url();
1937 ((KURLRequester*)paramWidget)->setURL( mParameter );
1942 ((KURLRequester*)paramWidget)->clear();
1947 mParameter = argsStr;
1970 insert( KMFilterActionMove::newAction );
1971 insert( KMFilterActionCopy::newAction );
1972 insert( KMFilterActionIdentity::newAction );
1973 insert( KMFilterActionSeStatus::newAction );
1974 insert( KMFilterActionFakeDisposition::newAction );
1975 insert( KMFilterActionTransport::newAction );
1976 insert( KMFilterActionReplyTo::newAction );
1977 insert( KMFilterActionForward::newAction );
1978 insert( KMFilterActionRedirect::newAction );
1979 insert( KMFilterActionSendReceipt::newAction );
1980 insert( KMFilterActionExec::newAction );
1981 insert( KMFilterActionExtFilter::newAction );
1982 insert( KMFilterActionRemoveHeader::newAction );
1983 insert( KMFilterActionAddHeader::newAction );
1984 insert( KMFilterActionRewriteHeader::newAction );
1985 insert( KMFilterActionExecSound::newAction );
1990 KMFilterActionDict::KMFilterActionDict()
1993 mList.setAutoDelete(
true);
2001 desc->name = action->
name();
2002 desc->label = action->
label();
2003 desc->create = aNewFunc;
2004 TQDict<KMFilterActionDesc>::insert( desc->name, desc );
2005 TQDict<KMFilterActionDesc>::insert( desc->label, desc );
2006 mList.append( desc );