• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • filter
  • filterimporter
filterimporterclawsmail.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, 2013 Montel Laurent <montel@kde.org>
3 
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.
7 
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.
12 
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
16 */
17 
18 #include "filterimporterclawsmail_p.h"
19 #include "filtermanager.h"
20 #include "mailfilter.h"
21 
22 #include <KConfig>
23 #include <KConfigGroup>
24 
25 #include <KDebug>
26 
27 #include <QFile>
28 
29 using namespace MailCommon;
30 
31 FilterImporterClawsMails::FilterImporterClawsMails( QFile *file )
32  :FilterImporterAbstract()
33 {
34  QTextStream stream(file);
35  MailFilter *filter = 0;
36  while ( !stream.atEnd() ) {
37  QString line = stream.readLine();
38  kDebug() << " line :" << line << " filter " << filter;
39 
40  if (line.isEmpty()) {
41  //Nothing
42  } else if (line.startsWith(QLatin1Char('[')) && line.endsWith(QLatin1Char(']'))) {
43  //TODO
44  } else {
45  appendFilter(filter);
46  filter = parseLine( line );
47  }
48  }
49  appendFilter(filter);
50 }
51 
52 FilterImporterClawsMails::FilterImporterClawsMails(bool interactive)
53  :FilterImporterAbstract(interactive)
54 {
55 }
56 
57 FilterImporterClawsMails::~FilterImporterClawsMails()
58 {
59 }
60 
61 QString FilterImporterClawsMails::defaultFiltersSettingsPath()
62 {
63  return QString::fromLatin1( "%1/.claws-mail/matcherrc" ).arg( QDir::homePath() );
64 }
65 
66 MailFilter * FilterImporterClawsMails::parseLine(const QString &line)
67 {
68  MailFilter *filter = new MailFilter();
69  QString tmp = line;
70  //Enabled ?
71  if (tmp.startsWith(QLatin1String("enabled"))) {
72  filter->setEnabled(true);
73  tmp.remove(QLatin1String("enabled "));
74  }
75 
76  //Filter name
77  if (tmp.startsWith(QLatin1String("rulename")) ) {
78  tmp.remove(QLatin1String("rulename "));
79  int pos;
80  const QString name = extractString(tmp, pos);
81  filter->pattern()->setName( name );
82  filter->setToolbarName( name );
83 
84  tmp = tmp.mid(pos+2); //remove "\" "
85  qDebug()<<" new tmp"<<tmp;
86  }
87 
88  tmp = extractConditions( tmp, filter);
89 
90  tmp = extractActions(tmp, filter);
91  //TODO
92  return filter;
93 }
94 
95 QString FilterImporterClawsMails::extractActions( const QString &line,MailFilter *filter)
96 {
97  return line;
98 }
99 
100 QString FilterImporterClawsMails::extractConditions( const QString &line,MailFilter *filter)
101 {
102  QByteArray fieldName;
103  //Action
104  if (line.startsWith(QLatin1String("subject"))) {
105  fieldName = "subject";
106  } else if (line.startsWith(QLatin1String("age_lower"))) {
107 
108  }
109  filter->pattern()->setOp( SearchPattern::OpAnd );
110  //TODO
111  return QString();
112 }
113 
114 QString FilterImporterClawsMails::extractString( const QString & tmp, int & pos)
115 {
116  QString name;
117  QChar previousChar;
118  int i = 0;
119  for (; i <tmp.length(); ++i) {
120  const QChar currentChar = tmp.at(i);
121  if (i == 0 && (currentChar.isSpace() || currentChar == QLatin1Char('"'))) {
122 
123  } else {
124  if (currentChar != QLatin1Char('"')) {
125  if (currentChar != QLatin1Char('\\')) {
126  name += currentChar;
127  }
128  } else {
129  if (previousChar == QLatin1Char('\\')) {
130  name += currentChar;
131  } else {
132  break;
133  }
134  }
135  previousChar = currentChar;
136  }
137  }
138  pos = i;
139  qDebug()<<" name "<<name;
140  return name;
141 }
142 
MailCommon::FilterImporterClawsMails::parseLine
MailFilter * parseLine(const QString &line)
Definition: filterimporterclawsmail.cpp:66
mailfilter.h
MailCommon::FilterImporterClawsMails::~FilterImporterClawsMails
~FilterImporterClawsMails()
Definition: filterimporterclawsmail.cpp:57
MailCommon::FilterImporterClawsMails::FilterImporterClawsMails
FilterImporterClawsMails(QFile *file)
Definition: filterimporterclawsmail.cpp:31
MailCommon::MailFilter::setToolbarName
void setToolbarName(const QString &toolbarName)
This sets the toolbar name for this filter.
Definition: mailfilter.cpp:338
MailCommon::FilterImporterAbstract
Definition: filterimporterabstract_p.h:33
MailCommon::MailFilter::setEnabled
void setEnabled(bool)
Definition: mailfilter.cpp:739
MailCommon::SearchPattern::OpAnd
Definition: searchpattern.h:606
MailCommon::FilterImporterAbstract::appendFilter
void appendFilter(MailCommon::MailFilter *filter)
Definition: filterimporterabstract.cpp:47
filterimporterclawsmail_p.h
MailCommon::FilterImporterClawsMails::defaultFiltersSettingsPath
static QString defaultFiltersSettingsPath()
Definition: filterimporterclawsmail.cpp:61
MailCommon::SearchPattern::setOp
void setOp(SearchPattern::Operator aOp)
Sets the filter operator.
Definition: searchpattern.h:713
filtermanager.h
MailCommon::MailFilter::pattern
SearchPattern * pattern()
Provides a reference to the internal pattern.
Definition: mailfilter.cpp:182
MailCommon::MailFilter
Definition: mailfilter.h:42
MailCommon::SearchPattern::setName
void setName(const QString &newName)
Sets the name of the search pattern.
Definition: searchpattern.h:697
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal