french -> French
[kdepim.git] / mailimporter / filter_clawsmail.cpp
blobd440f33759659aa44004549cf1ea7baa828da66d
1 /*
2 Copyright (c) 2012 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 /* based on filter_sylpheed filter */
20 #include "filter_clawsmail.h"
22 #include <klocale.h>
23 #include <kfiledialog.h>
24 #include <kdebug.h>
25 #include <QDomDocument>
26 #include <QDomElement>
28 using namespace MailImporter;
30 /** Default constructor. */
31 FilterClawsMail::FilterClawsMail() : FilterSylpheed()
33 setName(i18n( "Import Claws-mail Maildirs and Folder Structure" ));
34 setAuthor("Laurent Montel");
35 setInfo(i18n("<p><b>Claws-mail import filter</b></p>"
36 "<p>Select the base directory of the Claws-mail mailfolder you want to import "
37 "(usually: ~/Mail ).</p>"
38 "<p>Since it is possible to recreate the folder structure, the folders "
39 "will be stored under: \"ClawsMail-Import\" in your local folder.</p>"
40 "<p>This filter also recreates the status of message, e.g. new or forwarded.</p>"));
43 /** Destructor. */
44 FilterClawsMail::~FilterClawsMail()
48 QString FilterClawsMail::defaultSettingsPath()
50 return QDir::homePath() + QLatin1String( "/.claws-mail/" );
53 QString FilterClawsMail::localMailDirPath()
55 QFile folderListFile( FilterClawsMail::defaultSettingsPath() + QLatin1String( "/folderlist.xml" ) );
56 if ( folderListFile.exists() ) {
57 QDomDocument doc;
58 QString errorMsg;
59 int errorRow;
60 int errorCol;
61 if ( !doc.setContent( &folderListFile, &errorMsg, &errorRow, &errorCol ) ) {
62 kDebug() << "Unable to load document.Parse error in line " << errorRow
63 << ", col " << errorCol << ": " << errorMsg;
64 return QString();
66 QDomElement settings = doc.documentElement();
68 if ( settings.isNull() ) {
69 return QString();
72 for ( QDomElement e = settings.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() ) {
73 if ( e.tagName() == QLatin1String( "folder" ) ) {
74 if ( e.hasAttribute( "type" ) ) {
75 if ( e.attribute( "type" ) == QLatin1String( "mh" ) ) {
76 return QDir::homePath() + QDir::separator() + e.attribute("path" );
82 return QString();
85 bool FilterClawsMail::excludeFile(const QString &file)
87 if(file.endsWith(QLatin1String(".claws_cache")) ||
88 file.endsWith(QLatin1String(".claws_mark")) ||
89 file.endsWith(QLatin1String(".mh_sequences")) ) {
90 return true;
92 return false;
95 QString FilterClawsMail::defaultInstallFolder() const
97 return i18nc("define folder name where we will import clawsmail mails", "ClawsMail-Import") + QLatin1Char('/');
100 QString FilterClawsMail::markFile() const
102 return QString::fromLatin1(".claws_mark");