File indexing completed on 2024-06-23 05:20:44
0001 /* Copyright (C) 2006 - 2017 Jan Kundrát <jkt@kde.org> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef IMAP_MESSAGECOMPOSER_H 0024 #define IMAP_MESSAGECOMPOSER_H 0025 0026 #include <QAbstractListModel> 0027 #include <QPointer> 0028 0029 #include "Composer/AbstractComposer.h" 0030 #include "Composer/ContentDisposition.h" 0031 #include "Imap/Model/CatenateData.h" 0032 #include "Imap/Parser/Message.h" 0033 0034 namespace Imap { 0035 namespace Mailbox { 0036 class Model; 0037 } 0038 } 0039 0040 namespace Composer { 0041 0042 class AttachmentItem; 0043 0044 /** @short Model storing individual parts of a composed message */ 0045 class MessageComposer : public QAbstractListModel, public AbstractComposer 0046 { 0047 Q_OBJECT 0048 public: 0049 0050 explicit MessageComposer(Imap::Mailbox::Model *model); 0051 ~MessageComposer(); 0052 0053 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0054 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0055 Qt::DropActions supportedDropActions() const override; 0056 Qt::ItemFlags flags(const QModelIndex &index) const override; 0057 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0058 QStringList mimeTypes() const override; 0059 QMimeData *mimeData(const QModelIndexList &indexes) const override; 0060 0061 void setInReplyTo(const QList<QByteArray> &inReplyTo); 0062 void setReferences(const QList<QByteArray> &references); 0063 void setTimestamp(const QDateTime ×tamp); 0064 void setSubject(const QString &subject); 0065 void setOrganization(const QString &organization); 0066 void setText(const QString &text); 0067 void setReplyingToMessage(const QModelIndex &index); 0068 void prepareForwarding(const QModelIndex &index, const ForwardMode mode); 0069 0070 bool isReadyForSerialization() const override; 0071 bool asRawMessage(QIODevice *target, QString *errorMessage) const override; 0072 bool asCatenateData(QList<Imap::Mailbox::CatenatePair> &target, QString *errorMessage) const override; 0073 void setPreloadEnabled(const bool preload) override; 0074 void setRecipients(const QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > &recipients) override; 0075 void setFrom(const Imap::Message::MailAddress &from) override; 0076 0077 QDateTime timestamp() const override; 0078 QList<QByteArray> inReplyTo() const; 0079 QList<QByteArray> references() const; 0080 QByteArray rawFromAddress() const override; 0081 QList<QByteArray> rawRecipientAddresses() const override; 0082 QModelIndex replyingToMessage() const override; 0083 QModelIndex forwardingMessage() const override; 0084 0085 bool addFileAttachment(const QString &path); 0086 void removeAttachment(const QModelIndex &index); 0087 void setAttachmentContentDisposition(const QModelIndex &index, const ContentDisposition disposition); 0088 void setAttachmentName(const QModelIndex &index, const QString &newName); 0089 0090 void setReportTrojitaVersions(const bool reportVersion); 0091 0092 private: 0093 static QByteArray encodeHeaderField(const QString &text); 0094 0095 void ensureRandomStrings() const; 0096 void writeCommonMessageBeginning(QIODevice *target) const; 0097 bool writeAttachmentHeader(QIODevice *target, QString *errorMessage, const AttachmentItem *attachment) const; 0098 bool writeAttachmentBody(QIODevice *target, QString *errorMessage, const AttachmentItem *attachment) const; 0099 0100 void writeHeaderWithMsgIds(QIODevice *target, const QByteArray &headerName, const QList<QByteArray> &messageIds) const; 0101 0102 bool validateDropImapMessage(QDataStream &stream, QString &mailbox, uint &uidValidity, QList<uint> &uids) const; 0103 bool validateDropImapPart(QDataStream &stream, QString &mailbox, uint &uidValidity, uint &uid, QByteArray &trojitaPath) const; 0104 bool dropImapMessage(QDataStream &stream); 0105 bool dropImapPart(QDataStream &stream); 0106 bool dropAttachmentList(QDataStream &stream); 0107 0108 Imap::Message::MailAddress m_from; 0109 QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > m_recipients; 0110 QList<QByteArray> m_inReplyTo; 0111 QList<QByteArray> m_references; 0112 QDateTime m_timestamp; 0113 QString m_subject; 0114 QString m_organization; 0115 QString m_text; 0116 QPersistentModelIndex m_replyingTo; 0117 QPersistentModelIndex m_forwarding; 0118 mutable QByteArray m_messageId; 0119 mutable QByteArray m_mimeBoundary; 0120 0121 QList<AttachmentItem *> m_attachments; 0122 QPointer<Imap::Mailbox::Model> m_model; 0123 bool m_shouldPreload; 0124 bool m_reportTrojitaVersions; 0125 }; 0126 0127 } 0128 0129 #endif // IMAP_MESSAGECOMPOSER_H