Commit 88c5386d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 308227 - Changing identities (that have different custom

template) in composer window doesn't take effect for the message body

FIXED-IN: 4.10
BUG: 308227
parent 45aa2c2c
......@@ -98,6 +98,7 @@ class Composer : public KMail::SecondaryWindow
virtual void setCustomTemplate( const QString& customTemplate ) = 0;
virtual void setAutoSaveFileName( const QString &fileName ) = 0;
virtual void setCollectionForNewMessage( const Akonadi::Collection& folder ) = 0;
public: // kmcommand
/**
......
......@@ -968,7 +968,7 @@ void KMComposeWin::rethinkHeaderLine( int aValue, int aMask, int &aRow,
}
//-----------------------------------------------------------------------------
void KMComposeWin::applyTemplate( uint uoid )
void KMComposeWin::applyTemplate( uint uoid, uint uOldId )
{
const KPIMIdentities::Identity &ident = kmkernel->identityManager()->identityForUoid( uoid );
if ( ident.isNull() )
......@@ -1000,10 +1000,11 @@ void KMComposeWin::applyTemplate( uint uoid )
parser.setAllowDecryption( MessageViewer::GlobalSettings::self()->automaticDecrypt() );
parser.setIdentityManager( KMKernel::self()->identityManager() );
if ( !mCustomTemplate.isEmpty() )
parser.process( mCustomTemplate, KMime::Message::Ptr() );
parser.process( mCustomTemplate, mMsg, mCollectionForNewMessage );
else
parser.processWithIdentity( uoid, KMime::Message::Ptr() );
parser.processWithIdentity( uoid, mMsg, mCollectionForNewMessage );
mComposerBase->updateTemplate( mMsg );
updateSignature(uoid, uOldId);
return;
}
......@@ -1018,6 +1019,7 @@ void KMComposeWin::applyTemplate( uint uoid )
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
job->setProperty( "mode", (int)mode );
job->setProperty( "uoid", uoid );
job->setProperty( "uOldid", uOldId );
connect( job, SIGNAL(result(KJob*)), SLOT(slotDelayedApplyTemplate(KJob*)) );
}
}
......@@ -1029,6 +1031,7 @@ void KMComposeWin::slotDelayedApplyTemplate( KJob *job )
const TemplateParser::TemplateParser::Mode mode = static_cast<TemplateParser::TemplateParser::Mode>( fetchJob->property( "mode" ).toInt() );
const uint uoid = fetchJob->property( "uoid" ).toUInt();
const uint uOldId = fetchJob->property( "uOldid" ).toUInt();
TemplateParser::TemplateParser parser( mMsg, mode );
parser.setSelection( mTextSelection );
......@@ -1041,7 +1044,21 @@ void KMComposeWin::slotDelayedApplyTemplate( KJob *job )
else
parser.processWithIdentity( uoid, MessageCore::Util::message( item ) );
}
mComposerBase->updateTemplate( mMsg );
updateSignature(uoid, uOldId);
}
void KMComposeWin::updateSignature(uint uoid, uint uOldId)
{
const KPIMIdentities::Identity &ident = kmkernel->identityManager()->identityForUoid( uoid );
const KPIMIdentities::Identity &oldIdentity = kmkernel->identityManager()->identityForUoid( uOldId );
mComposerBase->identityChanged( ident, oldIdentity, true );
}
void KMComposeWin::setCollectionForNewMessage( const Akonadi::Collection& folder)
{
mCollectionForNewMessage = folder;
}
void KMComposeWin::setQuotePrefix( uint uoid )
......@@ -3016,7 +3033,6 @@ void KMComposeWin::slotIdentityChanged( uint uoid, bool initalChange )
const KPIMIdentities::Identity &oldIdentity =
KMKernel::self()->identityManager()->identityForUoidOrDefault( mId );
mComposerBase->identityChanged( ident, oldIdentity );
if ( ident.organization().isEmpty() ) {
mMsg->organization()->clear();
......@@ -3064,7 +3080,9 @@ void KMComposeWin::slotIdentityChanged( uint uoid, bool initalChange )
// if unmodified, apply new template, if one is set
if ( !wasModified && !( ident.templates().isEmpty() && mCustomTemplate.isEmpty() ) &&
!initalChange ) {
applyTemplate( uoid );
applyTemplate( uoid, mId );
} else {
mComposerBase->identityChanged( ident, oldIdentity, false );
}
......
......@@ -233,6 +233,8 @@ class KMComposeWin : public KMail::Composer
bool insertFromMimeData( const QMimeData *source, bool forceAttachment = false );
void setCurrentReplyTo(const QString&);
void setCollectionForNewMessage( const Akonadi::Collection& folder);
private:
/**
* Write settings to app's config file.
......@@ -462,6 +464,7 @@ class KMComposeWin : public KMail::Composer
void ignoreStickyFields();
private:
void updateSignature(uint uoid, uint uOldId);
Kleo::CryptoMessageFormat cryptoMessageFormat() const;
QString overwriteModeStr() const;
void printComposeResult( KJob *job, bool preview );
......@@ -492,7 +495,7 @@ class KMComposeWin : public KMail::Composer
/**
* Apply template to new or unmodified message.
*/
void applyTemplate( uint uoid );
void applyTemplate(uint uoid , uint uOldId);
/**
* Set the quote prefix according to identity.
......@@ -675,7 +678,7 @@ class KMComposeWin : public KMail::Composer
bool mCheckForForgottenAttachments;
bool mIgnoreStickyFields;
bool mWasModified;
Akonadi::Collection mCollectionForNewMessage;
};
#endif
......@@ -854,10 +854,12 @@ QDBusObjectPath KMKernel::newMessage( const QString &to,
TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage );
parser.setIdentityManager( identityManager() );
parser.process( msg, folder ? folder->collection() : Akonadi::Collection() );
Akonadi::Collection col = folder ? folder->collection() : Akonadi::Collection();
parser.process( msg, col );
KMail::Composer *win = makeComposer( msg, false, false, KMail::Composer::New, id );
win->setCollectionForNewMessage(col);
//Add the attachment if we have one
if ( !attachURL.isEmpty() && attachURL.isValid() ) {
win->addAttachment( attachURL, "" );
......
......@@ -1531,6 +1531,7 @@ void KMMainWidget::slotCompose()
parser.setIdentityManager( KMKernel::self()->identityManager() );
parser.process( msg, mCurrentFolder->collection() );
win = KMail::makeComposer( msg, false, false, KMail::Composer::New, mCurrentFolder->identity() );
win->setCollectionForNewMessage( mCurrentFolder->collection() );
} else {
MessageHelper::initHeader( msg, KMKernel::self()->identityManager() );
TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage );
......
......@@ -151,6 +151,7 @@ void KMail::Util::handleClickedURL( const KUrl &url, const QSharedPointer<MailCo
KMail::Composer * win = KMail::makeComposer( msg, false, false, KMail::Composer::New, identity );
win->setFocusToSubject();
win->setCollectionForNewMessage( folder->collection() );
win->show();
} else {
kWarning() << "Can't handle URL:" << url;
......
......@@ -187,6 +187,31 @@ void Message::ComposerViewBase::setMessage ( const KMime::Message::Ptr& msg )
}
}
void Message::ComposerViewBase::updateTemplate ( const KMime::Message::Ptr& msg )
{
// First, we copy the message and then parse it to the object tree parser.
// The otp gets the message text out of it, in textualContent(), and also decrypts
// the message if necessary.
KMime::Content *msgContent = new KMime::Content;
msgContent->setContent( msg->encodedContent() );
msgContent->parse();
MessageViewer::EmptySource emptySource;
MessageViewer::ObjectTreeParser otp( &emptySource );//All default are ok
otp.parseObjectTree( msgContent );
// Set the HTML text and collect HTML images
if ( !otp.htmlContent().isEmpty() ) {
m_editor->setHtml( otp.htmlContent() );
emit enableHtml();
collectImages( msg.get() );
} else {
m_editor->setPlainText( otp.plainTextContent() );
}
if ( msg->headerByType( "X-KMail-CursorPos" ) ) {
m_editor->setCursorPositionFromStart( m_msg->headerByType( "X-KMail-CursorPos" )->asUnicodeString().toInt() );
}
}
void Message::ComposerViewBase::send ( MessageSender::SendMethod method, MessageSender::SaveIn saveIn )
{
mSendMethod = method;
......@@ -1276,7 +1301,7 @@ void Message::ComposerViewBase::updateRecipients( const KPIMIdentities::Identity
}
}
void Message::ComposerViewBase::identityChanged ( const KPIMIdentities::Identity &ident, const KPIMIdentities::Identity &oldIdent )
void Message::ComposerViewBase::identityChanged ( const KPIMIdentities::Identity &ident, const KPIMIdentities::Identity &oldIdent, bool msgCleared )
{
updateRecipients( ident, oldIdent, MessageComposer::Recipient::Bcc );
updateRecipients( ident, oldIdent, MessageComposer::Recipient::Cc );
......@@ -1285,12 +1310,10 @@ void Message::ComposerViewBase::identityChanged ( const KPIMIdentities::Identity
( oldIdent ).signature();
KPIMIdentities::Signature newSig = const_cast<KPIMIdentities::Identity&>
( ident ).signature();
//replace existing signatures
const bool replaced = editor()->replaceSignature( oldSig, newSig );
// Just append the signature if there was no old signature
if ( !replaced && (/* msgCleared ||*/ oldSig.rawText().isEmpty() ) ) {
if ( !replaced && ( msgCleared || oldSig.rawText().isEmpty() ) ) {
signatureController()->applySignature( newSig );
}
const QString vcardFileName = ident.vCardFile();
......
......@@ -94,6 +94,8 @@ public:
*/
void setMessage( const KMime::Message::Ptr& newMsg );
void updateTemplate ( const KMime::Message::Ptr& msg );
/**
* Send the message with the specified method, saving it in the specified folder.
*/
......@@ -211,7 +213,7 @@ public:
public slots:
void identityChanged( const KPIMIdentities::Identity &ident, const KPIMIdentities::Identity &oldIdent );
void identityChanged( const KPIMIdentities::Identity &ident, const KPIMIdentities::Identity &oldIdent, bool msgCleared = false);
/**
* Save the message.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment