1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 2 3 This file is part of the Trojita Qt IMAP e-mail client, 4 http://trojita.flaska.net/ 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2 of 9 the License or (at your option) version 3 or any later version 10 accepted by the membership of KDE e.V. (or its successor approved 11 by the membership of KDE e.V.), which shall act as a proxy 12 defined in Section 14 of version 3 of the license. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef IMAP_MESSAGECOMPOSER_H 24 #define IMAP_MESSAGECOMPOSER_H 25 26 #include <QAbstractListModel> 27 #include <QPointer> 28 29 #include "Composer/ContentDisposition.h" 30 #include "Composer/Recipients.h" 31 #include "Imap/Model/CatenateData.h" 32 #include "Imap/Parser/Message.h" 33 34 namespace Imap { 35 namespace Mailbox { 36 class Model; 37 } 38 } 39 40 namespace Composer { 41 42 class AttachmentItem; 43 44 /** @short Model storing individual parts of a composed message */ 45 class MessageComposer : public QAbstractListModel 46 { 47 Q_OBJECT 48 public: 49 50 explicit MessageComposer(Imap::Mailbox::Model *model, QObject *parent = 0); 51 ~MessageComposer(); 52 53 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; 54 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 55 virtual Qt::DropActions supportedDropActions() const; 56 virtual Qt::ItemFlags flags(const QModelIndex &index) const; 57 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); 58 virtual QStringList mimeTypes() const; 59 virtual QMimeData *mimeData(const QModelIndexList &indexes) const; 60 61 void setFrom(const Imap::Message::MailAddress &from); 62 void setRecipients(const QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > &recipients); 63 void setInReplyTo(const QList<QByteArray> &inReplyTo); 64 void setReferences(const QList<QByteArray> &references); 65 void setTimestamp(const QDateTime ×tamp); 66 void setSubject(const QString &subject); 67 void setOrganization(const QString &organization); 68 void setText(const QString &text); 69 void setReplyingToMessage(const QModelIndex &index); 70 void prepareForwarding(const QModelIndex &index, const ForwardMode mode); 71 72 bool isReadyForSerialization() const; 73 bool asRawMessage(QIODevice *target, QString *errorMessage) const; 74 bool asCatenateData(QList<Imap::Mailbox::CatenatePair> &target, QString *errorMessage) const; 75 76 QDateTime timestamp() const; 77 QList<QByteArray> inReplyTo() const; 78 QList<QByteArray> references() const; 79 QByteArray rawFromAddress() const; 80 QList<QByteArray> rawRecipientAddresses() const; 81 QModelIndex replyingToMessage() const; 82 QModelIndex forwardingMessage() const; 83 84 bool addFileAttachment(const QString &path); 85 void removeAttachment(const QModelIndex &index); 86 void setAttachmentContentDisposition(const QModelIndex &index, const ContentDisposition disposition); 87 void setAttachmentName(const QModelIndex &index, const QString &newName); 88 89 void setPreloadEnabled(const bool preload); 90 void setReportTrojitaVersions(const bool reportVersion); 91 92 private: 93 static QByteArray encodeHeaderField(const QString &text); 94 95 void ensureRandomStrings() const; 96 void writeCommonMessageBeginning(QIODevice *target) const; 97 bool writeAttachmentHeader(QIODevice *target, QString *errorMessage, const AttachmentItem *attachment) const; 98 bool writeAttachmentBody(QIODevice *target, QString *errorMessage, const AttachmentItem *attachment) const; 99 100 void writeHeaderWithMsgIds(QIODevice *target, const QByteArray &headerName, const QList<QByteArray> &messageIds) const; 101 102 bool validateDropImapMessage(QDataStream &stream, QString &mailbox, uint &uidValidity, QList<uint> &uids) const; 103 bool validateDropImapPart(QDataStream &stream, QString &mailbox, uint &uidValidity, uint &uid, QByteArray &trojitaPath) const; 104 bool dropImapMessage(QDataStream &stream); 105 bool dropImapPart(QDataStream &stream); 106 bool dropAttachmentList(QDataStream &stream); 107 108 Imap::Message::MailAddress m_from; 109 QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > m_recipients; 110 QList<QByteArray> m_inReplyTo; 111 QList<QByteArray> m_references; 112 QDateTime m_timestamp; 113 QString m_subject; 114 QString m_organization; 115 QString m_text; 116 QPersistentModelIndex m_replyingTo; 117 QPersistentModelIndex m_forwarding; 118 mutable QByteArray m_messageId; 119 mutable QByteArray m_mimeBoundary; 120 121 QList<AttachmentItem *> m_attachments; 122 QPointer<Imap::Mailbox::Model> m_model; 123 bool m_shouldPreload; 124 bool m_reportTrojitaVersions; 125 }; 126 127 } 128 129 #endif // IMAP_MESSAGECOMPOSER_H 130