[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: Re: kmail's fileter execute command parameters
From: Marc Mutz <mutz () kde ! org>
Date: 2002-12-30 16:15:35
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
On Monday 30 December 2002 11:32, Chris wrote:
<snip>
> In the documentation it talks about using %0 for the body, %1 for the
> first attachement and so on. Is there a flag for the subject line, or
> any of the other parts of the message?
<snip>
What about attached patch?
It now replaces all occurrences of %{foo} with the content of the foo
header.
Marc
--
This is as small as I think is sensible.
-- Don Sanders after commiting a 1MB patch to KMail CVS
["kmfilteraction.cpp.diff" (text/x-diff)]
Index: kmfilteraction.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfilteraction.cpp,v
retrieving revision 1.83.2.1
diff -u -3 -p -r1.83.2.1 kmfilteraction.cpp
--- kmfilteraction.cpp 8 Dec 2002 06:54:37 -0000 1.83.2.1
+++ kmfilteraction.cpp 30 Dec 2002 16:19:37 -0000
@@ -351,14 +351,14 @@ QString KMFilterActionWithCommand::subst
{
QString result = mParameter;
QValueList<int> argList;
- QRegExp r( "%[\\-0-9]+" );
- int start=-1, len=0;
- bool OK = FALSE;
+ QRegExp r( "%[0-9-]+" );
// search for '%n'
+ int start = -1;
while ( ( start = r.search( result, start + 1 ) ) > 0 ) {
- len = r.matchedLength();
+ int len = r.matchedLength();
// and save the encountered 'n' in a list.
+ bool OK = false;
int n = result.mid( start + 1, len - 1 ).toInt( &OK );
if ( OK )
argList.append( n );
@@ -370,9 +370,7 @@ QString KMFilterActionWithCommand::subst
// and use QString::arg to substitute filenames for the %n's.
int lastSeen = -2;
QString tempFileName;
- KMMessagePart msgPart;
- QValueList<int>::Iterator it;
- for ( it = argList.begin() ; it != argList.end() ; ++it ) {
+ for ( QValueList<int>::Iterator it = argList.begin() ; it != argList.end() ; ++it ) {
// setup temp files with check for duplicate %n's
if ( (*it) != lastSeen ) {
KTempFile *tf = new KTempFile();
@@ -392,6 +390,7 @@ QString KMFilterActionWithCommand::subst
kByteArrayToFile( aMsg->bodyDecodedBinary(), tempFileName,
false, false, false );
else {
+ KMMessagePart msgPart;
aMsg->bodyPart( (*it), &msgPart );
kByteArrayToFile( msgPart.bodyDecodedBinary(), tempFileName,
false, false, false );
@@ -403,6 +402,16 @@ QString KMFilterActionWithCommand::subst
// many times as there are %n's, regardless of their multiplicity.
if ((*it) == -1) result.replace( QRegExp("%-1"), tempFileName );
else result = result.arg( tempFileName );
+ }
+
+ // And finally, replace the %{foo} with the content of the foo
+ // header field:
+ QRegExp header_rx( "%\\{([a-z0-9-]+)\\}", false );
+ int idx = 0;
+ while ( ( idx = header_rx.search( result, idx ) ) != -1 ) {
+ QString replacement = KProcess::quote( aMsg->headerField( header_rx.cap(1).latin1() ) );
+ result.replace( idx, header_rx.matchedLength(), replacement );
+ idx += replacement.length();
}
return result;
[Attachment #6 (application/pgp-signature)]
_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic