clawsmailimportdata.cpp 3.35 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
2
   Copyright (C) 2012-2017 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

Laurent Montel's avatar
Laurent Montel committed
4 5 6 7
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
Laurent Montel's avatar
Laurent Montel committed
8

Laurent Montel's avatar
Laurent Montel committed
9 10 11 12
   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
   General Public License for more details.
Laurent Montel's avatar
Laurent Montel committed
13

Laurent Montel's avatar
Laurent Montel committed
14 15 16 17
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
Laurent Montel's avatar
Laurent Montel committed
18 19
*/

Laurent Montel's avatar
Typo  
Laurent Montel committed
20 21 22
#include "claws-mail/clawsmailimportdata.h"
#include "claws-mail/clawsmailsettings.h"
#include "claws-mail/clawsmailaddressbook.h"
23
#include "mailimporter/filterclawsmail.h"
Laurent Montel's avatar
Laurent Montel committed
24
#include "MailCommon/FilterImporterClawsMail"
Laurent Montel's avatar
Laurent Montel committed
25 26 27 28
#include "mailimporter/filterinfo.h"
#include "importfilterinfogui.h"
#include "importwizard.h"

29
#include <kpluginfactory.h>
Laurent Montel's avatar
Laurent Montel committed
30
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
31 32 33

#include <QDir>

34
K_PLUGIN_FACTORY_WITH_JSON(ClawsMailImporterFactory, "clawsmailimporter.json", registerPlugin<ClawsMailImportData>();)
35 36

ClawsMailImportData::ClawsMailImportData(QObject *parent, const QList<QVariant> &)
Laurent Montel's avatar
Laurent Montel committed
37
    : AbstractImporter(parent)
Laurent Montel's avatar
Laurent Montel committed
38
{
39
    mPath = MailImporter::FilterClawsMail::defaultSettingsPath();
Laurent Montel's avatar
Laurent Montel committed
40 41
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
42
ClawsMailImportData::~ClawsMailImportData()
Laurent Montel's avatar
Laurent Montel committed
43 44 45
{
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
46
bool ClawsMailImportData::foundMailer() const
Laurent Montel's avatar
Laurent Montel committed
47
{
Laurent Montel's avatar
Laurent Montel committed
48 49
    QDir directory(mPath);
    if (directory.exists()) {
50
        return true;
Laurent Montel's avatar
Laurent Montel committed
51
    }
52
    return false;
Laurent Montel's avatar
Laurent Montel committed
53 54
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
55
QString ClawsMailImportData::name() const
Laurent Montel's avatar
Laurent Montel committed
56
{
Laurent Montel's avatar
Laurent Montel committed
57
    return QStringLiteral("Claws Mails");
Laurent Montel's avatar
Laurent Montel committed
58 59
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
60
bool ClawsMailImportData::importMails()
Laurent Montel's avatar
Laurent Montel committed
61
{
62
    MailImporter::FilterClawsMail clawsMail;
Laurent Montel's avatar
Laurent Montel committed
63 64
    initializeFilter(clawsMail);
    clawsMail.filterInfo()->setStatusMessage(i18n("Import in progress"));
65 66
    const QString mailsPath = clawsMail.localMailDirPath();
    QDir directory(mailsPath);
Laurent Montel's avatar
Laurent Montel committed
67
    if (directory.exists()) {
68
        clawsMail.importMails(mailsPath);
Laurent Montel's avatar
Laurent Montel committed
69
    } else {
70
        clawsMail.import();
Laurent Montel's avatar
Laurent Montel committed
71
    }
Laurent Montel's avatar
Laurent Montel committed
72
    clawsMail.filterInfo()->setStatusMessage(i18n("Import finished"));
73
    return true;
Laurent Montel's avatar
Laurent Montel committed
74 75
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
76
bool ClawsMailImportData::importAddressBook()
Laurent Montel's avatar
Laurent Montel committed
77
{
78
    const QDir addressbookDir(mPath + QLatin1String("addrbook/"));
Laurent Montel's avatar
Laurent Montel committed
79
    ClawsMailAddressBook account(addressbookDir, mImportWizard);
80
    account.importAddressBook();
81
    return true;
Laurent Montel's avatar
Laurent Montel committed
82 83
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
84
bool ClawsMailImportData::importSettings()
Laurent Montel's avatar
Laurent Montel committed
85
{
86
    const QString accountFile = mPath + QLatin1String("accountrc");
87
    if (QFileInfo::exists(accountFile)) {
Laurent Montel's avatar
Laurent Montel committed
88
        ClawsMailSettings account(mImportWizard);
89 90 91 92 93
        account.importSettings(accountFile, mPath);
    } else {
        addImportSettingsInfo(i18n("Claws Mail settings not found."));
    }
    return true;
Laurent Montel's avatar
Laurent Montel committed
94 95
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
96
bool ClawsMailImportData::importFilters()
Laurent Montel's avatar
Laurent Montel committed
97
{
98
    const QString filterPath(mPath + QLatin1String("matcherrc"));
Laurent Montel's avatar
Laurent Montel committed
99
    return addFilters(filterPath, MailCommon::FilterImporterExporter::ClawsMailFilter);
Laurent Montel's avatar
Laurent Montel committed
100 101
}

Laurent Montel's avatar
Typo  
Laurent Montel committed
102
AbstractImporter::TypeSupportedOptions ClawsMailImportData::supportedOption()
Laurent Montel's avatar
Laurent Montel committed
103
{
104
    TypeSupportedOptions options;
Laurent Montel's avatar
Laurent Montel committed
105 106 107 108
    options |= AbstractImporter::Mails;
    options |= AbstractImporter::AddressBooks;
    options |= AbstractImporter::Settings;
    options |= AbstractImporter::Filters;
109
    return options;
Laurent Montel's avatar
Laurent Montel committed
110
}
111 112

#include "clawsmailimportdata.moc"