24 #include <tqdatetime.h>
25 #include <tdelocale.h>
26 #include <kcalendarsystem.h>
27 #include <kmime_util.h>
28 #include <tdeglobal.h>
29 #include <tdeprocess.h>
32 #include <tdemessagebox.h>
34 #include <tqfileinfo.h>
36 #include "kmmessage.h"
37 #include "kmmsgbase.h"
39 #include "templatesconfiguration.h"
40 #include "templatesconfiguration_kfg.h"
41 #include "customtemplates_kfg.h"
42 #include "globalsettings_base.h"
44 #include <libkpimidentities/identity.h>
45 #include <libkpimidentities/identitymanager.h>
47 #include "attachmentcollector.h"
48 #include "objecttreeparser.h"
51 #include "templateparser.h"
52 #include <mimelib/bodypart.h>
54 using namespace KMail;
56 TemplateParser::TemplateParser(
KMMessage *amsg,
const Mode amode ) :
57 mMode( amode ), mFolder( 0 ), mIdentity( 0 ),
58 mAllowDecryption( false ),
59 mDebug( false ), mQuoteString(
"> " ), mAppend( false ), mOrigRoot( 0 )
66 mSelection = selection;
71 mAllowDecryption = allowDecryption;
77 return ( mMode == Reply || mMode == ReplyAll) && GlobalSettings::stripSignature();
80 TemplateParser::~TemplateParser()
86 int TemplateParser::parseQuotes(
const TQString &prefix,
const TQString &str,
87 TQString "e )
const
89 int pos = prefix.length();
91 int str_len = str.length();
98 while ( pos < str_len ) {
110 }
else if ( c == qc ) {
121 TQString TemplateParser::getFName(
const TQString &str )
129 if ( ( sep_pos = str.find(
'@' ) ) > 0 ) {
131 for ( i = (sep_pos - 1); i >= 0; --i ) {
133 if ( c.isLetterOrNumber() ) {
139 }
else if ( ( sep_pos = str.find(
',') ) > 0 ) {
142 for ( i = sep_pos; i < str.length(); ++i ) {
144 if ( c.isLetterOrNumber() ) {
147 }
else if ( begin ) {
153 for ( i = 0; i < str.length(); ++i ) {
155 if ( c.isLetterOrNumber() ) {
165 TQString TemplateParser::getLName(
const TQString &str )
172 if ( ( sep_pos = str.find(
',') ) > 0 ) {
174 for ( i = sep_pos; i >= 0; --i ) {
176 if ( c.isLetterOrNumber() ) {
183 if ( ( sep_pos = str.find(
' ' ) ) > 0 ) {
186 for ( i = sep_pos; i < str.length(); ++i ) {
188 if ( c.isLetterOrNumber() ) {
191 }
else if ( begin ) {
200 void TemplateParser::process(
KMMessage *aorig_msg,
KMFolder *afolder,
bool append )
203 mOrigMsg = aorig_msg;
206 return processWithTemplate( tmpl );
209 void TemplateParser::process(
const TQString &tmplName,
KMMessage *aorig_msg,
213 mOrigMsg = aorig_msg;
216 return processWithTemplate( tmpl );
219 void TemplateParser::processWithTemplate(
const TQString &tmpl )
222 int tmpl_len = tmpl.length();
224 for (
int i = 0; i < tmpl_len; ++i ) {
228 TQString cmd = tmpl.mid( i + 1 );
230 if ( cmd.startsWith(
"-" ) ) {
232 kdDebug() <<
"Command: -" << endl;
236 }
else if ( cmd.startsWith(
"REM=" ) ) {
238 kdDebug() <<
"Command: REM=" << endl;
240 int len = parseQuotes(
"REM=", cmd, q );
243 }
else if ( cmd.startsWith(
"INSERT=" ) ) {
245 kdDebug() <<
"Command: INSERT=" << endl;
247 int len = parseQuotes(
"INSERT=", cmd, q );
249 TQString path = KShell::tildeExpand( q );
250 TQFileInfo finfo( path );
251 if (finfo.isRelative() ) {
252 path = KShell::homeDir(
"" );
257 if ( file.open( IO_ReadOnly ) ) {
258 TQByteArray content = file.readAll();
259 TQString str = TQString::fromLocal8Bit( content, content.size() );
261 }
else if ( mDebug ) {
262 KMessageBox::error( 0,
263 i18n(
"Cannot insert content from file %1: %2" ).
264 arg( path ).arg( file.errorString() ) );
267 }
else if ( cmd.startsWith(
"SYSTEM=" ) ) {
269 kdDebug() <<
"Command: SYSTEM=" << endl;
271 int len = parseQuotes(
"SYSTEM=", cmd, q );
273 TQString pipe_cmd = q;
274 TQString str = pipe( pipe_cmd,
"" );
277 }
else if ( cmd.startsWith(
"PUT=" ) ) {
279 kdDebug() <<
"Command: PUT=" << endl;
281 int len = parseQuotes(
"PUT=", cmd, q );
283 TQString path = KShell::tildeExpand( q );
284 TQFileInfo finfo( path );
285 if (finfo.isRelative() ) {
286 path = KShell::homeDir(
"" );
291 if ( file.open( IO_ReadOnly ) ) {
292 TQByteArray content = file.readAll();
293 body.append( TQString::fromLocal8Bit( content, content.size() ) );
294 }
else if ( mDebug ) {
295 KMessageBox::error( 0,
296 i18n(
"Cannot insert content from file %1: %2").
297 arg( path ).arg(file.errorString() ));
300 }
else if ( cmd.startsWith(
"QUOTEPIPE=" ) ) {
302 kdDebug() <<
"Command: QUOTEPIPE=" << endl;
304 int len = parseQuotes(
"QUOTEPIPE=", cmd, q );
306 TQString pipe_cmd = q;
308 TQString str = pipe( pipe_cmd,
messageText(
false ) );
311 body.append( quote );
314 }
else if ( cmd.startsWith(
"QUOTE" ) ) {
315 kdDebug() <<
"Command: QUOTE" << endl;
316 i += strlen(
"QUOTE" );
320 body.append( quote );
323 }
else if ( cmd.startsWith(
"QHEADERS" ) ) {
324 kdDebug() <<
"Command: TQHEADERS" << endl;
325 i += strlen(
"QHEADERS" );
330 body.append( quote );
333 }
else if ( cmd.startsWith(
"HEADERS" ) ) {
334 kdDebug() <<
"Command: HEADERS" << endl;
335 i += strlen(
"HEADERS" );
341 }
else if ( cmd.startsWith(
"TEXTPIPE=" ) ) {
343 kdDebug() <<
"Command: TEXTPIPE=" << endl;
345 int len = parseQuotes(
"TEXTPIPE=", cmd, q );
347 TQString pipe_cmd = q;
349 TQString str = pipe(pipe_cmd,
messageText(
false ) );
353 }
else if ( cmd.startsWith(
"MSGPIPE=" ) ) {
355 kdDebug() <<
"Command: MSGPIPE=" << endl;
357 int len = parseQuotes(
"MSGPIPE=", cmd, q );
359 TQString pipe_cmd = q;
361 TQString str = pipe(pipe_cmd, mOrigMsg->
asString() );
365 }
else if ( cmd.startsWith(
"BODYPIPE=" ) ) {
367 kdDebug() <<
"Command: BODYPIPE=" << endl;
369 int len = parseQuotes(
"BODYPIPE=", cmd, q );
371 TQString pipe_cmd = q;
372 TQString str = pipe( pipe_cmd, body );
375 }
else if ( cmd.startsWith(
"CLEARPIPE=" ) ) {
378 kdDebug() <<
"Command: CLEARPIPE=" << endl;
380 int len = parseQuotes(
"CLEARPIPE=", cmd, q );
382 TQString pipe_cmd = q;
383 TQString str = pipe( pipe_cmd, body );
387 }
else if ( cmd.startsWith(
"TEXT" ) ) {
388 kdDebug() <<
"Command: TEXT" << endl;
389 i += strlen(
"TEXT" );
392 body.append( quote );
395 }
else if ( cmd.startsWith(
"OTEXTSIZE" ) ) {
396 kdDebug() <<
"Command: OTEXTSIZE" << endl;
397 i += strlen(
"OTEXTSIZE" );
399 TQString str = TQString(
"%1" ).arg( mOrigMsg->
body().length() );
403 }
else if ( cmd.startsWith(
"OTEXT" ) ) {
404 kdDebug() <<
"Command: OTEXT" << endl;
405 i += strlen(
"OTEXT" );
408 body.append( quote );
411 }
else if ( cmd.startsWith(
"OADDRESSEESADDR" ) ) {
412 kdDebug() <<
"Command: OADDRESSEESADDR" << endl;
413 i += strlen(
"OADDRESSEESADDR" );
414 const TQString to = mOrigMsg->
to();
415 const TQString cc = mOrigMsg->
cc();
417 body.append( i18n(
"To:" ) +
' ' + to );
418 if ( !to.isEmpty() && !cc.isEmpty() )
421 body.append( i18n(
"CC:" ) +
' ' + cc );
423 }
else if ( cmd.startsWith(
"CCADDR" ) ) {
424 kdDebug() <<
"Command: CCADDR" << endl;
425 i += strlen(
"CCADDR" );
426 TQString str = mMsg->
cc();
429 }
else if ( cmd.startsWith(
"CCNAME" ) ) {
430 kdDebug() <<
"Command: CCNAME" << endl;
431 i += strlen(
"CCNAME" );
432 TQString str = mMsg->ccStrip();
435 }
else if ( cmd.startsWith(
"CCFNAME" ) ) {
436 kdDebug() <<
"Command: CCFNAME" << endl;
437 i += strlen(
"CCFNAME" );
438 TQString str = mMsg->ccStrip();
439 body.append( getFName( str ) );
441 }
else if ( cmd.startsWith(
"CCLNAME" ) ) {
442 kdDebug() <<
"Command: CCLNAME" << endl;
443 i += strlen(
"CCLNAME" );
444 TQString str = mMsg->ccStrip();
445 body.append( getLName( str ) );
447 }
else if ( cmd.startsWith(
"TOADDR" ) ) {
448 kdDebug() <<
"Command: TOADDR" << endl;
449 i += strlen(
"TOADDR" );
450 TQString str = mMsg->
to();
453 }
else if ( cmd.startsWith(
"TONAME" ) ) {
454 kdDebug() <<
"Command: TONAME" << endl;
455 i += strlen(
"TONAME" );
456 TQString str = mMsg->toStrip();
459 }
else if ( cmd.startsWith(
"TOFNAME" ) ) {
460 kdDebug() <<
"Command: TOFNAME" << endl;
461 i += strlen(
"TOFNAME" );
462 TQString str = mMsg->toStrip();
463 body.append( getFName( str ) );
465 }
else if ( cmd.startsWith(
"TOLNAME" ) ) {
466 kdDebug() <<
"Command: TOLNAME" << endl;
467 i += strlen(
"TOLNAME" );
468 TQString str = mMsg->toStrip();
469 body.append( getLName( str ) );
471 }
else if ( cmd.startsWith(
"TOLIST" ) ) {
472 kdDebug() <<
"Command: TOLIST" << endl;
473 i += strlen(
"TOLIST" );
474 TQString str = mMsg->
to();
477 }
else if ( cmd.startsWith(
"FROMADDR" ) ) {
478 kdDebug() <<
"Command: FROMADDR" << endl;
479 i += strlen(
"FROMADDR" );
480 TQString str = mMsg->
from();
483 }
else if ( cmd.startsWith(
"FROMNAME" ) ) {
484 kdDebug() <<
"Command: FROMNAME" << endl;
485 i += strlen(
"FROMNAME" );
486 TQString str = mMsg->fromStrip();
489 }
else if ( cmd.startsWith(
"FROMFNAME" ) ) {
490 kdDebug() <<
"Command: FROMFNAME" << endl;
491 i += strlen(
"FROMFNAME" );
492 TQString str = mMsg->fromStrip();
493 body.append( getFName( str ) );
495 }
else if ( cmd.startsWith(
"FROMLNAME" ) ) {
496 kdDebug() <<
"Command: FROMLNAME" << endl;
497 i += strlen(
"FROMLNAME" );
498 TQString str = mMsg->fromStrip();
499 body.append( getLName( str ) );
501 }
else if ( cmd.startsWith(
"FULLSUBJECT" ) ) {
502 kdDebug() <<
"Command: FULLSUBJECT" << endl;
503 i += strlen(
"FULLSUBJECT" );
504 TQString str = mMsg->
subject();
507 }
else if ( cmd.startsWith(
"FULLSUBJ" ) ) {
508 kdDebug() <<
"Command: FULLSUBJ" << endl;
509 i += strlen(
"FULLSUBJ" );
510 TQString str = mMsg->
subject();
513 }
else if ( cmd.startsWith(
"MSGID" ) ) {
514 kdDebug() <<
"Command: MSGID" << endl;
515 i += strlen(
"MSGID" );
516 TQString str = mMsg->
id();
519 }
else if ( cmd.startsWith(
"OHEADER=" ) ) {
521 kdDebug() <<
"Command: OHEADER=" << endl;
523 int len = parseQuotes(
"OHEADER=", cmd, q );
527 TQString str = mOrigMsg->
headerFields(hdr.local8Bit() ).join(
", " );
531 }
else if ( cmd.startsWith(
"HEADER=" ) ) {
533 kdDebug() <<
"Command: HEADER=" << endl;
535 int len = parseQuotes(
"HEADER=", cmd, q );
538 TQString str = mMsg->
headerFields(hdr.local8Bit() ).join(
", " );
541 }
else if ( cmd.startsWith(
"HEADER( " ) ) {
543 kdDebug() <<
"Command: HEADER( " << endl;
544 TQRegExp re = TQRegExp(
"^HEADER\\((.+)\\)" );
545 re.setMinimal(
true );
546 int res = re.search( cmd );
549 i += strlen(
"HEADER( " );
551 i += re.matchedLength();
552 TQString hdr = re.cap( 1 );
553 TQString str = mMsg->
headerFields( hdr.local8Bit() ).join(
", " );
557 }
else if ( cmd.startsWith(
"OCCADDR" ) ) {
558 kdDebug() <<
"Command: OCCADDR" << endl;
559 i += strlen(
"OCCADDR" );
561 TQString str = mOrigMsg->
cc();
565 }
else if ( cmd.startsWith(
"OCCNAME" ) ) {
566 kdDebug() <<
"Command: OCCNAME" << endl;
567 i += strlen(
"OCCNAME" );
569 TQString str = mOrigMsg->ccStrip();
573 }
else if ( cmd.startsWith(
"OCCFNAME" ) ) {
574 kdDebug() <<
"Command: OCCFNAME" << endl;
575 i += strlen(
"OCCFNAME" );
577 TQString str = mOrigMsg->ccStrip();
578 body.append( getFName( str ) );
581 }
else if ( cmd.startsWith(
"OCCLNAME" ) ) {
582 kdDebug() <<
"Command: OCCLNAME" << endl;
583 i += strlen(
"OCCLNAME" );
585 TQString str = mOrigMsg->ccStrip();
586 body.append( getLName( str ) );
589 }
else if ( cmd.startsWith(
"OTOADDR" ) ) {
590 kdDebug() <<
"Command: OTOADDR" << endl;
591 i += strlen(
"OTOADDR" );
593 TQString str = mOrigMsg->
to();
597 }
else if ( cmd.startsWith(
"OTONAME" ) ) {
598 kdDebug() <<
"Command: OTONAME" << endl;
599 i += strlen(
"OTONAME" );
601 TQString str = mOrigMsg->toStrip();
605 }
else if ( cmd.startsWith(
"OTOFNAME" ) ) {
606 kdDebug() <<
"Command: OTOFNAME" << endl;
607 i += strlen(
"OTOFNAME" );
609 TQString str = mOrigMsg->toStrip();
610 body.append( getFName( str ) );
613 }
else if ( cmd.startsWith(
"OTOLNAME" ) ) {
614 kdDebug() <<
"Command: OTOLNAME" << endl;
615 i += strlen(
"OTOLNAME" );
617 TQString str = mOrigMsg->toStrip();
618 body.append( getLName( str ) );
621 }
else if ( cmd.startsWith(
"OTOLIST" ) ) {
622 kdDebug() <<
"Command: OTOLIST" << endl;
623 i += strlen(
"OTOLIST" );
625 TQString str = mOrigMsg->
to();
629 }
else if ( cmd.startsWith(
"OTO" ) ) {
630 kdDebug() <<
"Command: OTO" << endl;
631 i += strlen(
"OTO" );
633 TQString str = mOrigMsg->
to();
637 }
else if ( cmd.startsWith(
"OFROMADDR" ) ) {
638 kdDebug() <<
"Command: OFROMADDR" << endl;
639 i += strlen(
"OFROMADDR" );
641 TQString str = mOrigMsg->
from();
645 }
else if ( cmd.startsWith(
"OFROMNAME" ) ) {
646 kdDebug() <<
"Command: OFROMNAME" << endl;
647 i += strlen(
"OFROMNAME" );
649 TQString str = mOrigMsg->fromStrip();
653 }
else if ( cmd.startsWith(
"OFROMFNAME" ) ) {
654 kdDebug() <<
"Command: OFROMFNAME" << endl;
655 i += strlen(
"OFROMFNAME" );
657 TQString str = mOrigMsg->fromStrip();
658 body.append( getFName( str ) );
661 }
else if ( cmd.startsWith(
"OFROMLNAME" ) ) {
662 kdDebug() <<
"Command: OFROMLNAME" << endl;
663 i += strlen(
"OFROMLNAME" );
665 TQString str = mOrigMsg->fromStrip();
666 body.append( getLName( str ) );
669 }
else if ( cmd.startsWith(
"OFULLSUBJECT" ) ) {
670 kdDebug() <<
"Command: OFULLSUBJECT" << endl;
671 i += strlen(
"OFULLSUBJECT" );
673 TQString str = mOrigMsg->
subject();
677 }
else if ( cmd.startsWith(
"OFULLSUBJ" ) ) {
678 kdDebug() <<
"Command: OFULLSUBJ" << endl;
679 i += strlen(
"OFULLSUBJ" );
681 TQString str = mOrigMsg->
subject();
685 }
else if ( cmd.startsWith(
"OMSGID" ) ) {
686 kdDebug() <<
"Command: OMSGID" << endl;
687 i += strlen(
"OMSGID" );
689 TQString str = mOrigMsg->
id();
693 }
else if ( cmd.startsWith(
"DATEEN" ) ) {
694 kdDebug() <<
"Command: DATEEN" << endl;
695 i += strlen(
"DATEEN" );
696 TQDateTime date = TQDateTime::currentDateTime();
697 TDELocale locale(
"C" );
698 TQString str = locale.formatDate( date.date(),
false );
701 }
else if ( cmd.startsWith(
"DATESHORT" ) ) {
702 kdDebug() <<
"Command: DATESHORT" << endl;
703 i += strlen(
"DATESHORT" );
704 TQDateTime date = TQDateTime::currentDateTime();
705 TQString str = TDEGlobal::locale()->formatDate( date.date(),
true );
708 }
else if ( cmd.startsWith(
"DATE" ) ) {
709 kdDebug() <<
"Command: DATE" << endl;
710 i += strlen(
"DATE" );
711 TQDateTime date = TQDateTime::currentDateTime();
712 TQString str = TDEGlobal::locale()->formatDate( date.date(),
false );
715 }
else if ( cmd.startsWith(
"DOW" ) ) {
716 kdDebug() <<
"Command: DOW" << endl;
717 i += strlen(
"DOW" );
718 TQDateTime date = TQDateTime::currentDateTime();
719 TQString str = TDEGlobal::locale()->calendar()->weekDayName( date.date(),
false );
722 }
else if ( cmd.startsWith(
"TIMELONGEN" ) ) {
723 kdDebug() <<
"Command: TIMELONGEN" << endl;
724 i += strlen(
"TIMELONGEN" );
725 TQDateTime date = TQDateTime::currentDateTime();
726 TDELocale locale(
"C");
727 TQString str = locale.formatTime( date.time(),
true );
730 }
else if ( cmd.startsWith(
"TIMELONG" ) ) {
731 kdDebug() <<
"Command: TIMELONG" << endl;
732 i += strlen(
"TIMELONG" );
733 TQDateTime date = TQDateTime::currentDateTime();
734 TQString str = TDEGlobal::locale()->formatTime( date.time(),
true );
737 }
else if ( cmd.startsWith(
"TIME" ) ) {
738 kdDebug() <<
"Command: TIME" << endl;
739 i += strlen(
"TIME" );
740 TQDateTime date = TQDateTime::currentDateTime();
741 TQString str = TDEGlobal::locale()->formatTime( date.time(),
false );
744 }
else if ( cmd.startsWith(
"ODATEEN" ) ) {
745 kdDebug() <<
"Command: ODATEEN" << endl;
746 i += strlen(
"ODATEEN" );
749 date.setTime_t( mOrigMsg->date() );
750 TDELocale locale(
"C");
751 TQString str = locale.formatDate( date.date(),
false );
755 }
else if ( cmd.startsWith(
"ODATESHORT") ) {
756 kdDebug() <<
"Command: ODATESHORT" << endl;
757 i += strlen(
"ODATESHORT");
760 date.setTime_t( mOrigMsg->date() );
761 TQString str = TDEGlobal::locale()->formatDate( date.date(),
true );
765 }
else if ( cmd.startsWith(
"ODATE") ) {
766 kdDebug() <<
"Command: ODATE" << endl;
767 i += strlen(
"ODATE");
770 date.setTime_t( mOrigMsg->date() );
771 TQString str = TDEGlobal::locale()->formatDate( date.date(),
false );
775 }
else if ( cmd.startsWith(
"ODOW") ) {
776 kdDebug() <<
"Command: ODOW" << endl;
777 i += strlen(
"ODOW");
780 date.setTime_t( mOrigMsg->date() );
781 TQString str = TDEGlobal::locale()->calendar()->weekDayName( date.date(),
false );
785 }
else if ( cmd.startsWith(
"OTIMELONGEN") ) {
786 kdDebug() <<
"Command: OTIMELONGEN" << endl;
787 i += strlen(
"OTIMELONGEN");
790 date.setTime_t( mOrigMsg->date() );
791 TDELocale locale(
"C");
792 TQString str = locale.formatTime( date.time(),
true );
796 }
else if ( cmd.startsWith(
"OTIMELONG") ) {
797 kdDebug() <<
"Command: OTIMELONG" << endl;
798 i += strlen(
"OTIMELONG");
801 date.setTime_t( mOrigMsg->date() );
802 TQString str = TDEGlobal::locale()->formatTime( date.time(),
true );
806 }
else if ( cmd.startsWith(
"OTIME") ) {
807 kdDebug() <<
"Command: OTIME" << endl;
808 i += strlen(
"OTIME");
811 date.setTime_t( mOrigMsg->date() );
812 TQString str = TDEGlobal::locale()->formatTime( date.time(),
false );
816 }
else if ( cmd.startsWith(
"BLANK" ) ) {
818 kdDebug() <<
"Command: BLANK" << endl;
819 i += strlen(
"BLANK" );
821 }
else if ( cmd.startsWith(
"NOP" ) ) {
823 kdDebug() <<
"Command: NOP" << endl;
824 i += strlen(
"NOP" );
826 }
else if ( cmd.startsWith(
"CLEAR" ) ) {
828 kdDebug() <<
"Command: CLEAR" << endl;
829 i += strlen(
"CLEAR" );
833 }
else if ( cmd.startsWith(
"DEBUGOFF" ) ) {
835 kdDebug() <<
"Command: DEBUGOFF" << endl;
836 i += strlen(
"DEBUGOFF" );
839 }
else if ( cmd.startsWith(
"DEBUG" ) ) {
841 kdDebug() <<
"Command: DEBUG" << endl;
842 i += strlen(
"DEBUG" );
845 }
else if ( cmd.startsWith(
"CURSOR" ) ) {
847 kdDebug() <<
"Command: CURSOR" << endl;
848 i += strlen(
"CURSOR" );
856 }
else if ( dnl && ( c ==
'\n' || c ==
'\r') ) {
858 if ( ( c ==
'\n' && tmpl[i + 1] ==
'\r' ) ||
859 ( c ==
'\r' && tmpl[i + 1] ==
'\n' ) ) {
874 if ( !mSelection.isEmpty() && allowSelectionOnly )
887 mOrigRoot = partNode::fromMessage( mOrigMsg );
888 ObjectTreeParser otp;
889 otp.parseObjectTree( mOrigRoot );
898 TQCString msg_body = mMsg->
body();
899 msg_body.append( body.utf8() );
906 AttachmentCollector ac;
907 ac.collectAttachmentsFrom( root );
914 if ( mMode == Forward ) {
915 if ( !mTo.isEmpty() ) {
916 mMsg->setTo( mMsg->
to() +
',' + mTo );
918 if ( !mCC.isEmpty() )
919 mMsg->setCc( mMsg->
cc() +
',' + mCC );
924 if ( ac.attachments().empty() || mMode != Forward ) {
925 mMsg->
headers().ContentType().FromString( DwString() );
926 mMsg->
headers().ContentType().Parse();
927 mMsg->
headers().ContentType().SetType( DwMime::kTypeText );
928 mMsg->
headers().ContentType().SetSubtype( DwMime::kSubtypePlain );
938 mMsg->
headers().ContentType().SetType( DwMime::kTypeMultipart );
939 mMsg->
headers().ContentType().SetSubtype( DwMime::kSubtypeMixed );
940 mMsg->
headers().ContentType().CreateBoundary( 0 );
942 KMMessagePart textPart;
943 textPart.setBodyFromUnicode( body );
947 int attachmentNumber = 1;
948 for ( std::vector<partNode*>::const_iterator it = ac.attachments().begin();
949 it != ac.attachments().end(); ++it, attachmentNumber++ ) {
955 ( *it )->dwPart()->SetNext( 0 );
957 DwBodyPart *cloned =
static_cast<DwBodyPart*
>( ( *it )->dwPart()->Clone() );
961 if ( cloned->Headers().HasContentType() ) {
962 DwMediaType &ct = cloned->Headers().ContentType();
965 TQString ctStr = ct.AsString().c_str();
966 if ( !ctStr.lower().contains(
"name=" ) && !ctStr.lower().contains(
"filename=" ) ) {
967 DwParameter *nameParameter =
new DwParameter;
968 nameParameter->SetAttribute(
"name" );
969 nameParameter->SetValue( Util::dwString( KMMsgBase::encodeRFC2231StringAutoDetectCharset(
970 i18n(
"Attachment %1" ).arg( attachmentNumber ) ) ) );
971 ct.AddParameter( nameParameter );
984 CTemplates t( tmplName );
987 TQString content = t.content();
988 if ( !content.isEmpty() ) {
998 if ( !GlobalSettings::self()->phrasesConverted() ) {
999 TemplatesConfiguration::importFromPhrases();
1007 mFolder = mMsg->parent();
1010 mFolder = mOrigMsg->parent();
1013 kdDebug(5006) <<
"Oops! No folder for message" << endl;
1017 kdDebug(5006) <<
"Folder found: " << mFolder << endl;
1021 TQString fid = mFolder->
idString();
1022 Templates fconf( fid );
1023 if ( fconf.useCustomTemplates() ) {
1026 tmpl = fconf.templateNewMessage();
1029 tmpl = fconf.templateReply();
1032 tmpl = fconf.templateReplyAll();
1035 tmpl = fconf.templateForward();
1038 kdDebug(5006) <<
"Unknown message mode: " << mMode << endl;
1041 mQuoteString = fconf.quoteString();
1042 if ( !tmpl.isEmpty() ) {
1050 if ( !mIdentity && mOrigMsg ) {
1053 mIdentity = kmkernel->identityManager()->identityForUoidOrDefault( mIdentity ).uoid();
1055 kdDebug(5006) <<
"Oops! No identity for message" << endl;
1058 kdDebug(5006) <<
"Identity found: " << mIdentity << endl;
1062 iid = TQString(
"IDENTITY_%1").arg( mIdentity );
1065 iid =
"IDENTITY_NO_IDENTITY";
1068 Templates iconf( iid );
1069 if ( iconf.useCustomTemplates() ) {
1072 tmpl = iconf.templateNewMessage();
1075 tmpl = iconf.templateReply();
1078 tmpl = iconf.templateReplyAll();
1081 tmpl = iconf.templateForward();
1084 kdDebug(5006) <<
"Unknown message mode: " << mMode << endl;
1087 mQuoteString = iconf.quoteString();
1088 if ( !tmpl.isEmpty() ) {
1095 tmpl = GlobalSettings::self()->templateNewMessage();
1098 tmpl = GlobalSettings::self()->templateReply();
1101 tmpl = GlobalSettings::self()->templateReplyAll();
1104 tmpl = GlobalSettings::self()->templateForward();
1107 kdDebug(5006) <<
"Unknown message mode: " << mMode << endl;
1111 mQuoteString = GlobalSettings::self()->quoteString();
1115 TQString TemplateParser::pipe(
const TQString &cmd,
const TQString &buf )
1122 TQCString data = buf.local8Bit();
1126 proc << KShell::splitArgs( cmd, KShell::TildeExpand );
1127 proc.setUseShell(
true );
1128 connect( &proc, TQ_SIGNAL( receivedStdout( TDEProcess *,
char *,
int ) ),
1129 this, TQ_SLOT( onReceivedStdout( TDEProcess *,
char *,
int ) ) );
1130 connect( &proc, TQ_SIGNAL( receivedStderr( TDEProcess *,
char *,
int ) ),
1131 this, TQ_SLOT( onReceivedStderr( TDEProcess *,
char *,
int ) ) );
1132 connect( &proc, TQ_SIGNAL( wroteStdin( TDEProcess * ) ),
1133 this, TQ_SLOT( onWroteStdin( TDEProcess * ) ) );
1135 if ( proc.start( TDEProcess::NotifyOnExit, TDEProcess::All ) ) {
1137 bool pipe_filled = proc.writeStdin( data, data.length() );
1138 if ( pipe_filled ) {
1141 bool exited = proc.wait( PipeTimeout );
1144 if ( proc.normalExit() ) {
1146 mPipeRc = proc.exitStatus();
1147 if ( mPipeRc != 0 && mDebug ) {
1148 if ( mPipeErr.isEmpty() ) {
1149 KMessageBox::error( 0,
1150 i18n(
"Pipe command exit with status %1: %2").
1151 arg( mPipeRc ).arg( cmd ) );
1153 KMessageBox::detailedError( 0,
1154 i18n(
"Pipe command exit with status %1: %2" ).
1155 arg( mPipeRc ).arg( cmd ), mPipeErr );
1161 mPipeRc = -( proc.exitSignal() );
1162 if ( mPipeRc != 0 && mDebug ) {
1163 if ( mPipeErr.isEmpty() ) {
1164 KMessageBox::error( 0,
1165 i18n(
"Pipe command killed by signal %1: %2" ).
1166 arg( -(mPipeRc) ).arg( cmd ) );
1168 KMessageBox::detailedError( 0,
1169 i18n(
"Pipe command killed by signal %1: %2" ).
1170 arg( -(mPipeRc) ).arg( cmd ), mPipeErr );
1180 KMessageBox::error( 0,
1181 i18n(
"Pipe command did not finish within %1 seconds: %2" ).
1182 arg( PipeTimeout ).arg( cmd ) );
1191 if ( mPipeErr.isEmpty() ) {
1192 KMessageBox::error( 0,
1193 i18n(
"Cannot write to process stdin: %1" ).arg( cmd ) );
1195 KMessageBox::detailedError( 0,
1196 i18n(
"Cannot write to process stdin: %1" ).
1197 arg( cmd ), mPipeErr );
1202 }
else if ( mDebug ) {
1203 KMessageBox::error( 0,
1204 i18n(
"Cannot start pipe command from template: %1" ).
1211 void TemplateParser::onProcessExited( TDEProcess *proc )
1217 void TemplateParser::onReceivedStdout( TDEProcess *proc,
char *buffer,
int buflen )
1220 mPipeOut += TQString::fromLocal8Bit( buffer, buflen );
1223 void TemplateParser::onReceivedStderr( TDEProcess *proc,
char *buffer,
int buflen )
1226 mPipeErr += TQString::fromLocal8Bit( buffer, buflen );
1229 void TemplateParser::onWroteStdin( TDEProcess *proc )
1234 #include "templateparser.moc"
TQString idString() const
Returns a string that can be used to identify this folder.
uint identityUoid() const
void setBody(const TQCString &aStr)
Set the message body.
void setBodyFromUnicode(const TQString &str, DwEntity *entity=0)
Sets this body's content to str.
TQCString body() const
Get the message body.
TQString from() const
Get or set the 'From' header field.
TQString asQuotedString(const TQString &headerStr, const TQString &indentStr, const TQString &selection=TQString(), bool aStripSignature=true, bool allowDecryption=true) const
Returns message body with quoting header and indented by the given indentation string.
TQString to() const
Get or set the 'To' header field.
TQString subject() const
Get or set the 'Subject' header field.
TQCString headerAsSendableString() const
Return the message header with the headers that should not be sent stripped off.
void addDwBodyPart(DwBodyPart *aDwPart)
Append a DwBodyPart to the message.
TQStringList headerFields(const TQCString &name) const
Returns a list of the values of all header fields with the given name.
TQString asPlainTextFromObjectTree(partNode *root, bool stripSignature, bool allowDecryption) const
Same as asPlainText(), only that this method expects an already parsed object tree as paramter.
TQCString asString() const
Return the entire message contents as a string.
TQString cc() const
Get or set the 'Cc' header field.
TQCString id() const
Returns the message ID, useful for followups.
DwHeaders & headers() const
get the DwHeaders (make sure to call setNeedsAssembly() function after directly modyfying internal da...
void assembleIfNeeded()
Assemble the internal message.
void deleteBodyParts()
Delete all body parts.
DwBodyPart * createDWBodyPart(const KMMessagePart *aPart)
Compose a DwBodyPart (needed for adding a part to the message).
void setCursorPos(int pos)
Set cursor position as offset from message start.
void setAllowDecryption(const bool allowDecryption)
Sets whether the template parser is allowed to decrypt the original message when needing its message ...
virtual TQString findCustomTemplate(const TQString &tmpl)
Finds the template with the given name.
void setSelection(const TQString &selection)
Sets the selection.
bool shouldStripSignature() const
Determines whether the signature should be stripped when getting the text of the original message,...
virtual TQString findTemplate()
This finds the template to use.
partNode * parsedObjectTree()
Returns the parsed object tree of the original message.
TQString messageText(bool allowSelectionOnly)
If there was a text selection set in the constructor, that will be returned.
void addProcessedBodyToMessage(const TQString &body)
Called by processWithTemplate().
void append(TQByteArray &that, const TQByteArray &str)
Append a bytearray to a bytearray.