diff --git a/messagecomposer/src/job/attachmentclipboardjob.cpp b/messagecomposer/src/job/attachmentclipboardjob.cpp index 7025e7ec..3fed484b 100644 --- a/messagecomposer/src/job/attachmentclipboardjob.cpp +++ b/messagecomposer/src/job/attachmentclipboardjob.cpp @@ -1,64 +1,65 @@ /* Copyright (c) 2015-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "attachmentclipboardjob.h" #include #include #include #include using namespace MessageComposer; AttachmentClipBoardJob::AttachmentClipBoardJob(QObject *parent) : MessageCore::AttachmentLoadJob(parent) { } AttachmentClipBoardJob::~AttachmentClipBoardJob() { } void AttachmentClipBoardJob::addAttachment(const QByteArray &data, const QString &attachmentName) { MessageCore::AttachmentPart::Ptr attachment = MessageCore::AttachmentPart::Ptr(new MessageCore::AttachmentPart()); if (!data.isEmpty()) { attachment->setName(attachmentName); attachment->setFileName(attachmentName); attachment->setData(data); attachment->setMimeType("text/plain"); // TODO what about the other fields? } setAttachmentPart(attachment); emitResult(); // Success. } void AttachmentClipBoardJob::doStart() { QClipboard *clip = QApplication::clipboard(); const QString clipText = clip->text(); if (clipText.isEmpty()) { setError(KJob::UserDefinedError); setErrorText(i18n("No text found in Clipboard")); emitResult(); } else { QString attachmentName = QInputDialog::getText(nullptr, i18n("Define Attachment Name"), i18n("Attachment Name:")); if (attachmentName.isEmpty()) { attachmentName = i18n("Clipboard Text"); } addAttachment(clipText.toUtf8(), attachmentName); } } diff --git a/messagecomposer/src/job/attachmentclipboardjob.h b/messagecomposer/src/job/attachmentclipboardjob.h index ffaee38e..5daa48c2 100644 --- a/messagecomposer/src/job/attachmentclipboardjob.h +++ b/messagecomposer/src/job/attachmentclipboardjob.h @@ -1,38 +1,39 @@ /* Copyright (c) 2015-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AttachmentClipBoardJob_H #define AttachmentClipBoardJob_H #include "MessageCore/AttachmentLoadJob" #include "messagecomposer_export.h" namespace MessageComposer { class MESSAGECOMPOSER_EXPORT AttachmentClipBoardJob : public MessageCore::AttachmentLoadJob { Q_OBJECT public: explicit AttachmentClipBoardJob(QObject *parent = nullptr); ~AttachmentClipBoardJob() override; protected Q_SLOTS: void doStart() override; private: void addAttachment(const QByteArray &data, const QString &attachmentName); }; } #endif // AttachmentClipBoardJob_H diff --git a/messagecomposer/src/job/attachmentvcardfromaddressbookjob.cpp b/messagecomposer/src/job/attachmentvcardfromaddressbookjob.cpp index 2a0435cc..6e20c344 100644 --- a/messagecomposer/src/job/attachmentvcardfromaddressbookjob.cpp +++ b/messagecomposer/src/job/attachmentvcardfromaddressbookjob.cpp @@ -1,119 +1,120 @@ /* Copyright (c) 2015-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "attachmentvcardfromaddressbookjob.h" #include #include #include #include #include using namespace MessageComposer; class MessageComposer::AttachmentVcardFromAddressBookJobPrivate { public: explicit AttachmentVcardFromAddressBookJobPrivate(const Akonadi::Item &item) : mItem(item) { } Akonadi::Item mItem; }; AttachmentVcardFromAddressBookJob::AttachmentVcardFromAddressBookJob(const Akonadi::Item &item, QObject *parent) : MessageCore::AttachmentLoadJob(parent) , d(new MessageComposer::AttachmentVcardFromAddressBookJobPrivate(item)) { } AttachmentVcardFromAddressBookJob::~AttachmentVcardFromAddressBookJob() { delete d; } void AttachmentVcardFromAddressBookJob::addAttachment(const QByteArray &data, const QString &attachmentName) { MessageCore::AttachmentPart::Ptr attachment = MessageCore::AttachmentPart::Ptr(new MessageCore::AttachmentPart()); if (!data.isEmpty()) { attachment->setName(attachmentName); attachment->setFileName(attachmentName); attachment->setData(data); attachment->setMimeType("text/x-vcard"); // TODO what about the other fields? } setAttachmentPart(attachment); emitResult(); // Success. } void AttachmentVcardFromAddressBookJob::doStart() { if (d->mItem.isValid()) { if (d->mItem.hasPayload()) { const KContacts::Addressee contact = d->mItem.payload(); if (contact.isEmpty()) { invalidContact(); } else { const QString contactRealName(contact.realName()); const QString attachmentName = (contactRealName.isEmpty() ? QStringLiteral("vcard") : contactRealName) + QLatin1String(".vcf"); QByteArray data = d->mItem.payloadData(); //Workaround about broken kaddressbook fields. KContacts::adaptIMAttributes(data); addAttachment(data, attachmentName); } } else if (d->mItem.hasPayload()) { const KContacts::ContactGroup group = d->mItem.payload(); const QString groupName(group.name()); const QString attachmentName = (groupName.isEmpty() ? QStringLiteral("vcard") : groupName) + QLatin1String(".vcf"); Akonadi::ContactGroupExpandJob *expandJob = new Akonadi::ContactGroupExpandJob(group, this); expandJob->setProperty("groupName", attachmentName); connect(expandJob, &KJob::result, this, &AttachmentVcardFromAddressBookJob::slotExpandGroupResult); expandJob->start(); } else { setError(KJob::UserDefinedError); setErrorText(i18n("Unknown Contact Type")); emitResult(); } } else { invalidContact(); } } void AttachmentVcardFromAddressBookJob::invalidContact() { setError(KJob::UserDefinedError); setErrorText(i18n("Invalid Contact")); emitResult(); } void AttachmentVcardFromAddressBookJob::slotExpandGroupResult(KJob *job) { Akonadi::ContactGroupExpandJob *expandJob = qobject_cast(job); Q_ASSERT(expandJob); const QString attachmentName = expandJob->property("groupName").toString(); KContacts::VCardConverter converter; const QByteArray groupData = converter.exportVCards(expandJob->contacts(), KContacts::VCardConverter::v3_0); if (!groupData.isEmpty()) { addAttachment(groupData, attachmentName); } else { setError(KJob::UserDefinedError); setErrorText(i18n("Impossible to generate vCard.")); emitResult(); } } diff --git a/messagecomposer/src/job/attachmentvcardfromaddressbookjob.h b/messagecomposer/src/job/attachmentvcardfromaddressbookjob.h index 77cdb38b..ecce7a6f 100644 --- a/messagecomposer/src/job/attachmentvcardfromaddressbookjob.h +++ b/messagecomposer/src/job/attachmentvcardfromaddressbookjob.h @@ -1,45 +1,46 @@ /* Copyright (c) 2015-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef ATTACHMENTVCARDFROMADDRESSBOOKJOB_H #define ATTACHMENTVCARDFROMADDRESSBOOKJOB_H #include "MessageCore/AttachmentLoadJob" #include #include "messagecomposer_export.h" namespace MessageComposer { class AttachmentVcardFromAddressBookJobPrivate; class MESSAGECOMPOSER_EXPORT AttachmentVcardFromAddressBookJob : public MessageCore::AttachmentLoadJob { Q_OBJECT public: explicit AttachmentVcardFromAddressBookJob(const Akonadi::Item &item, QObject *parent = nullptr); ~AttachmentVcardFromAddressBookJob() override; protected Q_SLOTS: void doStart() override; private Q_SLOTS: void slotExpandGroupResult(KJob *job); private: void invalidContact(); void addAttachment(const QByteArray &data, const QString &attachmentName); AttachmentVcardFromAddressBookJobPrivate *const d; }; } #endif // ATTACHMENTVCARDFROMADDRESSBOOKJOB_H diff --git a/messagecomposer/src/utils/kleo_util.h b/messagecomposer/src/utils/kleo_util.h index bfc84d3e..7ce02c0e 100644 --- a/messagecomposer/src/utils/kleo_util.h +++ b/messagecomposer/src/utils/kleo_util.h @@ -1,95 +1,96 @@ /* -*- c++ -*- kleo_util.h This file is part of KMail, the KDE mail client. Copyright (c) 2004 Marc Mutz KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef KDEPIM_KMAIL_KLEO_UTIL_H #define KDEPIM_KMAIL_KLEO_UTIL_H #include "libkleo/enum.h" static const Kleo::CryptoMessageFormat cryptoMessageFormats[] = { Kleo::AutoFormat, Kleo::InlineOpenPGPFormat, Kleo::OpenPGPMIMEFormat, Kleo::SMIMEFormat, Kleo::SMIMEOpaqueFormat }; static const int numCryptoMessageFormats = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats; static const Kleo::CryptoMessageFormat concreteCryptoMessageFormats[] = { Kleo::OpenPGPMIMEFormat, Kleo::SMIMEFormat, Kleo::SMIMEOpaqueFormat, Kleo::InlineOpenPGPFormat }; static const unsigned int numConcreteCryptoMessageFormats = sizeof concreteCryptoMessageFormats / sizeof *concreteCryptoMessageFormats; static inline Kleo::CryptoMessageFormat cb2format(int idx) { return cryptoMessageFormats[ idx >= 0 && idx < numCryptoMessageFormats ? idx : 0 ]; } static inline int format2cb(Kleo::CryptoMessageFormat f) { for (int i = 0; i < numCryptoMessageFormats; ++i) { if (f == cryptoMessageFormats[i]) { return i; } } return 0; } // // some helper functions indicating the need for CryptoMessageFormat // to be a class type :) // static inline bool isSMIME(Kleo::CryptoMessageFormat f) { return f == Kleo::SMIMEFormat || f == Kleo::SMIMEOpaqueFormat; } static inline bool isOpenPGP(Kleo::CryptoMessageFormat f) { return f == Kleo::InlineOpenPGPFormat || f == Kleo::OpenPGPMIMEFormat; } static inline bool containsSMIME(unsigned int f) { return f & (Kleo::SMIMEFormat | Kleo::SMIMEOpaqueFormat); } static inline bool containsOpenPGP(unsigned int f) { return f & (Kleo::OpenPGPMIMEFormat | Kleo::InlineOpenPGPFormat); } #endif // KDEPIM_KMAIL_KLEO_UTIL_H diff --git a/messagecore/src/misc/imagecollector.cpp b/messagecore/src/misc/imagecollector.cpp index 6d0708d4..4f325db5 100644 --- a/messagecore/src/misc/imagecollector.cpp +++ b/messagecore/src/misc/imagecollector.cpp @@ -1,105 +1,106 @@ /* -*- c++ -*- * imagecollector.cpp * * This file is part of KMail, the KDE mail client. * Copyright (c) 2004 Marc Mutz * Copyright (c) 2011 Torgny Nyblom * * KMail is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * KMail 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * In addition, as a special exception, the copyright holders give * permission to link the code of this program with any edition of * the Qt library by Trolltech AS, Norway (or with modified versions * of Qt that use the same license as Qt), and distribute linked * combinations including the two. You must obey the GNU General * Public License in all respects for all of the code used other than * Qt. If you modify this file, you may extend this exception to * your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from * your version. */ #include "imagecollector.h" #include "MessageCore/NodeHelper" #include "messagecore_debug.h" #include static bool isInExclusionList(KMime::Content *node) { if (!node) { return true; } if (node->contentType()->mediaType() != "image") { return true; } if (node->contentType()->isMultipart()) { return true; } return false; } class Q_DECL_HIDDEN MessageCore::ImageCollector::Private { public: std::vector mImages; }; MessageCore::ImageCollector::ImageCollector() : d(new Private) { } MessageCore::ImageCollector::~ImageCollector() { delete d; } void MessageCore::ImageCollector::collectImagesFrom(KMime::Content *node) { KMime::Content *parent = nullptr; while (node) { parent = node->parent(); if (node->topLevel()->textContent() == node) { node = MessageCore::NodeHelper::next(node); continue; } if (isInExclusionList(node)) { node = MessageCore::NodeHelper::next(node); continue; } if (parent && parent->contentType()->isMultipart() && parent->contentType()->subType() == "related") { qCWarning(MESSAGECORE_LOG) << "Adding image" << node->contentID(); d->mImages.push_back(node); node = MessageCore::NodeHelper::next(node); // skip embedded images continue; } node = MessageCore::NodeHelper::next(node); } } const std::vector &MessageCore::ImageCollector::images() const { return d->mImages; } diff --git a/messagecore/src/misc/imagecollector.h b/messagecore/src/misc/imagecollector.h index 90c31b6c..7a47f93a 100644 --- a/messagecore/src/misc/imagecollector.h +++ b/messagecore/src/misc/imagecollector.h @@ -1,88 +1,89 @@ /* -*- c++ -*- * imagecollector.h * * This file is part of KMail, the KDE mail client. * Copyright (c) 2004 Marc Mutz * Copyright (c) 2011 Torgny Nyblom * * KMail is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * KMail 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * In addition, as a special exception, the copyright holders give * permission to link the code of this program with any edition of * the Qt library by Trolltech AS, Norway (or with modified versions * of Qt that use the same license as Qt), and distribute linked * combinations including the two. You must obey the GNU General * Public License in all respects for all of the code used other than * Qt. If you modify this file, you may extend this exception to * your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from * your version. */ #ifndef MESSAGECORE_IMAGECOLLECTOR_H #define MESSAGECORE_IMAGECOLLECTOR_H #include "messagecore_export.h" #include #include namespace KMime { class Content; } namespace MessageCore { /** * @short A helper class to collect the embedded images of a email. * * @author Marc Mutz * @author Torgny Nyblom * @todo: Make it a simple static method?!? */ class MESSAGECORE_EXPORT ImageCollector { public: /** * Creates a new image collector. */ ImageCollector(); /** * Destroys the image collector. */ ~ImageCollector(); /** * Starts collecting the images. * * @param content The email content that contains the images. */ void collectImagesFrom(KMime::Content *content); /** * Returns the collected images. */ Q_REQUIRED_RESULT const std::vector &images() const; private: //@cond PRIVATE class Private; Private *const d; Q_DISABLE_COPY(ImageCollector) //@endcond }; } #endif diff --git a/messagelist/src/core/widgets/quicksearchwarning.cpp b/messagelist/src/core/widgets/quicksearchwarning.cpp index aa9dc219..06ec59dc 100644 --- a/messagelist/src/core/widgets/quicksearchwarning.cpp +++ b/messagelist/src/core/widgets/quicksearchwarning.cpp @@ -1,65 +1,66 @@ /* Copyright (c) 2015-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "quicksearchwarning.h" #include "messagelistsettings.h" #include #include using namespace MessageList::Core; QuickSearchWarning::QuickSearchWarning(QWidget *parent) : KMessageWidget(parent) { setVisible(false); setCloseButtonVisible(true); setMessageType(Warning); setWordWrap(true); setText(i18n("The words less than 3 letters are ignored.")); QAction *action = new QAction(i18n("Do not show again"), this); action->setObjectName(QStringLiteral("donotshowagain")); connect(action, &QAction::triggered, this, &QuickSearchWarning::slotDoNotRememberIt); addAction(action); } QuickSearchWarning::~QuickSearchWarning() { } void QuickSearchWarning::setSearchText(const QString &text) { if (!MessageList::MessageListSettings::quickSearchWarningDoNotShowAgain()) { const QStringList lstText = text.split(QLatin1Char(' '), QString::SkipEmptyParts); bool foundLessThanThreeCharacters = false; for (const QString &text : lstText) { if (text.trimmed().size() < 3) { foundLessThanThreeCharacters = true; break; } } if (foundLessThanThreeCharacters) { animatedShow(); } else { animatedHide(); } } } void QuickSearchWarning::slotDoNotRememberIt() { MessageList::MessageListSettings::setQuickSearchWarningDoNotShowAgain(true); animatedHide(); } diff --git a/messagelist/src/core/widgets/quicksearchwarning.h b/messagelist/src/core/widgets/quicksearchwarning.h index 97c15491..e46e6901 100644 --- a/messagelist/src/core/widgets/quicksearchwarning.h +++ b/messagelist/src/core/widgets/quicksearchwarning.h @@ -1,38 +1,39 @@ /* Copyright (c) 2015-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef QUICKSEARCHWARNING_H #define QUICKSEARCHWARNING_H #include #include "messagelist_private_export.h" namespace MessageList { namespace Core { class MESSAGELIST_TESTS_EXPORT QuickSearchWarning : public KMessageWidget { Q_OBJECT public: explicit QuickSearchWarning(QWidget *parent = nullptr); ~QuickSearchWarning(); void setSearchText(const QString &text); private Q_SLOTS: void slotDoNotRememberIt(); }; } } #endif // QUICKSEARCHWARNING_H diff --git a/messagelist/src/core/widgets/searchlinestatus.cpp b/messagelist/src/core/widgets/searchlinestatus.cpp index cffa8f11..f3b67214 100644 --- a/messagelist/src/core/widgets/searchlinestatus.cpp +++ b/messagelist/src/core/widgets/searchlinestatus.cpp @@ -1,370 +1,371 @@ /* Copyright (c) 2016-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "searchlinestatus.h" #include "messagelist_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include static const char qLineEditclearButtonActionNameC[] = "_q_qlineeditclearaction"; #define MAX_COMPLETION_ITEMS 20 using namespace MessageList::Core; SearchLineStatus::SearchLineStatus(QWidget *parent) : QLineEdit(parent) , mLocked(false) , mHasFilter(false) , mLockAction(nullptr) , mFiltersAction(nullptr) , mFilterMenu(nullptr) , mContainsOutboundMessages(false) { mCompleter = new QCompleter(this); mCompleterListModel = new QStringListModel(this); mCompleter->setModel(mCompleterListModel); setCompleter(mCompleter); setClearButtonEnabled(true); initializeActions(); createMenuSearch(); QAction *act = findChild(QLatin1String(qLineEditclearButtonActionNameC)); if (act) { connect(act, &QAction::triggered, this, &SearchLineStatus::slotClear); } else { qCWarning(MESSAGELIST_LOG) << "Clear button name was changed ! Please verify qt code"; } } SearchLineStatus::~SearchLineStatus() { } void SearchLineStatus::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { qDebug() << " void SearchLineStatus::keyPressEvent(QKeyEvent *e)" << mCompleter->widget(); if (mCompleter->popup()->isVisible()) { QLineEdit::keyPressEvent(e); } else { Q_EMIT forceLostFocus(); qDebug() << " void SearchLineStatus::keyPressEvent(QKeyEvent *e)ESCAPre"; } } else { QLineEdit::keyPressEvent(e); } } void SearchLineStatus::slotClear() { Q_EMIT clearButtonClicked(); } void SearchLineStatus::updateLockAction() { if (mLocked) { mLockAction->setIcon(QIcon::fromTheme(QStringLiteral("object-locked"))); mLockAction->setToolTip(i18nc("@info:tooltip", "Prevent the quick search field from being cleared when changing folders")); } else { mLockAction->setIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); mLockAction->setToolTip(i18nc("@info:tooltip", "Clear the quick search field when changing folders")); } } void SearchLineStatus::setLocked(bool b) { if (mLocked != b) { slotToggledLockAction(); } } bool SearchLineStatus::locked() const { return mLocked; } void SearchLineStatus::initializeActions() { mLockAction = addAction(QIcon::fromTheme(QStringLiteral("object-locked")), QLineEdit::TrailingPosition); mLockAction->setWhatsThis( i18nc("@info:whatsthis", "Toggle this button if you want to keep your quick search " "locked when moving to other folders or when narrowing the search " "by message status.")); connect(mLockAction, &QAction::triggered, this, &SearchLineStatus::slotToggledLockAction); updateLockAction(); const QStringList overlays = QStringList() << QStringLiteral("list-add"); mWithFilter = QIcon(new KIconEngine(QStringLiteral("view-filter"), KIconLoader::global(), overlays)); mWithoutFilter = QIcon::fromTheme(QStringLiteral("view-filter")); mFiltersAction = addAction(mWithoutFilter, QLineEdit::LeadingPosition); mFiltersAction->setToolTip(i18n("Filter Mails by Status")); connect(mFiltersAction, &QAction::triggered, this, &SearchLineStatus::showMenu); } void SearchLineStatus::slotToggledLockAction() { mLocked = !mLocked; updateLockAction(); } void SearchLineStatus::updateFilters() { QList lstStatus; for (QAction *act : qAsConst(mFilterListActions)) { if (act->isChecked()) { Akonadi::MessageStatus status; status.fromQInt32(static_cast< qint32 >(act->data().toInt())); lstStatus.append(status); } } mHasFilter = !lstStatus.isEmpty(); Q_EMIT filterActionChanged(lstStatus); updateFilterActionIcon(); } void SearchLineStatus::showMenu() { if (mFilterMenu->exec(mapToGlobal(QPoint(0, height())))) { updateFilters(); } } void SearchLineStatus::clearFilterAction() { for (QAction *act : qAsConst(mFilterListActions)) { act->setChecked(false); } mHasFilter = false; updateFilterActionIcon(); } void SearchLineStatus::createFilterAction(const QIcon &icon, const QString &text, int value) { QAction *act = new QAction(icon, text, this); act->setCheckable(true); act->setData(value); mFilterMenu->addAction(act); mFilterListActions.append(act); } void SearchLineStatus::updateFilterActionIcon() { mFiltersAction->setIcon(mHasFilter ? mWithFilter : mWithoutFilter); if (mColorName.isEmpty()) { const KColorScheme::BackgroundRole bgColorScheme(KColorScheme::PositiveBackground); KStatefulBrush bgBrush(KColorScheme::View, bgColorScheme); mColorName = bgBrush.brush(this).color().name(); } setStyleSheet(mHasFilter ? QStringLiteral("QLineEdit{ background-color:%1 }").arg(mColorName) : QString()); } void SearchLineStatus::clearFilterButtonClicked() { clearFilterAction(); clearFilterByAction(); updateFilters(); } void SearchLineStatus::createMenuSearch() { mFilterMenu = new QMenu(this); mFilterMenu->setObjectName(QStringLiteral("filtermenu")); QWidgetAction *clearWidgetAction = new QWidgetAction(mFilterMenu); QPushButton *clearFilterButton = new QPushButton(i18n("Clear Filter"), mFilterMenu); connect(clearFilterButton, &QPushButton::clicked, this, &SearchLineStatus::clearFilterButtonClicked); clearWidgetAction->setDefaultWidget(clearFilterButton); mFilterMenu->addAction(clearWidgetAction); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-unread")), i18nc("@action:inmenu Status of a message", "Unread"), Akonadi::MessageStatus::statusUnread().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-replied")), i18nc("@action:inmenu Status of a message", "Replied"), Akonadi::MessageStatus::statusReplied().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-forwarded")), i18nc("@action:inmenu Status of a message", "Forwarded"), Akonadi::MessageStatus::statusForwarded().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("emblem-important")), i18nc("@action:inmenu Status of a message", "Important"), Akonadi::MessageStatus::statusImportant().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-task")), i18nc("@action:inmenu Status of a message", "Action Item"), Akonadi::MessageStatus::statusToAct().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-thread-watch.png")), i18nc("@action:inmenu Status of a message", "Watched"), Akonadi::MessageStatus::statusWatched().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-thread-ignored.png")), i18nc("@action:inmenu Status of a message", "Ignored"), Akonadi::MessageStatus::statusIgnored().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-attachment")), i18nc("@action:inmenu Status of a message", "Has Attachment"), Akonadi::MessageStatus::statusHasAttachment().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-invitation")), i18nc("@action:inmenu Status of a message", "Has Invitation"), Akonadi::MessageStatus::statusHasInvitation().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-mark-junk")), i18nc("@action:inmenu Status of a message", "Spam"), Akonadi::MessageStatus::statusSpam().toQInt32()); createFilterAction(QIcon::fromTheme(QStringLiteral("mail-mark-notjunk")), i18nc("@action:inmenu Status of a message", "Ham"), Akonadi::MessageStatus::statusHam().toQInt32()); createFilterByAction(); } void SearchLineStatus::createFilterByAction() { mFilterMenu->addSeparator(); QActionGroup *grp = new QActionGroup(mFilterMenu); mSearchEveryWhereAction = new QAction(i18n("Full Message"), mFilterMenu); mSearchEveryWhereAction->setCheckable(true); mSearchEveryWhereAction->setChecked(true); mFilterMenu->addAction(mSearchEveryWhereAction); grp->addAction(mSearchEveryWhereAction); mSearchAgainstBodyAction = new QAction(i18n("Body"), mFilterMenu); grp->addAction(mSearchAgainstBodyAction); mFilterMenu->addAction(mSearchAgainstBodyAction); mSearchAgainstBodyAction->setCheckable(true); mSearchAgainstSubjectAction = new QAction(i18n("Subject"), mFilterMenu); grp->addAction(mSearchAgainstSubjectAction); mFilterMenu->addAction(mSearchAgainstSubjectAction); mSearchAgainstSubjectAction->setCheckable(true); mSearchAgainstFromOrToAction = new QAction(mFilterMenu); changeSearchAgainstFromOrToText(); grp->addAction(mSearchAgainstFromOrToAction); mFilterMenu->addAction(mSearchAgainstFromOrToAction); mSearchAgainstFromOrToAction->setCheckable(true); mSearchAgainstBccAction = new QAction(i18n("BCC"), mFilterMenu); grp->addAction(mSearchAgainstBccAction); mFilterMenu->addAction(mSearchAgainstBccAction); mSearchAgainstBccAction->setCheckable(true); connect(grp, &QActionGroup::triggered, this, &SearchLineStatus::slotFilterActionClicked); } void SearchLineStatus::clearFilterByAction() { mSearchEveryWhereAction->setChecked(true); } bool SearchLineStatus::containsOutboundMessages() const { return mContainsOutboundMessages; } void SearchLineStatus::setContainsOutboundMessages(bool containsOutboundMessages) { if (mContainsOutboundMessages != containsOutboundMessages) { mContainsOutboundMessages = containsOutboundMessages; changeSearchAgainstFromOrToText(); } } void SearchLineStatus::changeSearchAgainstFromOrToText() { if (mContainsOutboundMessages) { mSearchAgainstFromOrToAction->setText(i18n("To")); } else { mSearchAgainstFromOrToAction->setText(i18n("From")); } } QuickSearchLine::SearchOptions SearchLineStatus::searchOptions() const { QuickSearchLine::SearchOptions searchOptions; if (mSearchEveryWhereAction->isChecked()) { searchOptions |= QuickSearchLine::SearchEveryWhere; } if (mSearchAgainstBodyAction->isChecked()) { searchOptions |= QuickSearchLine::SearchAgainstBody; } if (mSearchAgainstSubjectAction->isChecked()) { searchOptions |= QuickSearchLine::SearchAgainstSubject; } if (mSearchAgainstFromOrToAction->isChecked()) { if (mContainsOutboundMessages) { searchOptions |= QuickSearchLine::SearchAgainstTo; } else { searchOptions |= QuickSearchLine::SearchAgainstFrom; } } if (mSearchAgainstBccAction->isChecked()) { searchOptions |= QuickSearchLine::SearchAgainstBcc; } return searchOptions; } void SearchLineStatus::slotFilterActionClicked(QAction *act) { Q_UNUSED(act); Q_EMIT searchOptionChanged(); } void SearchLineStatus::addCompletionItem(const QString &str) { mListCompetion.removeAll(str); mListCompetion.prepend(str); while (mListCompetion.size() > MAX_COMPLETION_ITEMS) { mListCompetion.removeLast(); } mCompleterListModel->setStringList(mListCompetion); } void SearchLineStatus::contextMenuEvent(QContextMenuEvent *e) { QMenu *popup = QLineEdit::createStandardContextMenu(); if (popup) { popup->addSeparator(); popup->addAction(QIcon::fromTheme(QStringLiteral("edit-clear-locationbar-rtl")), i18n("Clear History"), this, &SearchLineStatus::slotClearHistory); popup->exec(e->globalPos()); delete popup; } } void SearchLineStatus::slotClearHistory() { mListCompetion.clear(); mCompleterListModel->setStringList(mListCompetion); } diff --git a/messagelist/src/core/widgets/searchlinestatus.h b/messagelist/src/core/widgets/searchlinestatus.h index c66343f4..a3b39b4e 100644 --- a/messagelist/src/core/widgets/searchlinestatus.h +++ b/messagelist/src/core/widgets/searchlinestatus.h @@ -1,95 +1,96 @@ /* Copyright (c) 2016-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef SEARCHLINESTATUS_H #define SEARCHLINESTATUS_H #include #include #include "messagelist_private_export.h" #include "quicksearchline.h" #include class QStringListModel; class QAction; namespace MessageList { namespace Core { class MESSAGELIST_TESTS_EXPORT SearchLineStatus : public QLineEdit { Q_OBJECT public: explicit SearchLineStatus(QWidget *parent = nullptr); ~SearchLineStatus() override; void setLocked(bool b); Q_REQUIRED_RESULT bool locked() const; void setContainsOutboundMessages(bool containsOutboundMessages); Q_REQUIRED_RESULT bool containsOutboundMessages() const; Q_REQUIRED_RESULT QuickSearchLine::SearchOptions searchOptions() const; void addCompletionItem(const QString &str); void slotClearHistory(); void clearFilterButtonClicked(); Q_SIGNALS: void filterActionChanged(const QList &lst); void searchOptionChanged(); void clearButtonClicked(); void forceLostFocus(); protected: void contextMenuEvent(QContextMenuEvent *e) override; void keyPressEvent(QKeyEvent *e) override; private Q_SLOTS: void slotToggledLockAction(); void showMenu(); void slotFilterActionClicked(QAction *act); private: void clearFilterAction(); void createFilterAction(const QIcon &icon, const QString &text, int value); void createMenuSearch(); void updateLockAction(); void initializeActions(); void updateFilterActionIcon(); void updateFilters(); void createFilterByAction(); void clearFilterByAction(); void changeSearchAgainstFromOrToText(); void slotClear(); bool mLocked; bool mHasFilter; QIcon mWithoutFilter; QIcon mWithFilter; QAction *mLockAction = nullptr; QAction *mFiltersAction = nullptr; QMenu *mFilterMenu = nullptr; QCompleter *mCompleter = nullptr; QList mFilterListActions; QAction *mSearchEveryWhereAction; QAction *mSearchAgainstBodyAction; QAction *mSearchAgainstSubjectAction; QAction *mSearchAgainstFromOrToAction; QAction *mSearchAgainstBccAction; QStringListModel *mCompleterListModel; QStringList mListCompetion; QString mColorName; bool mContainsOutboundMessages; }; } } #endif // SEARCHLINESTATUS_H diff --git a/messagelist/src/messagelistutil.cpp b/messagelist/src/messagelistutil.cpp index 1d2be0eb..f4dab11f 100644 --- a/messagelist/src/messagelistutil.cpp +++ b/messagelist/src/messagelistutil.cpp @@ -1,175 +1,176 @@ /* This file is part of KMail, the KDE mail client. Copyright (c) 2011-2018 Montel Laurent KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "messagelistutil.h" #include "messagelistutil_p.h" #include "messagelistsettings.h" #include #include #include #include #include #include #include QString MessageList::Util::messageSortingConfigName() { return QStringLiteral("MessageSorting"); } QString MessageList::Util::messageSortDirectionConfigName() { return QStringLiteral("MessageSortDirection"); } QString MessageList::Util::groupSortingConfigName() { return QStringLiteral("GroupSorting"); } QString MessageList::Util::groupSortDirectionConfigName() { return QStringLiteral("GroupSortDirection"); } QString MessageList::Util::messageUniqueIdConfigName() { return QStringLiteral("MessageUniqueIdForStorageModel%1"); } QString MessageList::Util::storageModelSortOrderGroup() { return QStringLiteral("MessageListView::StorageModelSortOrder"); } QString MessageList::Util::storageModelThemesGroup() { return QStringLiteral("MessageListView::StorageModelThemes"); } QString MessageList::Util::storageModelAggregationsGroup() { return QStringLiteral("MessageListView::StorageModelAggregations"); } QString MessageList::Util::setForStorageModelConfigName() { return QStringLiteral("SetForStorageModel%1"); } QString MessageList::Util::storageModelSelectedMessageGroup() { return QStringLiteral("MessageListView::StorageModelSelectedMessages"); } void MessageList::Util::deleteConfig(const QString &collectionId) { KConfigGroup confselectedMessage(MessageListSettings::self()->config(), MessageList::Util::storageModelSelectedMessageGroup()); confselectedMessage.deleteEntry(MessageList::Util::messageUniqueIdConfigName().arg(collectionId)); KConfigGroup storageModelOrder(MessageListSettings::self()->config(), MessageList::Util::storageModelSortOrderGroup()); storageModelOrder.deleteEntry(collectionId + groupSortDirectionConfigName()); storageModelOrder.deleteEntry(collectionId + groupSortingConfigName()); storageModelOrder.deleteEntry(collectionId + messageSortDirectionConfigName()); storageModelOrder.deleteEntry(collectionId + messageSortingConfigName()); KConfigGroup storageModelTheme(MessageListSettings::self()->config(), MessageList::Util::storageModelThemesGroup()); storageModelTheme.deleteEntry(collectionId + setForStorageModelConfigName()); KConfigGroup storageModelAggregation(MessageListSettings::self()->config(), MessageList::Util::storageModelAggregationsGroup()); storageModelAggregation.deleteEntry(collectionId + setForStorageModelConfigName()); } QColor MessageList::Util::unreadDefaultMessageColor() { return KColorScheme(QPalette::Active, KColorScheme::Complementary).decoration(KColorScheme::FocusColor).color(); } QColor MessageList::Util::importantDefaultMessageColor() { return KColorScheme(QPalette::Active).foreground(KColorScheme::NegativeText).color(); } QColor MessageList::Util::todoDefaultMessageColor() { return KColorScheme(QPalette::Active).foreground(KColorScheme::PositiveText).color(); } void MessageList::Util::fillViewMenu(QMenu *menu, QObject *receiver) { QMenu *sortingMenu = new QMenu(i18n("Sorting"), menu); sortingMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sort-ascending"))); menu->addMenu(sortingMenu); QObject::connect(sortingMenu, SIGNAL(aboutToShow()), receiver, SLOT(sortOrderMenuAboutToShow())); QMenu *aggregationMenu = new QMenu(i18n("Aggregation"), menu); aggregationMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-process-tree"))); menu->addMenu(aggregationMenu); QObject::connect(aggregationMenu, SIGNAL(aboutToShow()), receiver, SLOT(aggregationMenuAboutToShow())); QMenu *themeMenu = new QMenu(i18n("Theme"), menu); themeMenu->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-theme"))); menu->addMenu(themeMenu); QObject::connect(themeMenu, SIGNAL(aboutToShow()), receiver, SLOT(themeMenuAboutToShow())); } QString MessageList::Util::contentSummary(const Akonadi::Item &item) { if (!item.hasPayload()) { return QString(); } KMime::Message::Ptr message = item.payload(); KMime::Content *textContent = message->textContent(); if (!textContent) { return QString(); } const QString content = textContent->decodedText(true, true); if (content.isEmpty()) { return QString(); } // Extract the first 5 non-empty, non-quoted lines from the content and return it int numLines = 0; const int maxLines = 5; const QStringList lines = content.split(QLatin1Char('\n')); if (lines.isEmpty()) { return QString(); } if (lines.count() == 1 && content.length() > 100) { return content.left(100); } QString ret; for (const QString &line : lines) { const QString lineTrimmed = line.trimmed(); const bool isQuoted = lineTrimmed.startsWith(QLatin1Char('>')) || lineTrimmed.startsWith(QLatin1Char('|')); if (!isQuoted && !lineTrimmed.isEmpty()) { ret += line + QLatin1Char('\n'); numLines++; if (numLines >= maxLines) { break; } } } return ret.toHtmlEscaped(); } diff --git a/messagelist/src/messagelistutil.h b/messagelist/src/messagelistutil.h index 106da16d..4b4016ab 100644 --- a/messagelist/src/messagelistutil.h +++ b/messagelist/src/messagelistutil.h @@ -1,40 +1,41 @@ /* This file is part of KMail, the KDE mail client. Copyright (c) 2011-2018 Montel Laurent KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MESSAGELISTUTIL_H #define MESSAGELISTUTIL_H #include #include #include namespace Akonadi { class Item; } namespace MessageList { namespace Util { MESSAGELIST_EXPORT void deleteConfig(const QString &collectionId); MESSAGELIST_EXPORT QColor unreadDefaultMessageColor(); MESSAGELIST_EXPORT QColor importantDefaultMessageColor(); MESSAGELIST_EXPORT QColor todoDefaultMessageColor(); /// Returns the first few lines of the actual email text if available. MESSAGELIST_EXPORT QString contentSummary(const Akonadi::Item &item); } } #endif /* MESSAGELISTUTIL_H */ diff --git a/messagelist/src/messagelistutil_p.h b/messagelist/src/messagelistutil_p.h index b0aa4597..21972898 100644 --- a/messagelist/src/messagelistutil_p.h +++ b/messagelist/src/messagelistutil_p.h @@ -1,43 +1,44 @@ /* This file is part of KMail, the KDE mail client. Copyright (c) 2011-2018 Montel Laurent KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MESSAGELISTUTIL_P_H #define MESSAGELISTUTIL_P_H #include #include class QMenu; namespace MessageList { namespace Util { QString messageSortingConfigName(); QString messageSortDirectionConfigName(); QString groupSortingConfigName(); QString groupSortDirectionConfigName(); QString messageUniqueIdConfigName(); QString storageModelSortOrderGroup(); QString storageModelThemesGroup(); QString storageModelAggregationsGroup(); QString setForStorageModelConfigName(); QString storageModelSelectedMessageGroup(); void fillViewMenu(QMenu *menu, QObject *receiver); } } #endif /* MESSAGELISTUTIL_H */ diff --git a/mimetreeparser/src/bodypartformatter.cpp b/mimetreeparser/src/bodypartformatter.cpp index de7f4bc1..728cbb40 100644 --- a/mimetreeparser/src/bodypartformatter.cpp +++ b/mimetreeparser/src/bodypartformatter.cpp @@ -1,176 +1,177 @@ /* -*- c++ -*- bodypartformatter.cpp This file is part of KMail, the KDE mail client. Copyright (c) 2003 Marc Mutz KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include "mimetreeparser_debug.h" #include "bodyformatter/applicationpgpencrypted.h" #include "bodyformatter/applicationpkcs7mime.h" #include "bodyformatter/encrypted.h" #include "bodyformatter/mailman.h" #include "bodyformatter/multipartalternative.h" #include "bodyformatter/multipartmixed.h" #include "bodyformatter/multipartencrypted.h" #include "bodyformatter/multipartsigned.h" #include "bodyformatter/texthtml.h" #include "bodyformatter/textplain.h" #include "interfaces/bodypartformatter.h" #include "interfaces/bodypart.h" #include "bodypartformatterfactory.h" #include "bodypartformatterfactory_p.h" #include "objecttreeparser.h" #include "messagepart.h" #include #include using namespace MimeTreeParser; namespace { class AnyTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter { static const AnyTypeBodyPartFormatter *self; public: MessagePart::Ptr process(Interface::BodyPart &part) const override { KMime::Content *node = part.content(); const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage())); part.processResult()->setInlineSignatureState(mp->signatureState()); part.processResult()->setInlineEncryptionState(mp->encryptionState()); part.processResult()->setNeverDisplayInline(true); mp->setNeverDisplayInline(true); mp->setIsImage(false); return mp; } static const MimeTreeParser::Interface::BodyPartFormatter *create() { if (!self) { self = new AnyTypeBodyPartFormatter(); } return self; } }; const AnyTypeBodyPartFormatter *AnyTypeBodyPartFormatter::self = nullptr; class ImageTypeBodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter { static const ImageTypeBodyPartFormatter *self; public: static const MimeTreeParser::Interface::BodyPartFormatter *create() { if (!self) { self = new ImageTypeBodyPartFormatter(); } return self; } MessagePart::Ptr process(Interface::BodyPart &part) const override { KMime::Content *node = part.content(); auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage())); mp->setIsImage(true); part.processResult()->setInlineSignatureState(mp->signatureState()); part.processResult()->setInlineEncryptionState(mp->encryptionState()); auto preferredMode = part.source()->preferredMode(); const bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); if (node->parent() && node->parent()->contentType()->subType() == "related" && isHtmlPreferred) { part.nodeHelper()->setNodeDisplayedEmbedded(node, true); part.nodeHelper()->setNodeDisplayedHidden(node, true); return mp; } return mp; } }; const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = nullptr; class MessageRfc822BodyPartFormatter : public MimeTreeParser::Interface::BodyPartFormatter { static const MessageRfc822BodyPartFormatter *self; public: MessagePart::Ptr process(Interface::BodyPart &) const override; static const MimeTreeParser::Interface::BodyPartFormatter *create(); }; const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self; const MimeTreeParser::Interface::BodyPartFormatter *MessageRfc822BodyPartFormatter::create() { if (!self) { self = new MessageRfc822BodyPartFormatter(); } return self; } MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const { const KMime::Message::Ptr message = part.content()->bodyAsMessage(); return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message)); } } // anon namespace void BodyPartFormatterFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() { insert(QStringLiteral("application/pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/x-pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/pgp-encrypted"), ApplicationPGPEncryptedBodyPartFormatter::create()); insert(QStringLiteral("application/octet-stream"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/octet-stream"), EncryptedBodyPartFormatter::create()); insert(QStringLiteral("application/octet-stream"), AnyTypeBodyPartFormatter::create()); insert(QStringLiteral("text/pgp"), EncryptedBodyPartFormatter::create()); insert(QStringLiteral("text/html"), TextHtmlBodyPartFormatter::create()); insert(QStringLiteral("text/rtf"), AnyTypeBodyPartFormatter::create()); insert(QStringLiteral("text/plain"), MailmanBodyPartFormatter::create()); insert(QStringLiteral("text/plain"), TextPlainBodyPartFormatter::create()); insert(QStringLiteral("image/png"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/jpeg"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/gif"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/svg+xml"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/bmp"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("image/vnd.microsoft.icon"), ImageTypeBodyPartFormatter::create()); insert(QStringLiteral("message/rfc822"), MessageRfc822BodyPartFormatter::create()); insert(QStringLiteral("multipart/alternative"), MultiPartAlternativeBodyPartFormatter::create()); insert(QStringLiteral("multipart/encrypted"), MultiPartEncryptedBodyPartFormatter::create()); insert(QStringLiteral("multipart/signed"), MultiPartSignedBodyPartFormatter::create()); insert(QStringLiteral("multipart/mixed"), MultiPartMixedBodyPartFormatter::create()); } diff --git a/mimetreeparser/src/memento/cryptobodypartmemento.cpp b/mimetreeparser/src/memento/cryptobodypartmemento.cpp index 1378e0ad..d3e24a14 100644 --- a/mimetreeparser/src/memento/cryptobodypartmemento.cpp +++ b/mimetreeparser/src/memento/cryptobodypartmemento.cpp @@ -1,53 +1,54 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "cryptobodypartmemento.h" using namespace GpgME; using namespace MimeTreeParser; CryptoBodyPartMemento::CryptoBodyPartMemento() : QObject(nullptr) , Interface::BodyPartMemento() , m_running(false) { } CryptoBodyPartMemento::~CryptoBodyPartMemento() { } bool CryptoBodyPartMemento::isRunning() const { return m_running; } void CryptoBodyPartMemento::setAuditLog(const Error &err, const QString &log) { m_auditLogError = err; m_auditLog = log; } void CryptoBodyPartMemento::setRunning(bool running) { m_running = running; } void CryptoBodyPartMemento::detach() { disconnect(this, SIGNAL(update(MimeTreeParser::UpdateMode)), nullptr, nullptr); } diff --git a/mimetreeparser/src/memento/cryptobodypartmemento.h b/mimetreeparser/src/memento/cryptobodypartmemento.h index 2416e787..47a74682 100644 --- a/mimetreeparser/src/memento/cryptobodypartmemento.h +++ b/mimetreeparser/src/memento/cryptobodypartmemento.h @@ -1,72 +1,73 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H #define MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H #include #include #include #include "interfaces/bodypart.h" #include "enums.h" namespace MimeTreeParser { class CryptoBodyPartMemento : public QObject, public Interface::BodyPartMemento { Q_OBJECT public: CryptoBodyPartMemento(); ~CryptoBodyPartMemento() override; virtual bool start() = 0; virtual void exec() = 0; bool isRunning() const; const QString &auditLogAsHtml() const { return m_auditLog; } GpgME::Error auditLogError() const { return m_auditLogError; } void detach() override; Q_SIGNALS: void update(MimeTreeParser::UpdateMode); protected Q_SLOTS: void notify() { Q_EMIT update(MimeTreeParser::Force); } protected: void setAuditLog(const GpgME::Error &err, const QString &log); void setRunning(bool running); private: bool m_running; QString m_auditLog; GpgME::Error m_auditLogError; }; } #endif // MIMETREEPARSER_CRYPTOBODYPARTMEMENTO_H diff --git a/mimetreeparser/src/memento/decryptverifybodypartmemento.cpp b/mimetreeparser/src/memento/decryptverifybodypartmemento.cpp index d0fa9901..b18ec299 100644 --- a/mimetreeparser/src/memento/decryptverifybodypartmemento.cpp +++ b/mimetreeparser/src/memento/decryptverifybodypartmemento.cpp @@ -1,82 +1,83 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "decryptverifybodypartmemento.h" #include #include using namespace QGpgME; using namespace GpgME; using namespace MimeTreeParser; DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento(DecryptVerifyJob *job, const QByteArray &cipherText) : CryptoBodyPartMemento() , m_cipherText(cipherText) , m_job(job) { Q_ASSERT(m_job); } DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() { if (m_job) { m_job->slotCancel(); } } bool DecryptVerifyBodyPartMemento::start() { Q_ASSERT(m_job); if (const Error err = m_job->start(m_cipherText)) { m_dr = DecryptionResult(err); return false; } connect(m_job.data(), &DecryptVerifyJob::result, this, &DecryptVerifyBodyPartMemento::slotResult); setRunning(true); return true; } void DecryptVerifyBodyPartMemento::exec() { Q_ASSERT(m_job); QByteArray plainText; setRunning(true); const std::pair p = m_job->exec(m_cipherText, plainText); saveResult(p.first, p.second, plainText); m_job->deleteLater(); // exec'ed jobs don't delete themselves m_job = nullptr; } void DecryptVerifyBodyPartMemento::saveResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plainText) { Q_ASSERT(m_job); setRunning(false); m_dr = dr; m_vr = vr; m_plainText = plainText; setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); } void DecryptVerifyBodyPartMemento::slotResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plainText) { saveResult(dr, vr, plainText); m_job = nullptr; notify(); } diff --git a/mimetreeparser/src/memento/decryptverifybodypartmemento.h b/mimetreeparser/src/memento/decryptverifybodypartmemento.h index d60dbc0a..0fa2b400 100644 --- a/mimetreeparser/src/memento/decryptverifybodypartmemento.h +++ b/mimetreeparser/src/memento/decryptverifybodypartmemento.h @@ -1,75 +1,76 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H #define MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H #include "cryptobodypartmemento.h" #include #include #include #include "interfaces/bodypart.h" namespace QGpgME { class DecryptVerifyJob; } namespace MimeTreeParser { class DecryptVerifyBodyPartMemento : public CryptoBodyPartMemento { Q_OBJECT public: DecryptVerifyBodyPartMemento(QGpgME::DecryptVerifyJob *job, const QByteArray &cipherText); ~DecryptVerifyBodyPartMemento() override; bool start() override; void exec() override; const QByteArray &plainText() const { return m_plainText; } const GpgME::DecryptionResult &decryptResult() const { return m_dr; } const GpgME::VerificationResult &verifyResult() const { return m_vr; } private Q_SLOTS: void slotResult(const GpgME::DecryptionResult &dr, const GpgME::VerificationResult &vr, const QByteArray &plainText); private: void saveResult(const GpgME::DecryptionResult &, const GpgME::VerificationResult &, const QByteArray &); private: // input: const QByteArray m_cipherText; QPointer m_job; // output: GpgME::DecryptionResult m_dr; GpgME::VerificationResult m_vr; QByteArray m_plainText; }; } #endif // MIMETREEPARSER_DECRYPTVERIFYBODYPARTMEMENTO_H diff --git a/mimetreeparser/src/memento/verifydetachedbodypartmemento.cpp b/mimetreeparser/src/memento/verifydetachedbodypartmemento.cpp index 3b78452a..e31a0b1b 100644 --- a/mimetreeparser/src/memento/verifydetachedbodypartmemento.cpp +++ b/mimetreeparser/src/memento/verifydetachedbodypartmemento.cpp @@ -1,174 +1,175 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "verifydetachedbodypartmemento.h" #include "mimetreeparser_debug.h" #include #include #include #include #include using namespace QGpgME; using namespace GpgME; using namespace MimeTreeParser; VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento(VerifyDetachedJob *job, KeyListJob *klj, const QByteArray &signature, const QByteArray &plainText) : CryptoBodyPartMemento() , m_signature(signature) , m_plainText(plainText) , m_job(job) , m_keylistjob(klj) { assert(m_job); } VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() { if (m_job) { m_job->slotCancel(); } if (m_keylistjob) { m_keylistjob->slotCancel(); } } bool VerifyDetachedBodyPartMemento::start() { assert(m_job); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento started"; #endif connect(m_job.data(), &VerifyDetachedJob::result, this, &VerifyDetachedBodyPartMemento::slotResult); if (const Error err = m_job->start(m_signature, m_plainText)) { m_vr = VerificationResult(err); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento stopped with error"; #endif return false; } setRunning(true); return true; } void VerifyDetachedBodyPartMemento::exec() { assert(m_job); setRunning(true); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento execed"; #endif saveResult(m_job->exec(m_signature, m_plainText)); m_job->deleteLater(); // exec'ed jobs don't delete themselves m_job = nullptr; #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento after execed"; #endif if (canStartKeyListJob()) { std::vector keys; m_keylistjob->exec(keyListPattern(), /*secretOnly=*/ false, keys); if (!keys.empty()) { m_key = keys.back(); } } if (m_keylistjob) { m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves } m_keylistjob = nullptr; setRunning(false); } bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const { if (!m_keylistjob) { return false; } const char *const fpr = m_vr.signature(0).fingerprint(); return fpr && *fpr; } QStringList VerifyDetachedBodyPartMemento::keyListPattern() const { assert(canStartKeyListJob()); return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); } void VerifyDetachedBodyPartMemento::saveResult(const VerificationResult &vr) { assert(m_job); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::saveResult called"; #endif m_vr = vr; setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); } void VerifyDetachedBodyPartMemento::slotResult(const VerificationResult &vr) { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotResult called"; #endif saveResult(vr); m_job = nullptr; if (canStartKeyListJob() && startKeyListJob()) { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento: canStartKeyListJob && startKeyListJob"; #endif return; } if (m_keylistjob) { m_keylistjob->deleteLater(); } m_keylistjob = nullptr; setRunning(false); notify(); } bool VerifyDetachedBodyPartMemento::startKeyListJob() { assert(canStartKeyListJob()); if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { return false; } connect(m_keylistjob.data(), &Job::done, this, &VerifyDetachedBodyPartMemento::slotKeyListJobDone); connect(m_keylistjob.data(), &KeyListJob::nextKey, this, &VerifyDetachedBodyPartMemento::slotNextKey); return true; } void VerifyDetachedBodyPartMemento::slotNextKey(const GpgME::Key &key) { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotNextKey called"; #endif m_key = key; } void VerifyDetachedBodyPartMemento::slotKeyListJobDone() { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotKeyListJobDone called"; #endif m_keylistjob = nullptr; setRunning(false); notify(); } diff --git a/mimetreeparser/src/memento/verifydetachedbodypartmemento.h b/mimetreeparser/src/memento/verifydetachedbodypartmemento.h index bce0b5cf..7c537fdc 100644 --- a/mimetreeparser/src/memento/verifydetachedbodypartmemento.h +++ b/mimetreeparser/src/memento/verifydetachedbodypartmemento.h @@ -1,80 +1,81 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H #define MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H #include "cryptobodypartmemento.h" #include #include #include #include #include "interfaces/bodypart.h" namespace QGpgME { class VerifyDetachedJob; class KeyListJob; } class QStringList; namespace MimeTreeParser { class VerifyDetachedBodyPartMemento : public CryptoBodyPartMemento { Q_OBJECT public: VerifyDetachedBodyPartMemento(QGpgME::VerifyDetachedJob *job, QGpgME::KeyListJob *klj, const QByteArray &signature, const QByteArray &plainText); ~VerifyDetachedBodyPartMemento() override; bool start() override; void exec() override; const GpgME::VerificationResult &verifyResult() const { return m_vr; } const GpgME::Key &signingKey() const { return m_key; } private Q_SLOTS: void slotResult(const GpgME::VerificationResult &vr); void slotKeyListJobDone(); void slotNextKey(const GpgME::Key &); private: void saveResult(const GpgME::VerificationResult &); bool canStartKeyListJob() const; QStringList keyListPattern() const; bool startKeyListJob(); private: // input: const QByteArray m_signature; const QByteArray m_plainText; QPointer m_job; QPointer m_keylistjob; // output: GpgME::VerificationResult m_vr; GpgME::Key m_key; }; } #endif // MIMETREEPARSER_VERIFYDETACHEDBODYPARTMEMENTO_H diff --git a/mimetreeparser/src/memento/verifyopaquebodypartmemento.cpp b/mimetreeparser/src/memento/verifyopaquebodypartmemento.cpp index 18494890..b9a8d84c 100644 --- a/mimetreeparser/src/memento/verifyopaquebodypartmemento.cpp +++ b/mimetreeparser/src/memento/verifyopaquebodypartmemento.cpp @@ -1,175 +1,176 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "verifyopaquebodypartmemento.h" #include "mimetreeparser_debug.h" #include #include #include #include #include using namespace QGpgME; using namespace GpgME; using namespace MimeTreeParser; VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento(VerifyOpaqueJob *job, KeyListJob *klj, const QByteArray &signature) : CryptoBodyPartMemento() , m_signature(signature) , m_job(job) , m_keylistjob(klj) { assert(m_job); } VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() { if (m_job) { m_job->slotCancel(); } if (m_keylistjob) { m_keylistjob->slotCancel(); } } bool VerifyOpaqueBodyPartMemento::start() { assert(m_job); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento started"; #endif if (const Error err = m_job->start(m_signature)) { m_vr = VerificationResult(err); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento stopped with error"; #endif return false; } connect(m_job.data(), &VerifyOpaqueJob::result, this, &VerifyOpaqueBodyPartMemento::slotResult); setRunning(true); return true; } void VerifyOpaqueBodyPartMemento::exec() { assert(m_job); setRunning(true); QByteArray plainText; #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento execed"; #endif saveResult(m_job->exec(m_signature, plainText), plainText); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento after execed"; #endif m_job->deleteLater(); // exec'ed jobs don't delete themselves m_job = nullptr; if (canStartKeyListJob()) { std::vector keys; m_keylistjob->exec(keyListPattern(), /*secretOnly=*/ false, keys); if (!keys.empty()) { m_key = keys.back(); } } if (m_keylistjob) { m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves } m_keylistjob = nullptr; setRunning(false); } bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const { if (!m_keylistjob) { return false; } const char *const fpr = m_vr.signature(0).fingerprint(); return fpr && *fpr; } QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const { assert(canStartKeyListJob()); return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); } void VerifyOpaqueBodyPartMemento::saveResult(const VerificationResult &vr, const QByteArray &plainText) { assert(m_job); #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::saveResult called"; #endif m_vr = vr; m_plainText = plainText; setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); } void VerifyOpaqueBodyPartMemento::slotResult(const VerificationResult &vr, const QByteArray &plainText) { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotResult called"; #endif saveResult(vr, plainText); m_job = nullptr; if (canStartKeyListJob() && startKeyListJob()) { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento: canStartKeyListJob && startKeyListJob"; #endif return; } if (m_keylistjob) { m_keylistjob->deleteLater(); } m_keylistjob = nullptr; setRunning(false); notify(); } bool VerifyOpaqueBodyPartMemento::startKeyListJob() { assert(canStartKeyListJob()); if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { return false; } connect(m_keylistjob.data(), &Job::done, this, &VerifyOpaqueBodyPartMemento::slotKeyListJobDone); connect(m_keylistjob.data(), &KeyListJob::nextKey, this, &VerifyOpaqueBodyPartMemento::slotNextKey); return true; } void VerifyOpaqueBodyPartMemento::slotNextKey(const GpgME::Key &key) { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotNextKey called"; #endif m_key = key; } void VerifyOpaqueBodyPartMemento::slotKeyListJobDone() { #ifdef DEBUG_SIGNATURE qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotKeyListJobDone called"; #endif m_keylistjob = nullptr; setRunning(false); notify(); } diff --git a/mimetreeparser/src/memento/verifyopaquebodypartmemento.h b/mimetreeparser/src/memento/verifyopaquebodypartmemento.h index 41526700..afddc396 100644 --- a/mimetreeparser/src/memento/verifyopaquebodypartmemento.h +++ b/mimetreeparser/src/memento/verifyopaquebodypartmemento.h @@ -1,86 +1,87 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H #define MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H #include "cryptobodypartmemento.h" #include #include #include #include #include #include "interfaces/bodypart.h" namespace QGpgME { class VerifyOpaqueJob; class KeyListJob; } class QStringList; namespace MimeTreeParser { class VerifyOpaqueBodyPartMemento : public CryptoBodyPartMemento { Q_OBJECT public: VerifyOpaqueBodyPartMemento(QGpgME::VerifyOpaqueJob *job, QGpgME::KeyListJob *klj, const QByteArray &signature); ~VerifyOpaqueBodyPartMemento() override; bool start() override; void exec() override; const QByteArray &plainText() const { return m_plainText; } const GpgME::VerificationResult &verifyResult() const { return m_vr; } const GpgME::Key &signingKey() const { return m_key; } private Q_SLOTS: void slotResult(const GpgME::VerificationResult &vr, const QByteArray &plainText); void slotKeyListJobDone(); void slotNextKey(const GpgME::Key &); private: void saveResult(const GpgME::VerificationResult &, const QByteArray &); bool canStartKeyListJob() const; QStringList keyListPattern() const; bool startKeyListJob(); private: // input: const QByteArray m_signature; QPointer m_job; QPointer m_keylistjob; // output: GpgME::VerificationResult m_vr; QByteArray m_plainText; GpgME::Key m_key; }; } #endif // MIMETREEPARSER_VERIFYOPAQUEBODYPARTMEMENTO_H diff --git a/mimetreeparser/src/objecttreeparser.cpp b/mimetreeparser/src/objecttreeparser.cpp index f7ff5ffc..797a297c 100644 --- a/mimetreeparser/src/objecttreeparser.cpp +++ b/mimetreeparser/src/objecttreeparser.cpp @@ -1,341 +1,342 @@ /* objecttreeparser.cpp This file is part of KMail, the KDE mail client. Copyright (c) 2003 Marc Mutz Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia Copyright (c) 2015 Sandro Knauß KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ // MessageViewer includes #include "objecttreeparser.h" #include "bodypartformatterfactory.h" #include "nodehelper.h" #include "messagepart.h" #include "partnodebodypart.h" #include "mimetreeparser_debug.h" #include "bodyformatter/utils.h" #include "interfaces/bodypartformatter.h" #include "utils/util.h" #include #include // KDE includes // Qt includes #include #include using namespace MimeTreeParser; ObjectTreeParser::ObjectTreeParser(const ObjectTreeParser *topLevelParser) : mSource(topLevelParser->mSource) , mNodeHelper(topLevelParser->mNodeHelper) , mTopLevelContent(topLevelParser->mTopLevelContent) , mHasPendingAsyncJobs(false) , mAllowAsync(topLevelParser->mAllowAsync) { init(); } ObjectTreeParser::ObjectTreeParser(Interface::ObjectTreeSource *source, MimeTreeParser::NodeHelper *nodeHelper) : mSource(source) , mNodeHelper(nodeHelper) , mTopLevelContent(nullptr) , mHasPendingAsyncJobs(false) , mAllowAsync(false) { init(); } void ObjectTreeParser::init() { Q_ASSERT(mSource); if (!mNodeHelper) { mNodeHelper = new NodeHelper(); mDeleteNodeHelper = true; } else { mDeleteNodeHelper = false; } } ObjectTreeParser::ObjectTreeParser(const ObjectTreeParser &other) : mSource(other.mSource) , mNodeHelper(other.nodeHelper()) , mTopLevelContent(other.mTopLevelContent) , mHasPendingAsyncJobs(other.hasPendingAsyncJobs()) , mAllowAsync(other.allowAsync()) , mDeleteNodeHelper(false) { } ObjectTreeParser::~ObjectTreeParser() { if (mDeleteNodeHelper) { delete mNodeHelper; mNodeHelper = nullptr; } } void ObjectTreeParser::setAllowAsync(bool allow) { Q_ASSERT(!mHasPendingAsyncJobs); mAllowAsync = allow; } bool ObjectTreeParser::allowAsync() const { return mAllowAsync; } bool ObjectTreeParser::hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; } QString ObjectTreeParser::plainTextContent() const { return mPlainTextContent; } QString ObjectTreeParser::htmlContent() const { return mHtmlContent; } void ObjectTreeParser::copyContentFrom(const ObjectTreeParser *other) { mPlainTextContent += other->plainTextContent(); mHtmlContent += other->htmlContent(); if (!other->plainTextContentCharset().isEmpty()) { mPlainTextContentCharset = other->plainTextContentCharset(); } if (!other->htmlContentCharset().isEmpty()) { mHtmlContentCharset = other->htmlContentCharset(); } } //----------------------------------------------------------------------------- void ObjectTreeParser::parseObjectTree(KMime::Content *node, bool parseOnlySingleNode) { mTopLevelContent = node; mParsedPart = parseObjectTreeInternal(node, parseOnlySingleNode); if (mParsedPart) { mParsedPart->fix(); if (auto mp = toplevelTextNode(mParsedPart)) { if (auto _mp = mp.dynamicCast()) { extractNodeInfos(_mp->content(), true); } else if (auto _mp = mp.dynamicCast()) { if (_mp->childParts().contains(Util::MultipartPlain)) { extractNodeInfos(_mp->childParts()[Util::MultipartPlain]->content(), true); } } setPlainTextContent(mp->text()); } mSource->render(mParsedPart, parseOnlySingleNode); } } MessagePartPtr ObjectTreeParser::parsedPart() const { return mParsedPart; } MessagePartPtr ObjectTreeParser::processType(KMime::Content *node, ProcessResult &processResult, const QByteArray &mimeType) { const auto formatters = mSource->bodyPartFormatterFactory()->formattersForType(QString::fromUtf8(mimeType)); Q_ASSERT(!formatters.empty()); for (auto formatter : formatters) { PartNodeBodyPart part(this, &processResult, mTopLevelContent, node, mNodeHelper); mNodeHelper->setNodeDisplayedEmbedded(node, true); const MessagePart::Ptr result = formatter->process(part); if (!result) { continue; } result->setAttachmentContent(node); return result; } Q_UNREACHABLE(); return {}; } MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node, bool onlyOneMimePart) { if (!node) { return MessagePart::Ptr(); } // reset pending async jobs state (we'll rediscover pending jobs as we go) mHasPendingAsyncJobs = false; // reset "processed" flags for... if (onlyOneMimePart) { // ... this node and all descendants mNodeHelper->setNodeUnprocessed(node, false); if (!node->contents().isEmpty()) { mNodeHelper->setNodeUnprocessed(node, true); } } else if (!node->parent()) { // ...this node and all it's siblings and descendants mNodeHelper->setNodeUnprocessed(node, true); } const bool isRoot = node->isTopLevel(); auto parsedPart = MessagePart::Ptr(new MessagePartList(this)); parsedPart->setIsRoot(isRoot); KMime::Content *parent = node->parent(); auto contents = parent ? parent->contents() : KMime::Content::List(); if (contents.isEmpty()) { contents.append(node); } int i = contents.indexOf(node); if (i < 0) { return parsedPart; } else { for (; i < contents.size(); ++i) { node = contents.at(i); if (mNodeHelper->nodeProcessed(node)) { continue; } ProcessResult processResult(mNodeHelper); QByteArray mimeType("text/plain"); if (node->contentType(false) && !node->contentType()->mimeType().isEmpty()) { mimeType = node->contentType()->mimeType(); } // unfortunately there's many emails where we can't trust the attachment mimetype // so try to see if we can find something better if (mimeType == "application/octet-stream") { NodeHelper::magicSetType(node); mimeType = node->contentType()->mimeType(); } const auto mp = processType(node, processResult, mimeType); Q_ASSERT(mp); parsedPart->appendSubPart(mp); mNodeHelper->setNodeProcessed(node, false); // adjust signed/encrypted flags if inline PGP was found processResult.adjustCryptoStatesOfNode(node); if (onlyOneMimePart) { break; } } } return parsedPart; } KMMsgSignatureState ProcessResult::inlineSignatureState() const { return mInlineSignatureState; } void ProcessResult::setInlineSignatureState(KMMsgSignatureState state) { mInlineSignatureState = state; } KMMsgEncryptionState ProcessResult::inlineEncryptionState() const { return mInlineEncryptionState; } void ProcessResult::setInlineEncryptionState(KMMsgEncryptionState state) { mInlineEncryptionState = state; } bool ProcessResult::neverDisplayInline() const { return mNeverDisplayInline; } void ProcessResult::setNeverDisplayInline(bool display) { mNeverDisplayInline = display; } void ProcessResult::adjustCryptoStatesOfNode(const KMime::Content *node) const { if ((inlineSignatureState() != KMMsgNotSigned) || (inlineEncryptionState() != KMMsgNotEncrypted)) { mNodeHelper->setSignatureState(node, inlineSignatureState()); mNodeHelper->setEncryptionState(node, inlineEncryptionState()); } } void ObjectTreeParser::extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart) { if (isFirstTextPart) { mPlainTextContent += curNode->decodedText(); mPlainTextContentCharset += NodeHelper::charset(curNode); } } void ObjectTreeParser::setPlainTextContent(const QString &plainTextContent) { mPlainTextContent = plainTextContent; } const QTextCodec *ObjectTreeParser::codecFor(KMime::Content *node) const { Q_ASSERT(node); if (mSource->overrideCodec()) { return mSource->overrideCodec(); } return mNodeHelper->codec(node); } QByteArray ObjectTreeParser::plainTextContentCharset() const { return mPlainTextContentCharset; } QByteArray ObjectTreeParser::htmlContentCharset() const { return mHtmlContentCharset; } MimeTreeParser::NodeHelper *ObjectTreeParser::nodeHelper() const { return mNodeHelper; } diff --git a/mimetreeparser/src/objecttreeparser.h b/mimetreeparser/src/objecttreeparser.h index bbc6c87e..c863c0a6 100644 --- a/mimetreeparser/src/objecttreeparser.h +++ b/mimetreeparser/src/objecttreeparser.h @@ -1,372 +1,373 @@ /* objecttreeparser.h This file is part of KMail, the KDE mail client. Copyright (c) 2003 Marc Mutz Copyright (C) 2002-2003, 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Copyright (c) 2009 Andras Mantia KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. KMail 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef MIMETREEPARSER_OBJECTTREEPARSER_H #define MIMETREEPARSER_OBJECTTREEPARSER_H #include "mimetreeparser_export.h" #include "mimetreeparser/nodehelper.h" #include "mimetreeparser/objecttreesource.h" #include class QString; namespace KMime { class Content; } namespace MimeTreeParser { class PartMetaData; class ViewerPrivate; class NodeHelper; class MessagePart; class MimeMessagePart; typedef QSharedPointer MessagePartPtr; typedef QSharedPointer MimeMessagePartPtr; class MIMETREEPARSER_EXPORT ProcessResult { public: explicit ProcessResult(NodeHelper *nodeHelper, KMMsgSignatureState inlineSignatureState = KMMsgNotSigned, KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted, bool neverDisplayInline = false) : mInlineSignatureState(inlineSignatureState) , mInlineEncryptionState(inlineEncryptionState) , mNeverDisplayInline(neverDisplayInline) , mNodeHelper(nodeHelper) { } KMMsgSignatureState inlineSignatureState() const; void setInlineSignatureState(KMMsgSignatureState state); KMMsgEncryptionState inlineEncryptionState() const; void setInlineEncryptionState(KMMsgEncryptionState state); bool neverDisplayInline() const; void setNeverDisplayInline(bool display); void adjustCryptoStatesOfNode(const KMime::Content *node) const; private: KMMsgSignatureState mInlineSignatureState; KMMsgEncryptionState mInlineEncryptionState; bool mNeverDisplayInline : 1; NodeHelper *mNodeHelper; }; /** \brief Parses messages and generates HTML display code out of them \par Introduction First, have a look at the documentation in Mainpage.dox and at the documentation of ViewerPrivate to understand the broader picture. Just a note on the terminology: 'Node' refers to a MIME part here, which in KMime is a KMime::Content. \par Basics The ObjectTreeParser basically has two modes: Generating the HTML code for the Viewer, or only extracting the plainTextContent() for situations where only the message text is needed, for example when inline forwarding a message. The mode depends on the Interface::ObjectTreeSource passed to the constructor: If Interface::ObjectTreeSource::htmlWriter() is not 0, then the HTML code generation mode is used. Basically, all the ObjectTreeParser does is going through the tree of MIME parts and operating on those nodes. Operating here means creating the HTML code for the node or extracting the textual content from it. This process is started with parseObjectTree(), where we loop over the subnodes of the current root node. For each of those subnodes, we try to find a BodyPartFormatter that can handle the type of the node. This can either be an internal function, such as processMultiPartAlternativeSubtype() or processTextHtmlSubtype(), or it can be an external plugin. More on external plugins later. When no matching formatter is found, defaultHandling() is called for that node. \par Multipart Nodes Those nodes that are of type multipart have subnodes. If one of those children needs to be processed normally, the processMultipartXXX() functions call stdChildHandling() for the node that should be handled normally. stdChildHandling() creates its own ObjectTreeParser, which is a clone of the current ObjectTreeParser, and processes the node. stdChildHandling() is not called for all children of the multipart node, for example processMultiPartAlternativeSubtype() only calls it on one of the children, as the other one doesn't need to be displayed. Similary, processMultiPartSignedSubtype() doesn't call stdChildHandling() for the signature node, only for the signed node. \par Processed and Unprocessed Nodes When a BodyPartFormatter has finished processing a node, it is processed. Nodes are set to being not processed at the beginning of parseObjectTree(). The processed state of a node is saved in a list in NodeHelper, see NodeHelper::setNodeProcessed(), NodeHelper::nodeProcessed() and the other related helper functions. It is the responsibility of the BodyPartFormatter to correctly call setNodeProcessed() and the related functions. This is important so that processing the same node twice can be prevented. The check that prevents duplicate processing is in parseObjectTree(). An example where duplicate processing would happen if we didn't check for it is in stdChildHandling(), which is for example called from processMultiPartAlternativeSubtype(). Let's say the setting is to prefer HTML over plain text. In this case, processMultiPartAlternativeSubtype() would call stdChildHandling() on the HTML node, which would create a new ObjectTreeParser and call parseObjectTree() on it. parseObjectTree() processes the node and all its siblings, and one of the siblings is the plain text node, which shouldn't be processed! Therefore processMultiPartAlternativeSubtype() sets the plain text node as been processed already. \par Plain Text Output Various nodes have plain text that should be displayed. This plain text is usually processed though writeBodyString() first. That method checks if the provided text is an inline PGP text and decrypts it if necessary. It also pushes the text through quotedHTML(), which does a number of things like coloring quoted lines or detecting links and creating real link tags for them. \par Modifying the Message The ObjectTreeParser does not only parse its message, in some circumstances it also modifies it before displaying. This is for example the case when displaying a decrypted message: The original message only contains a binary blob of crypto data, and processMultiPartEncryptedSubtype() decrypts that blob. After decryption, the current node is replaced with the decrypted node, which happens in insertAndParseNewChildNode(). \par Crypto Operations For signature and decryption handling, there are functions which help with generating the HTML code for the signature header and footer. These are writeDeferredDecryptionBlock(), writeSigstatFooter() and writeSigstatHeader(). As the name writeDeferredDecryptionBlock() suggests, a setting can cause the message to not be decrypted unless the user clicks a link. Whether the message should be decrypted or not can be controlled by Interface::ObjectTreeSource::decryptMessage(). When the user clicks the decryption link, the URLHandler for 'kmail:' URLs sets that variable to true and triggers an update of the Viewer, which will cause parseObjectTree() to be called again. \par Async Crypto Operations The above case describes decryption the message in place. However, decryption and also verifying of the signature can take a long time, so synchronous decryption and verifing would cause the Viewer to block. Therefore it is possible to run these operations in async mode, see allowAsync(). In the first run of the async mode, all the ObjectTreeParser does is starting the decrypt or the verify job, and informing the user that the operation is in progress with writeDecryptionInProgressBlock() or with writeSigstatHeader(). Then, it creates and associates a BodyPartMemento with the current node, for example a VerifyDetachedBodyPartMemento. Each node can have multiple mementos associated with it, which are differeniated by name. NodeHelper::setBodyPartMemento() and NodeHelper::bodyPartMemento() provide means to store and retrieve these mementos. A memento is basically a thin wrapper around the crypto job, it stores the job pointer, the job input data and the job result. Mementos can be used for any async situation, not just for crypto jobs, but I'll describe crypto jobs here. So in the first run of decrypting or verifying a message, the BodyPartFormatter only starts the crypto job, creates the BodyPartMemento and writes the HTML code that tells the user that the operation is in progress. parseObjectTree() thus finishes without waiting for anything, and the message is displayed. At some point, the crypto jobs then finish, which will cause slotResult() of the BodyPartMemento to be called. slotResult() then saves the result to some member variable and calls BodyPartMemento::notify(), which in the end will trigger an update of the Viewer. That update will, in ViewerPrivate::parseMsg(), create a new ObjectTreeParser and call parseObjectTree() on it. This is where the second run begins. The functions that deal with decrypting of verifying, like processMultiPartSignedSubtype() or processMultiPartEncryptedSubtype() will look if they find a BodyPartMemento that is associated with the current node. Now it finds that memento, since it was created in the first run. It checks if the memento's job has finished, and if so, the result can be written out (either the decrypted data or the verified signature). When dealing with encrypted nodes, new nodes are created with the decrypted data. It is important to note that the original MIME tree is never modified, and remains the same as the original one. The method createAndParseTempNode is called with the newly decrypted data, and it generates a new temporary node to store the decrypted data. When these nodes are created, it is important to keep track of them as otherwise some mementos that are added to the newly created temporary nodes will be constantly regenerated. As the regeneration triggers a viewer update when complete, it results in an infinite refresh loop. The function NodeHelper::linkAsPermanentDecrypted will create a link between the newly created node and the original parent. Conversely, the function NodeHelper::attachExtraContent will create a link in the other direction, from the parent node to the newly created temporary node. When generating some mementos for nodes that may be temporary nodes (for example, contact photo mementos), the function NodeHelper::setBodyPartMementoForPermanentParent is used. This will save the given body part memento for the closest found permanent parent node, rather than the transient node itself. Then when checking for the existence of a certain memento in a node, NodeHelper::findPermanentParentBodyPartMemento will check to see if any parent of the given temporary node is a permanent (encrypted) node that has been used to generate the asked-for node. To conclude: For async operations, parseObjectTree() is called twice: The first call starts the crypto operation and creates the BodyPartMemento, the second calls sees that the BodyPartMemento is there and can use its result for writing out the HTML. \par PartMetaData and ProcessResult For crypto operations, the class PartMetaData is used a lot, mainly to pass around info about the crypto state of a node. A PartMetaData can also be associated with a node by using NodeHelper::setPartMetaData(). The only user of that however is MessageAnalyzer::processPart() of the Nepomuk E-Mail Feeder, which also uses the ObjectTreeParser to analyze the message. You'll notice that a ProcessResult is passed to each formatter. The formatter is supposed to modify the ProcessResult to tell the callers something about the state of the nodes that were processed. One example for its use is to tell the caller about the crypto state of the node. \par BodyPartFormatter Plugins As mentioned way earlier, BodyPartFormatter can either be plugins or be internal. bodypartformatter.cpp contains some trickery so that the processXXX() methods of the ObjectTreeParser are called from a BodyPartFormatter associated with them, see the CREATE_BODY_PART_FORMATTER macro. The BodyPartFormatter code is work in progress, it was supposed to be refactored, but that has not yet happened at the time of writing. Therefore the code can seem a bit chaotic. External plugins are loaded with loadPlugins() in bodypartformatterfactory.cpp. External plugins can only use the classes in the interfaces/ directory, they include BodyPart, BodyPartMemento, BodyPartFormatterPlugin, BodyPartFormatter, BodyPartURLHandler and URLHandler. Therefore external plugins have powerful capabilities, which are needed for example in the iCal formatter or in the vCard formatter. \par Special HTML tags As also mentioned in the documentation of ViewerPrivate, the ObjectTreeParser writes out special links that are only understood by the viewer, for example 'kmail:' URLs or 'attachment:' URLs. Also, some special HTML tags are created, which the Viewer later uses for post-processing. For example a div with the id 'attachmentInjectionPoint', or a div with the id 'attachmentDiv', which is used to mark an attachment in the body with a yellow border when the user clicks the attachment in the header. Finally, parseObjectTree() creates an anchor with the id 'att%1', which is used in the Viewer to scroll to the attachment. */ class MIMETREEPARSER_EXPORT ObjectTreeParser { /** * @internal * Copies the context of @p other, but not it's rawDecryptedBody, plainTextContent or htmlContent. */ ObjectTreeParser(const ObjectTreeParser &other); public: explicit ObjectTreeParser(Interface::ObjectTreeSource *source, NodeHelper *nodeHelper = nullptr); explicit ObjectTreeParser(const ObjectTreeParser *topLevelParser); virtual ~ObjectTreeParser(); void setAllowAsync(bool allow); bool allowAsync() const; bool hasPendingAsyncJobs() const; /** * The text of the message, ie. what would appear in the * composer's text editor if this was edited or replied to. * This is usually the content of the first text/plain MIME part. */ QString plainTextContent() const; /** * Similar to plainTextContent(), but returns the HTML source of the first text/html MIME part. * * Not to be consfused with the HTML code that the message viewer widget displays, that HTML * is written out by htmlWriter() and a totally different pair of shoes. */ QString htmlContent() const; /** * The original charset of MIME part the plain text was extracted from. * * If there were more than one text/plain MIME parts in the mail, the this is the charset * of the last MIME part processed. */ QByteArray plainTextContentCharset() const; QByteArray htmlContentCharset() const; NodeHelper *nodeHelper() const; /** Parse beginning at a given node and recursively parsing the children of that node and it's next sibling. */ void parseObjectTree(KMime::Content *node, bool parseOnlySingleNode = false); MessagePartPtr parsedPart() const; private: void extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart); void setPlainTextContent(const QString &plainTextContent); /** * Does the actual work for parseObjectTree. Unlike parseObjectTree(), this does not change the * top-level content. */ MessagePartPtr parseObjectTreeInternal(KMime::Content *node, bool mOnlyOneMimePart); MessagePartPtr processType(KMime::Content *node, MimeTreeParser::ProcessResult &processResult, const QByteArray &mimeType); private: /** ctor helper */ void init(); const QTextCodec *codecFor(KMime::Content *node) const; void copyContentFrom(const ObjectTreeParser *other); private: Interface::ObjectTreeSource *mSource; NodeHelper *mNodeHelper; QByteArray mPlainTextContentCharset; QByteArray mHtmlContentCharset; QString mPlainTextContent; QString mHtmlContent; KMime::Content *mTopLevelContent; MessagePartPtr mParsedPart; /// Show only one mime part means that the user has selected some node in the message structure /// viewer that is not the root, which means the user wants to only see the selected node and its /// children. If that is the case, this variable is set to true. /// The code needs to behave differently if this is set. For example, it should not process the /// siblings. Also, consider inline images: Normally, those nodes are completely hidden, as the /// HTML node embedds them. However, when showing only the node of the image, one has to show them, /// as their is no HTML node in which they are displayed. There are many more cases where this /// variable needs to be obeyed. /// This variable is set to false again when processing the children in stdChildHandling(), as /// the children can be completely displayed again. bool mShowOnlyOneMimePart; bool mHasPendingAsyncJobs; bool mAllowAsync; // DataUrl Icons cache QString mCollapseIcon; QString mExpandIcon; bool mDeleteNodeHelper; friend class PartNodeBodyPart; friend class MessagePart; friend class EncryptedMessagePart; friend class SignedMessagePart; friend class TextMessagePart; friend class HtmlMessagePart; friend class MultiPartSignedBodyPartFormatter; friend class ApplicationPkcs7MimeBodyPartFormatter; }; } #endif // MIMETREEPARSER_OBJECTTREEPARSER_H diff --git a/mimetreeparser/src/partmetadata.h b/mimetreeparser/src/partmetadata.h index 29d72bbf..ae6565e8 100644 --- a/mimetreeparser/src/partmetadata.h +++ b/mimetreeparser/src/partmetadata.h @@ -1,66 +1,67 @@ /* -*- c++ -*- partmetadata.h KMail, the KDE mail client. Copyright (c) 2002-2003 Karl-Heinz Zimmer Copyright (c) 2003 Marc Mutz This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2.0, as published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US */ #ifndef MIMETREEPARSER_PARTMETADATA_H #define MIMETREEPARSER_PARTMETADATA_H #include "mimetreeparser_export.h" #include #include #include #include namespace MimeTreeParser { class PartMetaData { public: PartMetaData() : sigSummary(GpgME::Signature::None) , isSigned(false) , isGoodSignature(false) , isEncrypted(false) , isDecryptable(false) , inProgress(false) , technicalProblem(false) , isEncapsulatedRfc822Message(false) { } GpgME::Signature::Summary sigSummary; QString signClass; QString signer; QStringList signerMailAddresses; QByteArray keyId; GpgME::Signature::Validity keyTrust; QString status; // to be used for unknown plug-ins int status_code; // to be used for i18n of OpenPGP and S/MIME CryptPlugs QString errorText; QDateTime creationTime; QString decryptionError; QString auditLog; GpgME::Error auditLogError; bool isSigned : 1; bool isGoodSignature : 1; bool isEncrypted : 1; bool isDecryptable : 1; bool inProgress : 1; bool technicalProblem : 1; bool isEncapsulatedRfc822Message : 1; }; } #endif // MIMETREEPARSER_PARTMETADATA_H diff --git a/templateparser/src/templatestexteditor.cpp b/templateparser/src/templatestexteditor.cpp index cc9ff8da..fdb87d10 100644 --- a/templateparser/src/templatestexteditor.cpp +++ b/templateparser/src/templatestexteditor.cpp @@ -1,114 +1,115 @@ /* Copyright (c) 2013-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "templatestexteditor.h" #include "templatesutil_p.h" #include #include #include #include #include #include #include #include using namespace TemplateParser; TemplatesTextEditor::TemplatesTextEditor(QWidget *parent) : KPIMTextEdit::PlainTextEditor(parent) { setFocus(); const QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont); setFont(f); QStringList excludeKeyWord; const QStringList lst = TemplateParser::Util::keywords(); for (QString str : lst) { excludeKeyWord << str.remove(QLatin1Char('%')); excludeKeyWord << str.replace(QLatin1String("\\("), QLatin1String("(")); } addIgnoreWords(excludeKeyWord); setWordWrapMode(QTextOption::NoWrap); initCompleter(); createHighlighter(); } TemplatesTextEditor::~TemplatesTextEditor() { } void TemplatesTextEditor::updateHighLighter() { KPIMTextEdit::PlainTextSyntaxSpellCheckingHighlighter *hlighter = dynamic_cast(highlighter()); if (hlighter) { hlighter->toggleSpellHighlighting(checkSpellingEnabled()); } } void TemplatesTextEditor::clearDecorator() { //Nothing } void TemplatesTextEditor::createHighlighter() { KPIMTextEdit::PlainTextSyntaxSpellCheckingHighlighter *highlighter = new KPIMTextEdit::PlainTextSyntaxSpellCheckingHighlighter(this); highlighter->toggleSpellHighlighting(checkSpellingEnabled()); highlighter->setCurrentLanguage(spellCheckingLanguage()); highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("KMail Template"))); highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128) ? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme) : mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); setHighlighter(highlighter); } void TemplatesTextEditor::initCompleter() { QStringList listWord; QStringList excludeKeyWord; const QStringList lst = TemplateParser::Util::keywords(); excludeKeyWord.reserve(lst.count()); for (QString str : lst) { excludeKeyWord << str.replace(QLatin1String("\\("), QLatin1String("(")); } listWord << excludeKeyWord; listWord << Util::keywordsWithArgs(); mTextEditorCompleter = new KPIMTextEdit::TextEditorCompleter(this, this); mTextEditorCompleter->setCompleterStringList(listWord); mTextEditorCompleter->setExcludeOfCharacters(QStringLiteral("~!@#$^&*()+{}|\"<>,./;'[]\\-= ")); } void TemplatesTextEditor::keyPressEvent(QKeyEvent *e) { if (mTextEditorCompleter->completer()->popup()->isVisible()) { switch (e->key()) { case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Escape: case Qt::Key_Tab: case Qt::Key_Backtab: e->ignore(); return; // let the completer do default behavior default: break; } } KPIMTextEdit::PlainTextEditor::keyPressEvent(e); mTextEditorCompleter->completeText(); } diff --git a/templateparser/src/templatestexteditor.h b/templateparser/src/templatestexteditor.h index 33bbef9b..54a985a3 100644 --- a/templateparser/src/templatestexteditor.h +++ b/templateparser/src/templatestexteditor.h @@ -1,50 +1,51 @@ /* Copyright (c) 2013-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef TEMPLATESTEXTEDITOR_H #define TEMPLATESTEXTEDITOR_H #include "kpimtextedit/plaintexteditor.h" #include class QKeyEvent; namespace KPIMTextEdit { class TextEditorCompleter; } namespace TemplateParser { class TemplatesTextEditor : public KPIMTextEdit::PlainTextEditor { Q_OBJECT public: explicit TemplatesTextEditor(QWidget *parent = nullptr); ~TemplatesTextEditor() override; protected: void initCompleter(); void keyPressEvent(QKeyEvent *e) override; void updateHighLighter() override; void clearDecorator() override; void createHighlighter() override; private: KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter = nullptr; KSyntaxHighlighting::Repository mSyntaxRepo; }; } #endif // TEMPLATESTEXTEDITOR_H diff --git a/templateparser/src/templatesutil.cpp b/templateparser/src/templatesutil.cpp index dd91f5df..f760dedd 100644 --- a/templateparser/src/templatesutil.cpp +++ b/templateparser/src/templatesutil.cpp @@ -1,124 +1,125 @@ /* Copyright (c) 2011-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "templatesutil.h" #include "templatesutil_p.h" #include #include #include using namespace TemplateParser; void TemplateParser::Util::deleteTemplate(const QString &id) { KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("templatesconfigurationrc"), KConfig::NoGlobals); const QString key = QStringLiteral("Templates #%1").arg(id); if (config->hasGroup(key)) { KConfigGroup group = config->group(key); group.deleteGroup(); group.sync(); } } QStringList TemplateParser::Util::keywordsWithArgs() { const QStringList keywordsWithArgs = QStringList() << QStringLiteral("%REM=\"\"%-") << QStringLiteral("%INSERT=\"\"") << QStringLiteral("%SYSTEM=\"\"") << QStringLiteral("%QUOTEPIPE=\"\"") << QStringLiteral("%MSGPIPE=\"\"") << QStringLiteral("%BODYPIPE=\"\"") << QStringLiteral("%CLEARPIPE=\"\"") << QStringLiteral("%TEXTPIPE=\"\"") << QStringLiteral("%OHEADER=\"\"") << QStringLiteral("%HEADER=\"\"") << QStringLiteral("%DICTIONARYLANGUAGE=\"\"") << QStringLiteral("%LANGUAGE=\"\""); return keywordsWithArgs; } QStringList TemplateParser::Util::keywords() { const QStringList keywords = QStringList() << QStringLiteral("%QUOTE") << QStringLiteral("%FORCEDPLAIN") << QStringLiteral("%FORCEDHTML") << QStringLiteral("%QHEADERS") << QStringLiteral("%HEADERS") << QStringLiteral("%TEXT") << QStringLiteral("%OTEXTSIZE") << QStringLiteral("%OTEXT") << QStringLiteral("%OADDRESSEESADDR") << QStringLiteral("%CCADDR") << QStringLiteral("%CCNAME") << QStringLiteral("%CCFNAME") << QStringLiteral("%CCLNAME") << QStringLiteral("%TOADDR") << QStringLiteral("%TONAME") << QStringLiteral("%TOFNAME") << QStringLiteral("%TOLNAME") << QStringLiteral("%TOLIST") << QStringLiteral("%FROMADDR") << QStringLiteral("%FROMNAME") << QStringLiteral("%FROMFNAME") << QStringLiteral("%FROMLNAME") << QStringLiteral("%FULLSUBJECT") << QStringLiteral("%MSGID") << QStringLiteral("%HEADER\\( ") << QStringLiteral("%OCCADDR") << QStringLiteral("%OCCNAME") << QStringLiteral("%OCCFNAME") << QStringLiteral("%OCCLNAME") << QStringLiteral("%OTOADDR") << QStringLiteral("%OTONAME") << QStringLiteral("%OTOFNAME") << QStringLiteral("%OTOLNAME") << QStringLiteral("%OTOLIST") << QStringLiteral("%OTO") << QStringLiteral("%OFROMADDR") << QStringLiteral("%OFROMNAME") << QStringLiteral("%OFROMFNAME") << QStringLiteral("%OFROMLNAME") << QStringLiteral("%OFULLSUBJECT") << QStringLiteral("%OFULLSUBJ") << QStringLiteral("%OMSGID") << QStringLiteral("%DATEEN") << QStringLiteral("%DATESHORT") << QStringLiteral("%DATE") << QStringLiteral("%DOW") << QStringLiteral("%TIMELONGEN") << QStringLiteral("%TIMELONG") << QStringLiteral("%TIME") << QStringLiteral("%ODATEEN") << QStringLiteral("%ODATESHORT") << QStringLiteral("%ODATE") << QStringLiteral("%ODOW") << QStringLiteral("%OTIMELONGEN") << QStringLiteral("%OTIMELONG") << QStringLiteral("%OTIME") << QStringLiteral("%BLANK") << QStringLiteral("%NOP") << QStringLiteral("%CLEAR") << QStringLiteral("%DEBUGOFF") << QStringLiteral("%DEBUG") << QStringLiteral("%CURSOR") << QStringLiteral("%SIGNATURE"); return keywords; } diff --git a/templateparser/src/templatesutil.h b/templateparser/src/templatesutil.h index e7c3da3a..e7dfbdb6 100644 --- a/templateparser/src/templatesutil.h +++ b/templateparser/src/templatesutil.h @@ -1,30 +1,31 @@ /* Copyright (c) 2011-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This progam 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef TEMPLATEPARSER_TEMPLATESUTIL_H #define TEMPLATEPARSER_TEMPLATESUTIL_H #include "templateparser_export.h" class QString; namespace TemplateParser { namespace Util { TEMPLATEPARSER_EXPORT void deleteTemplate(const QString &id); } } #endif diff --git a/templateparser/src/templatesutil_p.h b/templateparser/src/templatesutil_p.h index b2471f66..0dc936a5 100644 --- a/templateparser/src/templatesutil_p.h +++ b/templateparser/src/templatesutil_p.h @@ -1,32 +1,33 @@ /* Copyright (c) 2011-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This progam 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef TEMPLATEPARSER_TEMPLATESUTIL_P_H #define TEMPLATEPARSER_TEMPLATESUTIL_P_H #include "templateparser_export.h" class QString; class QStringList; namespace TemplateParser { namespace Util { QStringList keywords(); QStringList keywordsWithArgs(); } } #endif