summaryrefslogtreecommitdiff
path: root/migrationutility/imapsourceaccount.h
blob: 0777f0dbe7c68961b64ab98836f9e2a9be7225e9 (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
/*
 * Copyright (C) 2012  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef IMAPSOURCEACCOUNT_H
#define IMAPSOURCEACCOUNT_H

#include "sourceaccount.h"

class IMAPSourceAccount: public SourceAccount
{
    Q_OBJECT
public:
    explicit IMAPSourceAccount(QObject* parent = 0);
    virtual ~IMAPSourceAccount();
    virtual QStringList lookupFolderList();
    virtual FetchObjectsJob *fetchObjects(const QString &folder);
    virtual Object convertObject(const Object &object, const QString& folder) const;
    virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);

    /**
     * Prepare the connection for a login attempt.
     */
    void prepareConnection(QString host, qint16 port, const QString &authorizationName, const QString &userName, const QString &password, KIMAP::LoginJob::EncryptionMode encryptionMode, KIMAP::LoginJob::AuthenticationMode authenticationMode);

    KJob *login();
    KJob *logout();
    virtual void recordSuccessfulMigration(const QList<Object> &obj, const QString &folder);

private slots:
    void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags);
    void onSessionStateChanged(KIMAP::Session::State,KIMAP::Session::State);

protected:
    //get namespace
    virtual void init();
    Kolab::FolderType getFolderType(const QString &folder);
    KIMAP::Session *getSession();
    QList<KIMAP::MailBoxDescriptor> mPersonalNamespaces;

private:
    /**
     * Get UIDS of all messages in the folder on the source account
     *
     * This is used to find out which objects to migrate by subtracting already migrated uids from the list.
     */
    QList<qint64> getImapUids(const QString &folder);

    QList<KIMAP::MailBoxDescriptor> mMailboxes;
    KIMAP::Session *mSession;
    QString mHost;
    int mPort;
    QString mUsername;
    QString mAuthorizationName;
    QString mPw;
    KIMAP::LoginJob::EncryptionMode mEncryptionMode;
    KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
};

class FetchIMAPObjectsJob : public FetchObjectsJob
{
    Q_OBJECT
public:
    FetchIMAPObjectsJob(FetchMessagesJob *fetchJob, QObject *parent);
    virtual void start();
    FetchMessagesJob * const mFetchMessagesJob;
private slots:
    void onJobDone(KJob *job);
};


#endif