File indexing completed on 2024-11-24 04:52:56
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 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 #ifndef COMPOSER_SUBMISSION_H 0023 #define COMPOSER_SUBMISSION_H 0024 0025 #include <memory> 0026 #include <QPersistentModelIndex> 0027 #include <QPointer> 0028 0029 #include "Common/Logging.h" 0030 #include "Composer/Recipients.h" 0031 0032 namespace Imap { 0033 namespace Mailbox { 0034 class ImapTask; 0035 class Model; 0036 } 0037 } 0038 0039 namespace MSA { 0040 class MSAFactory; 0041 } 0042 0043 namespace Composer { 0044 0045 class AbstractComposer; 0046 0047 /** @short Handle submission of an e-mail via multiple ways 0048 0049 This class uses the MessageComposer for modelling a message and an MSA implementation for the actual submission. 0050 The whole process is (trying to be) interruptable once started. 0051 */ 0052 class Submission : public QObject 0053 { 0054 Q_OBJECT 0055 public: 0056 explicit Submission(QObject *parent, std::shared_ptr<AbstractComposer> composer, Imap::Mailbox::Model *model, MSA::MSAFactory *msaFactory, const QString &accountId); 0057 virtual ~Submission(); 0058 0059 QString accountId() const; 0060 0061 void setImapOptions(const bool saveToSentFolder, const QString &sentFolderName, 0062 const QString &hostname, const QString &username, const bool useImapSubmit); 0063 void setSmtpOptions(const bool useBurl, const QString &smtpUsername); 0064 0065 void send(); 0066 0067 /** @short Progress of the current submission */ 0068 enum SubmissionProgress { 0069 STATE_INIT, /**< Nothing is happening yet */ 0070 STATE_BUILDING_MESSAGE, /**< Waiting for data to become available */ 0071 STATE_SAVING, /**< Saving the message to the Sent folder */ 0072 STATE_PREPARING_URLAUTH, /**< Making the resulting message available via IMAP's URLAUTH */ 0073 STATE_SUBMITTING, /**< Submitting the message via an MSA */ 0074 STATE_UPDATING_FLAGS, /**< Updating flags of the relevant message(s) */ 0075 STATE_SENT, /**< All done, succeeded */ 0076 STATE_FAILED /**< Unable to send */ 0077 }; 0078 0079 public slots: 0080 void setPassword(const QString &password); 0081 void cancelPassword(); 0082 0083 private slots: 0084 void gotError(const QString &error); 0085 void sent(); 0086 0087 void slotAppendUidKnown(const uint uidValidity, const uint uid); 0088 void slotGenUrlAuthReceived(const QString &url); 0089 void slotAppendSucceeded(); 0090 void slotAppendFailed(const QString &error); 0091 void onUpdatingFlagsOfReplyingToSucceded(); 0092 void onUpdatingFlagsOfReplyingToFailed(); 0093 void onUpdatingFlagsOfForwardingSucceeded(); 0094 void onUpdatingFlagsOfForwardingFailed(); 0095 0096 void slotMessageDataAvailable(); 0097 void slotAskForUrl(); 0098 void slotInvokeMsaNow(); 0099 0100 void onMsaProgressMaxChanged(const int max); 0101 void onMsaProgressCurrentChanged(const int value); 0102 0103 signals: 0104 void progressMin(const int min); 0105 void progressMax(const int max); 0106 void progress(const int progress); 0107 void updateStatusMessage(const QString &message); 0108 void failed(const QString &message); 0109 void succeeded(); 0110 void passwordRequested(const QString &user, const QString &host); 0111 void gotPassword(const QString &password); 0112 void canceled(); 0113 void logged(const Common::LogKind kind, const QString& source, const QString& message); 0114 0115 private: 0116 bool shouldBuildMessageLocally() const; 0117 0118 static QString killDomainPartFromString(const QString &s); 0119 0120 void changeConnectionState(const SubmissionProgress state); 0121 0122 bool m_appendUidReceived; 0123 uint m_appendUidValidity; 0124 uint m_appendUid; 0125 bool m_genUrlAuthReceived; 0126 QString m_urlauth; 0127 bool m_saveToSentFolder; 0128 QString m_sentFolderName; 0129 QString m_imapHostname; 0130 QString m_imapUsername; 0131 bool m_useBurl; 0132 QString m_smtpUsername; 0133 bool m_useImapSubmit; 0134 0135 SubmissionProgress m_state; 0136 QByteArray m_rawMessageData; 0137 int m_msaMaximalProgress; 0138 0139 std::shared_ptr<AbstractComposer> m_source; 0140 QPointer<Imap::Mailbox::Model> m_model; 0141 MSA::MSAFactory *m_msaFactory; 0142 QString m_accountId; 0143 0144 Imap::Mailbox::ImapTask *m_updateReplyingToMessageFlagsTask; 0145 Imap::Mailbox::ImapTask *m_updateForwardingMessageFlagsTask; 0146 0147 Submission(const Submission &); // don't implement 0148 Submission &operator=(const Submission &); // don't implement 0149 }; 0150 0151 QString submissionProgressToString(const Submission::SubmissionProgress progress); 0152 0153 } 0154 0155 #endif // COMPOSER_SUBMISSION_H