File indexing completed on 2024-05-12 05:17:23

0001 /*
0002     Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
0003     Copyright (c) 2009 Andras Mantia <amantia@kde.org>
0004     Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
0005 
0006     This library is free software; you can redistribute it and/or modify it
0007     under the terms of the GNU Library General Public License as published by
0008     the Free Software Foundation; either version 2 of the License, or (at your
0009     option) any later version.
0010 
0011     This library is distributed in the hope that it will be useful, but WITHOUT
0012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0014     License for more details.
0015 
0016     You should have received a copy of the GNU Library General Public License
0017     along with this library; see the file COPYING.LIB.  If not, write to the
0018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0019     02110-1301, USA.
0020 */
0021 
0022 #ifndef KIMAP2_LOGINJOB_H
0023 #define KIMAP2_LOGINJOB_H
0024 
0025 #include "kimap2_export.h"
0026 
0027 #include "job.h"
0028 #include <QtNetwork/QSsl>
0029 
0030 namespace KIMAP2
0031 {
0032 
0033 class Session;
0034 struct Message;
0035 class LoginJobPrivate;
0036 
0037 class KIMAP2_EXPORT LoginJob : public Job
0038 {
0039     Q_OBJECT
0040     Q_DECLARE_PRIVATE(LoginJob)
0041 
0042     friend class SessionPrivate;
0043 
0044 public:
0045 
0046     enum AuthenticationMode {
0047         ClearText = 0,
0048         Login,
0049         Plain,
0050         CramMD5,
0051         DigestMD5,
0052         NTLM,
0053         GSSAPI,
0054         Anonymous,
0055         XOAuth2
0056     };
0057 
0058     explicit LoginJob(Session *session);
0059     virtual ~LoginJob();
0060 
0061     QString userName() const;
0062     void setUserName(const QString &userName);
0063 
0064     /**
0065      * Get the authorization identity.
0066      * @since 4.10
0067      */
0068     QString authorizationName() const;
0069 
0070     /**
0071      * Set the authorization identity.
0072      *
0073      * If set, proxy-authentication according to RFC4616 will be used.
0074      *
0075      * Note that this feature only works with the "PLAIN" AuthenticationMode.
0076      *
0077      * The @param authorizationName will be used together with the password() to get authenticated as userName() by the authorization of the provided credentials.
0078      * This allows to login as a user using the admin credentials and the users name.
0079      * @since 4.10
0080      */
0081     void setAuthorizationName(const QString &authorizationName);
0082 
0083     QString password() const;
0084     void setPassword(const QString &password);
0085 
0086     /**
0087      * Returns the server greeting, in case of a successful login.
0088      * If the login wasn't successful, this method returns an empty string. Use errorString() to
0089      * get the error message in this case.
0090      *
0091      * Note that the content of this response is not defined by the IMAP protocol and is
0092      * implementation-dependent.
0093      * @since 4.7
0094      */
0095     QString serverGreeting() const;
0096 
0097     /**
0098      * Set the encryption mode for the connection. In case an encryption mode is set, the caller
0099      * MUST check the encryptionMode() result after executing the job, to see if the connection is
0100      * encrypted or not (e.g handshaking failed).
0101      * @param mode the encryption mode, see EncryptionModes
0102      */
0103     void setEncryptionMode(QSsl::SslProtocol mode, bool startTls = false);
0104 
0105     /**
0106       Get the encryption mode.
0107       @return the currently active encryption mode
0108     */
0109     QSsl::SslProtocol encryptionMode();
0110 
0111     void setAuthenticationMode(AuthenticationMode mode);
0112 
0113 protected:
0114     void doStart() Q_DECL_OVERRIDE;
0115     void handleResponse(const Message &response) Q_DECL_OVERRIDE;
0116     void connectionLost() Q_DECL_OVERRIDE;
0117 
0118 private:
0119     Q_PRIVATE_SLOT(d_func(), void sslResponse(bool))
0120 };
0121 
0122 }
0123 
0124 #endif