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

0001 /*
0002     SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
0003     SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "kimap_export.h"
0011 
0012 #include "job.h"
0013 
0014 namespace KIMAP
0015 {
0016 class Session;
0017 struct Response;
0018 class LoginJobPrivate;
0019 
0020 class KIMAP_EXPORT LoginJob : public Job
0021 {
0022     Q_OBJECT
0023     Q_DECLARE_PRIVATE(LoginJob)
0024 
0025     friend class SessionPrivate;
0026 
0027 public:
0028     enum EncryptionMode {
0029         Unencrypted = 0,
0030         SSLorTLS, /*!< Use SSL/TLS encryption, KIMAP will automatically negotiate
0031                        the best supported encryption protocol. */
0032         STARTTLS /*!< Use STARTTLS to upgrade an initially plaintext connection to
0033                       encrypted connection. KIMAP will automatically negotiate
0034                       the best supported encryption protocol. */
0035     };
0036     Q_ENUM(EncryptionMode)
0037 
0038     enum AuthenticationMode {
0039         ClearText = 0,
0040         Login,
0041         Plain,
0042         CramMD5,
0043         DigestMD5,
0044         NTLM,
0045         GSSAPI,
0046         Anonymous,
0047         XOAuth2,
0048     };
0049     Q_ENUM(AuthenticationMode)
0050 
0051     enum ErrorCode {
0052         ERR_COULD_NOT_CONNECT = KJob::UserDefinedError + 23 // same as in kio
0053     };
0054 
0055     explicit LoginJob(Session *session);
0056     ~LoginJob() override;
0057 
0058     [[nodiscard]] QString userName() const;
0059     void setUserName(const QString &userName);
0060 
0061     /**
0062      * Get the authorization identity.
0063      * @since 4.10
0064      */
0065     [[nodiscard]] QString authorizationName() const;
0066 
0067     /**
0068      * Set the authorization identity.
0069      *
0070      * If set, proxy-authentication according to RFC4616 will be used.
0071      *
0072      * Note that this feature only works with the "PLAIN" AuthenticationMode.
0073      *
0074      * The @param authorizationName will be used together with the password() to get authenticated as userName() by the authorization of the provided
0075      * credentials. This allows to login as a user using the admin credentials and the users name.
0076      * @since 4.10
0077      */
0078     void setAuthorizationName(const QString &authorizationName);
0079 
0080     [[nodiscard]] QString password() const;
0081     void setPassword(const QString &password);
0082 
0083     /**
0084      * Returns the server greeting, in case of a successful login.
0085      * If the login wasn't successful, this method returns an empty string. Use errorString() to
0086      * get the error message in this case.
0087      *
0088      * Note that the content of this response is not defined by the IMAP protocol and is
0089      * implementation-dependent.
0090      * @since 4.7
0091      */
0092     [[nodiscard]] QString serverGreeting() const;
0093 
0094     /**
0095      * Set the encryption mode for the connection. In case an encryption mode is set, the caller
0096      * MUST check the encryptionMode() result after executing the job, to see if the connection is
0097      * encrypted or not (e.g handshaking failed).
0098      * @param mode the encryption mode, see EncryptionModes
0099      */
0100     void setEncryptionMode(EncryptionMode mode);
0101 
0102     /**
0103       Get the encryption mode.
0104       @return the currently active encryption mode
0105     */
0106     [[nodiscard]] EncryptionMode encryptionMode();
0107 
0108     void setAuthenticationMode(AuthenticationMode mode);
0109 
0110 protected:
0111     void doStart() override;
0112     void handleResponse(const Response &response) override;
0113     void connectionLost() override;
0114 
0115 private:
0116     Q_PRIVATE_SLOT(d_func(), void sslResponse(bool))
0117 };
0118 
0119 }