aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/provider/MCAccountValidator.h
blob: a1d6299f0adb3a4f9b6eb370d98dd7e32fee9af9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
//  MCAccountValidator.h
//  mailcore2
//
//  Created by Christopher Hockley on 22/01/15.
//  Copyright (c) 2015 MailCore. All rights reserved.
//

#ifndef MAILCORE_MCACCOUNTVALIDATOR_H

#define MAILCORE_MCACCOUNTVALIDATOR_H

#include <MailCore/MCBaseTypes.h>

#ifdef __cplusplus

namespace mailcore {

    class NetService;
    class MailProvider;
    class MXRecordResolverOperation;
    class IMAPAsyncSession;
    class POPAsyncSession;
    class SMTPAsyncSession;

    class MAILCORE_EXPORT AccountValidator : public Operation, public OperationCallback, public ConnectionLogger {
    public:
        AccountValidator();
        virtual ~AccountValidator();
        
        virtual void setEmail(String * email);
        virtual String * email(); /* for SMTP */
        virtual void setUsername(String * username);
        virtual String * username();
        virtual void setPassword(String * password);
        virtual String * password();
        virtual void setOAuth2Token(String * OAuth2Token);
        virtual String * OAuth2Token();

        virtual void setImapEnabled(bool enabled);
        virtual bool isImapEnabled();

        virtual void setPopEnabled(bool enabled);
        virtual bool isPopEnabled();

        virtual void setSmtpEnabled(bool enabled);
        virtual bool isSmtpEnabled();

        virtual void setImapServices(Array * imapServices);
        virtual Array * /* NetService */ imapServices();
        virtual void setSmtpServices(Array * smtpServices);
        virtual Array * /* NetService */ smtpServices();
        virtual void setPopServices(Array * popServices);
        virtual Array * /* NetService */ popServices();
        
        virtual void setConnectionLogger(ConnectionLogger * logger);
        virtual ConnectionLogger * connectionLogger();

        // result
        virtual String * identifier();
        virtual NetService * imapServer();
        virtual NetService * popServer();
        virtual NetService * smtpServer();
        virtual ErrorCode imapError();
        virtual ErrorCode popError();
        virtual ErrorCode smtpError();
        virtual String * imapLoginResponse();

        virtual void start();
        virtual void cancel();

    public: // ConnectionLogger
        virtual void log(void * sender, ConnectionLogType logType, Data * buffer);

    private:
        String * mEmail; /* for SMTP */
        String * mUsername;
        String * mPassword;
        String * mOAuth2Token;
        
        Array * /* NetService */ mImapServices;
        Array * /* NetService */ mSmtpServices;
        Array * /* NetService */ mPopServices;
        
        // result
        String * mIdentifier;
        NetService * mImapServer;
        NetService * mPopServer;
        NetService * mSmtpServer;
        ErrorCode mImapError;
        ErrorCode mPopError;
        ErrorCode mSmtpError;
        String * mImapLoginResponse;
        
        MailProvider * mProvider;
        
        //indexs for services being tested
        int mCurrentServiceIndex;
        int mCurrentServiceTested;
        
        Operation * mOperation;
        virtual void operationFinished(Operation * op);
        
        OperationQueue * mQueue;
        MXRecordResolverOperation * mResolveMX;
        
        IMAPAsyncSession * mImapSession;
        POPAsyncSession * mPopSession;
        SMTPAsyncSession * mSmtpSession;

        bool mImapEnabled;
        bool mPopEnabled;
        bool mSmtpEnabled;

        pthread_mutex_t mConnectionLoggerLock;
        ConnectionLogger * mConnectionLogger;

        void init();
        void setupServices();
        void resolveMX();
        void resolveMXDone();
        void resolveMXTimeout(void * context);
        void startCheckingHosts();
        void checkNextHost();
        void checkNextHostDone();
    };
}

#endif

#endif