• 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
filterimporterprocmail.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 "filterimporterprocmail_p.h"
19 
20 #include "filtermanager.h"
21 #include "mailfilter.h"
22 
23 #include <KDebug>
24 
25 #include <QFile>
26 
27 using namespace MailCommon;
28 
29 FilterImporterProcmail::FilterImporterProcmail( QFile *file )
30  :FilterImporterAbstract(), mFilterCount( 0 )
31 {
32  QTextStream stream(file);
33  MailFilter *filter = 0;
34  while ( !stream.atEnd() ) {
35  QString line = stream.readLine();
36  kDebug() << " line :" << line << " filter " << filter;
37  filter = parseLine( stream, line, filter );
38  }
39 
40  appendFilter(filter);
41 }
42 
43 FilterImporterProcmail::~FilterImporterProcmail()
44 {
45 }
46 
47 QString FilterImporterProcmail::defaultFiltersSettingsPath()
48 {
49  return QDir::homePath();
50 }
51 
52 QString FilterImporterProcmail::createUniqFilterName()
53 {
54  return QString::fromLatin1( "Procmail filter %1" ).arg( mFilterCount++ );
55 }
56 
57 MailCommon::MailFilter *FilterImporterProcmail::parseLine( QTextStream &stream,
58  QString line,
59  MailCommon::MailFilter *filter )
60 {
61  Q_UNUSED( stream );
62  if ( line.isEmpty() ) {
63  //Empty line
64  return filter;
65  } else if ( line.startsWith( QLatin1Char( '#' ) ) ){
66  //Commented line
67  return filter;
68  } else if ( line.startsWith( QLatin1String( ":0" ) ) ) {
69  appendFilter(filter);
70  filter = new MailFilter();
71  const QString uniqName = createUniqFilterName();
72  filter->pattern()->setName( uniqName );
73  filter->setToolbarName( uniqName );
74 
75  } else if ( line.startsWith( QLatin1String( "* " ) ) ) {
76  line.remove( 0, 2 );
77  QByteArray fieldName;
78  SearchRule::Function functionName = SearchRule::FuncRegExp;
79  if ( line.startsWith( QLatin1String( "^From:" ) ) ) {
80  line.remove( QLatin1String( "^From:" ) );
81  fieldName = "from";
82  } else if ( line.startsWith( QLatin1String( "^Subject:" ) ) ) {
83  line.remove( QLatin1String( "^Subject:" ) );
84  fieldName = "subject";
85  } else if ( line.startsWith( QLatin1String( "^Sender:" ) ) ) {
86  line.remove( QLatin1String( "^Sender:" ) );
87  } else if ( line.startsWith( QLatin1String( "^(To|Cc):" ) ) ) {
88  line.remove( QLatin1String( "^(To|Cc):" ) );
89  fieldName = "<recipients>";
90  } else {
91  kDebug()<<" line condition not parsed :"<<line;
92  }
93  SearchRule::Ptr rule = SearchRule::createInstance( fieldName, functionName, line );
94  filter->pattern()->append( rule );
95  //Condition
96  } else if ( line.startsWith( QLatin1Char( '!' ) ) ) {
97  line.remove( QLatin1Char( '!' ) );
98  //Redirect email
99  } else if ( line.startsWith( QLatin1Char( '|' ) ) ) {
100  //Shell
101  const QString actionName( QLatin1String( "execute" ) );
102  const QString value( line );
103  createFilterAction( filter, actionName, value );
104  } else if ( line.startsWith( QLatin1Char( '{' ) ) ) {
105  //Block
106  } else if ( line.startsWith( QLatin1Char( '}' ) ) ) {
107  //End block
108  } else {
109  const QString actionName( QLatin1String( "transfer" ) );
110  const QString value( line );
111  createFilterAction( filter, actionName, value );
112  //Folder
113  }
114 
115 
116  return filter;
117 }
MailCommon::FilterImporterProcmail::defaultFiltersSettingsPath
static QString defaultFiltersSettingsPath()
Definition: filterimporterprocmail.cpp:47
MailCommon::FilterImporterProcmail::FilterImporterProcmail
FilterImporterProcmail(QFile *file)
Definition: filterimporterprocmail.cpp:29
mailfilter.h
MailCommon::SearchRule::Ptr
boost::shared_ptr< SearchRule > Ptr
Defines a pointer to a search rule.
Definition: searchpattern.h:69
MailCommon::FilterImporterProcmail::~FilterImporterProcmail
~FilterImporterProcmail()
Definition: filterimporterprocmail.cpp:43
MailCommon::SearchRule::Function
Function
Describes operators for comparison of field and contents.
Definition: searchpattern.h:80
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
filterimporterprocmail_p.h
MailCommon::SearchRule::FuncRegExp
Definition: searchpattern.h:86
MailCommon::FilterImporterAbstract::appendFilter
void appendFilter(MailCommon::MailFilter *filter)
Definition: filterimporterabstract.cpp:47
MailCommon::SearchRule::createInstance
static SearchRule::Ptr createInstance(const QByteArray &field=0, Function function=FuncContains, const QString &contents=QString())
Creates a new search rule of a certain type by instantiating the appropriate subclass depending on th...
Definition: searchpattern.cpp:140
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
MailCommon::FilterImporterAbstract::createFilterAction
void createFilterAction(MailCommon::MailFilter *filter, const QString &actionName, const QString &value)
Definition: filterimporterabstract.cpp:64
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