Extract other job

wilder-work
Montel Laurent 9 years ago
parent 98acec33e4
commit a97fd7275b
  1. 1
      src/CMakeLists.txt
  2. 87
      src/job/newmessagejob.cpp
  3. 77
      src/job/newmessagejob.h
  4. 6
      src/kmkernel.cpp

@ -131,6 +131,7 @@ set(kmailprivate_job_LIB_SRCS
job/handleclickedurljob.cpp
job/composenewmessagejob.cpp
job/opencomposerjob.cpp
job/newmessagejob.cpp
)
set(kmailprivate_widgets_LIB_SRCS

@ -0,0 +1,87 @@
/*
Copyright (C) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "newmessagejob.h"
#include "config-kmail.h"
#include "kmkernel.h"
#include "composer.h"
#include "editor/kmcomposerwin.h"
#include <KMime/Message>
#include <MessageComposer/MessageHelper>
//#ifdef KDEPIM_TEMPLATEPARSER_ASYNC_BUILD
//#include <TemplateParser/TemplateParserJob>
//#else
#include <TemplateParser/TemplateParser>
//#endif
NewMessageJob::NewMessageJob(QObject *parent)
: QObject(parent),
mMsg(nullptr)
{
}
NewMessageJob::~NewMessageJob()
{
}
void NewMessageJob::start()
{
QUrl attachURL = QUrl::fromLocalFile(mNewMessageJobSettings.mAttachURL);
mMsg = KMime::Message::Ptr(new KMime::Message);
MessageHelper::initHeader(mMsg, KMKernel::self()->identityManager(), mNewMessageJobSettings.mIdentity);
mMsg->contentType()->setCharset("utf-8");
//set basic headers
if (!mNewMessageJobSettings.mCc.isEmpty()) {
mMsg->cc()->fromUnicodeString(mNewMessageJobSettings.mCc, "utf-8");
}
if (!mNewMessageJobSettings.mBcc.isEmpty()) {
mMsg->bcc()->fromUnicodeString(mNewMessageJobSettings.mBcc, "utf-8");
}
if (!mNewMessageJobSettings.mTo.isEmpty()) {
mMsg->to()->fromUnicodeString(mNewMessageJobSettings.mTo, "utf-8");
}
mMsg->assemble();
TemplateParser::TemplateParser parser(mMsg, TemplateParser::TemplateParser::NewMessage);
parser.setIdentityManager(KMKernel::self()->identityManager());
Akonadi::Collection col = mNewMessageJobSettings.mFolder ? mNewMessageJobSettings.mFolder->collection() : Akonadi::Collection();
parser.process(mMsg, col);
KMail::Composer *win = makeComposer(mMsg, false, false, KMail::Composer::New, mNewMessageJobSettings.mIdentity);
win->setCollectionForNewMessage(col);
//Add the attachment if we have one
if (!attachURL.isEmpty() && attachURL.isValid()) {
win->addAttachment(attachURL, QString());
}
//only show window when required
if (!mNewMessageJobSettings.mHidden) {
win->show();
}
deleteLater();
}
void NewMessageJob::setNewMessageJobSettings(const NewMessageJobSettings &newMessageJobSettings)
{
mNewMessageJobSettings = newMessageJobSettings;
}

@ -0,0 +1,77 @@
/*
Copyright (C) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef NEWMESSAGEJOB_H
#define NEWMESSAGEJOB_H
#include <QObject>
#include <QSharedPointer>
#include <MailCommon/FolderCollection>
struct NewMessageJobSettings
{
NewMessageJobSettings()
: mFolder(nullptr),
mHidden(false),
mIdentity(0)
{
}
NewMessageJobSettings(const QString &to,
const QString &cc,
const QString &bcc,
bool hidden,
const QString &attachURL,
const QSharedPointer<MailCommon::FolderCollection> &folder,
uint identity)
: mTo(to),
mCc(cc),
mBcc(bcc),
mAttachURL(attachURL),
mFolder(folder),
mHidden(hidden),
mIdentity(identity)
{
}
QString mTo;
QString mCc;
QString mBcc;
QString mAttachURL;
QSharedPointer<MailCommon::FolderCollection> mFolder;
bool mHidden;
uint mIdentity;
};
class NewMessageJob : public QObject
{
Q_OBJECT
public:
explicit NewMessageJob(QObject *parent = nullptr);
~NewMessageJob();
void start();
void setNewMessageJobSettings(const NewMessageJobSettings &newMessageJobSettings);
private:
NewMessageJobSettings mNewMessageJobSettings;
KMime::Message::Ptr mMsg;
};
#endif // NEWMESSAGEJOB_H

@ -796,16 +796,16 @@ void KMKernel::newMessage(const QString &to,
const QString & /*messageFile*/,
const QString &_attachURL)
{
QUrl attachURL = QUrl::fromLocalFile(_attachURL);
KMime::Message::Ptr msg(new KMime::Message);
QSharedPointer<FolderCollection> folder;
uint id = 0;
if (useFolderId) {
//create message with required folder identity
folder = currentFolderCollection();
id = folder ? folder->identity() : 0;
}
QUrl attachURL = QUrl::fromLocalFile(_attachURL);
KMime::Message::Ptr msg(new KMime::Message);
MessageHelper::initHeader(msg, identityManager(), id);
msg->contentType()->setCharset("utf-8");
//set basic headers

Loading…
Cancel
Save