diff --git a/templateparser.cpp b/templateparser.cpp index 17fffe1f0..52b539328 100644 --- a/templateparser.cpp +++ b/templateparser.cpp @@ -846,6 +846,11 @@ void TemplateParser::processWithTemplate( const QString &tmpl ) i += strlen( "CURSOR" ); mMsg->setCursorPos( body.length() ); + } else if ( cmd.startsWith( QLatin1String( "SIGNATURE" ) ) ) { + kDebug() << "Command: SIGNATURE"; + i += strlen( "SIGNATURE" ); + body.append( getSignature() ); + } else { // wrong command, do nothing body.append( c ); @@ -868,6 +873,25 @@ void TemplateParser::processWithTemplate( const QString &tmpl ) addProcessedBodyToMessage( body ); } +QString TemplateParser::getSignature() const +{ + const KPIMIdentities::Identity &identity = + kmkernel->identityManager()->identityForUoid( mIdentity ); + if ( identity.isNull() ) + return QString(); + + KPIMIdentities::Signature signature = const_cast + ( identity ).signature(); + if ( signature.type() == KPIMIdentities::Signature::Inlined && + signature.isInlinedHtml() ) { + // templates don't support HTML; convert to plain text + return signature.plainText(); + } + else { + return signature.rawText(); + } +} + void TemplateParser::addProcessedBodyToMessage( const QString &body ) { diff --git a/templateparser.h b/templateparser.h index f378e1c7c..81f6f31f3 100644 --- a/templateparser.h +++ b/templateparser.h @@ -96,6 +96,12 @@ class TemplateParser : public QObject int parseQuotes( const QString &prefix, const QString &str, QString "e ) const; + + private: + /** + * Return the text signature used the by current identity. + */ + QString getSignature() const; }; } // namespace KMail diff --git a/templatesinsertcommand.cpp b/templatesinsertcommand.cpp index 06d157eb7..5a9456ce2 100644 --- a/templatesinsertcommand.cpp +++ b/templatesinsertcommand.cpp @@ -112,6 +112,8 @@ static const int extCommandsCount = sizeof( extCommands ) / sizeof( *extCommands ); static const InsertCommand miscCommands[] = { + { I18N_NOOP2( "Inserts user signature, also known as footer, into message", "Signature" ), + TemplatesInsertCommand::CSignature }, { I18N_NOOP( "Insert File Content" ), TemplatesInsertCommand::CInsert }, { I18N_NOOP2( "All characters, up to and including the next newline, are discarded without performing any macro expansion", "Discard to Next Line" ), TemplatesInsertCommand::CDnl }, @@ -261,6 +263,7 @@ void TemplatesInsertCommand::slotMapped( int cmd ) case TemplatesInsertCommand::CBodyPipe: emit insertCommand("%BODYPIPE=\"\"", -1); break; case TemplatesInsertCommand::CClearPipe: emit insertCommand("%CLEARPIPE=\"\"", -1); break; case TemplatesInsertCommand::CCursor: emit insertCommand("%CURSOR"); break; + case TemplatesInsertCommand::CSignature: emit insertCommand( "%SIGNATURE" ); break; case TemplatesInsertCommand::CInsert: emit insertCommand("%INSERT=\"\"", -1); break; case TemplatesInsertCommand::CDnl: emit insertCommand("%-"); break; case TemplatesInsertCommand::CRem: emit insertCommand("%REM=\"\"", -1); break; diff --git a/templatesinsertcommand.h b/templatesinsertcommand.h index a2ee1d426..98900aecf 100644 --- a/templatesinsertcommand.h +++ b/templatesinsertcommand.h @@ -44,7 +44,7 @@ class TemplatesInsertCommand : public QPushButton CBlank, CNop, CClear, CDebug, CDebugOff, CToFName, CToLName, CFromFName, CFromLName, COToFName, COToLName, COFromFName, COFromLName, CCursor, CCCAddr, CCCName, CCCFName, CCCLName, COCCAddr, COCCName, COCCFName, COCCLName, - COAddresseesAddr }; + COAddresseesAddr, CSignature }; signals: void insertCommand( TemplatesInsertCommand::Command cmd );