Commit b03377f8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 89882 - Use custom header fields with kmail composer from command line

FIXED-IN: 4.11

BUG: 89882
parent 7edbd6fa
......@@ -81,6 +81,7 @@ class Composer : public KMail::SecondaryWindow
virtual void setCurrentTransport( int transportId ) = 0;
virtual void setCurrentReplyTo(const QString& replyTo) = 0;
virtual void setFcc( const QString &idString ) = 0;
/**
* Returns @c true while the message composing is in progress.
......@@ -100,6 +101,8 @@ class Composer : public KMail::SecondaryWindow
virtual void setAutoSaveFileName( const QString &fileName ) = 0;
virtual void setCollectionForNewMessage( const Akonadi::Collection& folder ) = 0;
virtual void addExtraCustomHeaders( const QMap<QByteArray, QString> &header) = 0;
public: // kmcommand
/**
* If this folder is set, the original message is inserted back after
......
......@@ -16,7 +16,6 @@ static KCmdLineOptions kmail_options ()
options.add("bcc <address>", ki18n("Send BCC: to 'address'"));
options.add("h");
options.add("header <header_name:header_value>", ki18n("Add 'header' to message. This can be repeated"));
options.add("in-reply-to <in reply to>", ki18n("Add in reply to value."));
options.add("msg <file>", ki18n("Read message body from 'file'"));
options.add("body <text>", ki18n("Set body of message"));
options.add("attach <url>", ki18n("Add an attachment to the mail. This can be repeated"));
......
......@@ -2775,6 +2775,13 @@ void KMComposeWin::doDelayedSend( MessageSender::SendMethod method, MessageSende
customMimeHeader.readConfig();
customHeader.insert(customMimeHeader.custHeaderName().toLatin1(), customMimeHeader.custHeaderValue() );
}
QMapIterator<QByteArray, QString> extraCustomHeader(mExtraHeaders);
while (extraCustomHeader.hasNext()) {
extraCustomHeader.next();
customHeader.insert(extraCustomHeader.key(), extraCustomHeader.value() );
}
mComposerBase->setCustomHeader( customHeader );
mComposerBase->send( method, saveIn );
}
......@@ -3448,3 +3455,8 @@ void KMComposeWin::slotVerifyMissingAttachmentTimeout()
}
}
void KMComposeWin::addExtraCustomHeaders( const QMap<QByteArray, QString> &headers)
{
mExtraHeaders = headers;
}
......@@ -232,6 +232,8 @@ class KMComposeWin : public KMail::Composer
void setCurrentReplyTo(const QString&);
void setCollectionForNewMessage( const Akonadi::Collection& folder);
void addExtraCustomHeaders( const QMap<QByteArray, QString> &header);
private:
/**
* Write settings to app's config file.
......@@ -666,6 +668,7 @@ class KMComposeWin : public KMail::Composer
bool mIgnoreStickyFields;
bool mWasModified;
Akonadi::Collection mCollectionForNewMessage;
QMap<QByteArray, QString> mExtraHeaders;
};
#endif
......@@ -638,26 +638,6 @@ int KMKernel::openComposer( const QString &to, const QString &cc,
parser.process( KMime::Message::Ptr() );
}
if ( !customHeaders.isEmpty() )
{
QStringList::ConstIterator end = customHeaders.constEnd();
for ( QStringList::ConstIterator it = customHeaders.constBegin() ; it != end ; ++it )
if ( !(*it).isEmpty() )
{
const int pos = (*it).indexOf( ':' );
if ( pos > 0 )
{
const QString header = (*it).left( pos ).trimmed();
const QString value = (*it).mid( pos+1 ).trimmed();
if ( !header.isEmpty() && !value.isEmpty() ) {
KMime::Headers::Generic *h = new KMime::Headers::Generic( header.toUtf8(), msg.get(), value.toUtf8() );
msg->setHeader( h );
}
}
}
}
msg->assemble();
KMail::Composer * cWin = KMail::makeComposer( msg, false, false, context );
if (!to.isEmpty())
......@@ -674,6 +654,25 @@ int KMKernel::openComposer( const QString &to, const QString &cc,
if (!inReplyTo.isEmpty()) {
cWin->setCurrentReplyTo(inReplyTo);
}
if (!customHeaders.isEmpty()) {
QMap<QByteArray, QString> extraCustomHeaders;
QStringList::ConstIterator end = customHeaders.constEnd();
for ( QStringList::ConstIterator it = customHeaders.constBegin() ; it != end ; ++it ) {
if ( !(*it).isEmpty() ) {
const int pos = (*it).indexOf( ':' );
if ( pos > 0 ) {
const QString header = (*it).left( pos ).trimmed();
const QString value = (*it).mid( pos+1 ).trimmed();
if ( !header.isEmpty() && !value.isEmpty() ) {
extraCustomHeaders.insert(header.toUtf8(), value.toUtf8());
}
}
}
}
if (!extraCustomHeaders.isEmpty())
cWin->addExtraCustomHeaders(extraCustomHeaders);
}
if ( !hidden ) {
cWin->show();
// Activate window - doing this instead of KWindowSystem::activateWindow(cWin->winId());
......
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