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 #ifndef COMPOSER_SUBMISSION_H 23 #define COMPOSER_SUBMISSION_H 24 25 #include <QPersistentModelIndex> 26 #include <QPointer> 27 28 #include "Recipients.h" 29 30 namespace Imap { 31 namespace Mailbox { 32 class ImapTask; 33 class Model; 34 } 35 } 36 37 namespace MSA { 38 class MSAFactory; 39 } 40 41 namespace Composer { 42 43 class MessageComposer; 44 45 /** @short Handle submission of an e-mail via multiple ways 46 47 This class uses the MessageComposer for modelling a message and an MSA implementation for the actual submission. 48 The whole process is (trying to be) interruptable once started. 49 */ 50 class Submission : public QObject 51 { 52 Q_OBJECT 53 public: 54 explicit Submission(QObject *parent, Imap::Mailbox::Model *model, MSA::MSAFactory *msaFactory, const QString &accountId); 55 virtual ~Submission(); 56 57 MessageComposer *composer(); 58 59 QString accountId() const; 60 61 void setImapOptions(const bool saveToSentFolder, const QString &sentFolderName, 62 const QString &hostname, const QString &username, const bool useImapSubmit); 63 void setSmtpOptions(const bool useBurl, const QString &smtpUsername); 64 65 void send(); 66 67 /** @short Progress of the current submission */ 68 enum SubmissionProgress { 69 STATE_INIT, /**< Nothing is happening yet */ 70 STATE_BUILDING_MESSAGE, /**< Waiting for data to become available */ 71 STATE_SAVING, /**< Saving the message to the Sent folder */ 72 STATE_PREPARING_URLAUTH, /**< Making the resulting message available via IMAP's URLAUTH */ 73 STATE_SUBMITTING, /**< Submitting the message via an MSA */ 74 STATE_UPDATING_FLAGS, /**< Updating flags of the relevant message(s) */ 75 STATE_SENT, /**< All done, succeeded */ 76 STATE_FAILED /**< Unable to send */ 77 }; 78 79 public slots: 80 void setPassword(const QString &password); 81 void cancelPassword(); 82 83 private slots: 84 void gotError(const QString &error); 85 void sent(); 86 87 void slotAppendUidKnown(const uint uidValidity, const uint uid); 88 void slotGenUrlAuthReceived(const QString &url); 89 void slotAppendSucceeded(); 90 void slotAppendFailed(const QString &error); 91 void onUpdatingFlagsOfReplyingToSucceded(); 92 void onUpdatingFlagsOfReplyingToFailed(); 93 void onUpdatingFlagsOfForwardingSucceeded(); 94 void onUpdatingFlagsOfForwardingFailed(); 95 96 void slotMessageDataAvailable(); 97 void slotAskForUrl(); 98 void slotInvokeMsaNow(); 99 100 void onMsaProgressMaxChanged(const int max); 101 void onMsaProgressCurrentChanged(const int value); 102 103 signals: 104 void progressMin(const int min); 105 void progressMax(const int max); 106 void progress(const int progress); 107 void updateStatusMessage(const QString &message); 108 void failed(const QString &message); 109 void succeeded(); 110 void passwordRequested(const QString &user, const QString &host); 111 void gotPassword(const QString &password); 112 void canceled(); 113 114 private: 115 bool shouldBuildMessageLocally() const; 116 117 static QString killDomainPartFromString(const QString &s); 118 119 void changeConnectionState(const SubmissionProgress state); 120 121 bool m_appendUidReceived; 122 uint m_appendUidValidity; 123 uint m_appendUid; 124 bool m_genUrlAuthReceived; 125 QString m_urlauth; 126 bool m_saveToSentFolder; 127 QString m_sentFolderName; 128 QString m_imapHostname; 129 QString m_imapUsername; 130 bool m_useBurl; 131 QString m_smtpUsername; 132 bool m_useImapSubmit; 133 134 SubmissionProgress m_state; 135 QByteArray m_rawMessageData; 136 int m_msaMaximalProgress; 137 138 MessageComposer *m_composer; 139 QPointer<Imap::Mailbox::Model> m_model; 140 MSA::MSAFactory *m_msaFactory; 141 QString m_accountId; 142 143 Imap::Mailbox::ImapTask *m_updateReplyingToMessageFlagsTask; 144 Imap::Mailbox::ImapTask *m_updateForwardingMessageFlagsTask; 145 146 Submission(const Submission &); // don't implement 147 Submission &operator=(const Submission &); // don't implement 148 }; 149 150 QString submissionProgressToString(const Submission::SubmissionProgress progress); 151 152 } 153 154 #endif // COMPOSER_SUBMISSION_H 155