MailImporter

filterclawsmail.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7/* based on filter_sylpheed filter */
8
9#include "filterclawsmail.h"
10
11#include "mailimporter_debug.h"
12#include <KLocalizedString>
13#include <QDomDocument>
14#include <QDomElement>
15
16using namespace MailImporter;
17
18/** Default constructor. */
21{
22 setName(i18n("Import Claws-mail Maildirs and Folder Structure"));
23 setAuthor(QStringLiteral("Laurent Montel"));
24 setInfo(
25 i18n("<p><b>Claws-mail import filter</b></p>"
26 "<p>Select the base directory of the Claws-mail mailfolder you want to import "
27 "(usually: ~/Mail ).</p>"
28 "<p>Since it is possible to recreate the folder structure, the folders "
29 "will be stored under: \"ClawsMail-Import\" in your local folder.</p>"
30 "<p>This filter also recreates the status of message, e.g. new or forwarded.</p>"));
31}
32
33/** Destructor. */
37
38QString FilterClawsMail::isMailerFound()
39{
40 QDir directory(FilterClawsMail::defaultSettingsPath());
41 if (directory.exists()) {
42 return i18nc("name of clawsMail application", "ClawsMail");
43 }
44 return {};
45}
46
47QString FilterClawsMail::defaultSettingsPath()
48{
49 return QDir::homePath() + QLatin1StringView("/.claws-mail/");
50}
51
52QString FilterClawsMail::localMailDirPath()
53{
54 QFile folderListFile(FilterClawsMail::defaultSettingsPath() + QLatin1StringView("/folderlist.xml"));
55 if (folderListFile.exists()) {
56 QDomDocument doc;
57 if (!folderListFile.open(QIODevice::ReadOnly)) {
58 qCWarning(MAILIMPORTER_LOG) << "Impossible to open " << folderListFile.fileName();
59 }
60 const QDomDocument::ParseResult parseResult = doc.setContent(&folderListFile);
61 if (!parseResult) {
62 qCDebug(MAILIMPORTER_LOG) << "Unable to load document.Parse error in line " << parseResult.errorLine << ", col " << parseResult.errorColumn << ": "
63 << qPrintable(parseResult.errorMessage);
64 return QString();
65 }
66 QDomElement settings = doc.documentElement();
67
68 if (settings.isNull()) {
69 return QString();
70 }
71
72 for (QDomElement e = settings.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
73 if (e.tagName() == QLatin1StringView("folder")) {
74 if (e.hasAttribute(QStringLiteral("type"))) {
75 if (e.attribute(QStringLiteral("type")) == QLatin1StringView("mh")) {
76 return QDir::homePath() + QLatin1Char('/') + e.attribute(QStringLiteral("path"));
77 }
78 }
79 }
80 }
81 }
82 return QString();
83}
84
85bool FilterClawsMail::excludeFile(const QString &file)
86{
87 if (file.endsWith(QLatin1StringView(".claws_cache")) || file.endsWith(QLatin1StringView(".claws_mark"))
88 || file.endsWith(QLatin1StringView(".mh_sequences"))) {
89 return true;
90 }
91 return false;
92}
93
94QString FilterClawsMail::defaultInstallFolder() const
95{
96 return i18nc("define folder name where we will import clawsmail mails", "ClawsMail-Import") + QLatin1Char('/');
97}
98
99QString FilterClawsMail::markFile() const
100{
101 return QStringLiteral(".claws_mark");
102}
FilterClawsMail()
Default constructor.
~FilterClawsMail() override
Destructor.
Imports Sylpheed mail folder with maildir format recursively, recreating the folder structure.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString homePath()
QDomElement documentElement() const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.