26 using namespace MailCommon;
35 QDomElement filters = doc.documentElement();
37 if ( filters.isNull() ) {
38 kDebug() <<
"No filters defined";
42 for ( QDomElement e = filters.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() ) {
43 const QString tag = e.tagName();
44 if ( tag == QLatin1String(
"rule" ) ) {
47 kDebug() <<
" unknown tag " << tag;
58 return QString::fromLatin1(
"%1/.sylpheed-2.0/filter.xml" ).arg( QDir::homePath() );
63 if ( e.hasAttribute( QLatin1String(
"bool") ) ) {
64 const QString attr = e.attribute( QLatin1String(
"bool") );
65 if ( attr == QLatin1String(
"and" ) ) {
67 }
else if ( attr == QLatin1String(
"or" ) ) {
70 kDebug() <<
" bool not defined: " << attr;
73 for ( QDomElement ruleFilter = e.firstChildElement();
75 ruleFilter = ruleFilter.nextSiblingElement() ) {
80 const QString nexttag = ruleFilter.tagName();
81 if ( nexttag == QLatin1String(
"match-header" ) ){
82 if ( ruleFilter.hasAttribute( QLatin1String(
"name") ) ) {
83 const QString attr = ruleFilter.attribute( QLatin1String(
"name") );
84 if ( attr == QLatin1String(
"From" ) ) {
86 }
else if ( attr == QLatin1String(
"Cc" ) ) {
88 }
else if ( attr == QLatin1String(
"To" ) ) {
90 }
else if ( attr == QLatin1String(
"Reply-To" ) ) {
91 fieldName =
"reply-to";
92 }
else if ( attr == QLatin1String(
"Subject" ) ) {
93 fieldName =
"subject";
94 }
else if ( attr == QLatin1String(
"List-Id" ) ) {
95 fieldName =
"list-id";
96 }
else if ( attr == QLatin1String(
"X-ML-Name" ) ) {
97 fieldName =
"x-mailing-list";
99 if ( fieldName.isEmpty() ) {
100 kDebug()<<
" match-header not implemented " << attr;
103 contentsName = ruleFilter.text();
104 }
else if ( nexttag == QLatin1String(
"match-any-header" ) ) {
105 fieldName =
"<any header>";
106 contentsName = ruleFilter.text();
107 }
else if ( nexttag == QLatin1String(
"match-to-or-cc" ) ) {
108 fieldName =
"<recipients>";
109 contentsName = ruleFilter.text();
110 }
else if ( nexttag == QLatin1String(
"match-body-text" ) ) {
111 fieldName =
"<body>";
112 contentsName = ruleFilter.text();
113 }
else if ( nexttag == QLatin1String(
"command-test" ) ) {
116 }
else if ( nexttag == QLatin1String(
"size" ) ) {
117 fieldName =
"<size>";
118 contentsName = QString::number(ruleFilter.text().toInt()*1024);
119 }
else if ( nexttag == QLatin1String(
"age" ) ) {
120 fieldName =
"<age in days>";
121 contentsName = ruleFilter.text();
122 }
else if ( nexttag == QLatin1String(
"unread" ) ) {
123 fieldName =
"<status>";
124 contentsName = QLatin1String(
"Unread" );
125 }
else if ( nexttag == QLatin1String(
"mark" ) ) {
127 }
else if ( nexttag == QLatin1String(
"color-label" ) ) {
129 }
else if ( nexttag == QLatin1String(
"mime" ) ) {
131 }
else if ( nexttag == QLatin1String(
"account-id" ) ) {
133 }
else if ( nexttag == QLatin1String(
"target-folder" ) ) {
136 kDebug() <<
" tag not recognize " << nexttag;
138 if (fieldName.isEmpty()) {
139 kDebug()<<
" field not implemented "<<nexttag;
142 if ( ruleFilter.hasAttribute( QLatin1String(
"type") ) ) {
143 const QString attr = ruleFilter.attribute( QLatin1String(
"type") );
144 if ( attr == QLatin1String(
"not-contain" ) ) {
146 }
else if ( attr == QLatin1String(
"contains" ) ) {
148 }
else if ( attr == QLatin1String(
"is-not" ) ) {
150 }
else if ( attr == QLatin1String(
"is" ) ) {
152 }
else if ( attr == QLatin1String(
"not-regex" ) ) {
154 }
else if ( attr == QLatin1String(
"regex" ) ) {
156 }
else if ( attr == QLatin1String(
"not-in-addressbook" ) ) {
158 }
else if ( attr == QLatin1String(
"in-addressbook" ) ) {
160 }
else if ( attr == QLatin1String(
"gt" ) ) {
162 }
else if ( attr == QLatin1String(
"lt" ) ) {
165 kDebug() <<
" Attr type not implemented :" << attr;
169 filter->
pattern()->append( rule );
173 void FilterImporterSylpheed::parseActions(
const QDomElement &e,
176 for ( QDomElement ruleFilter = e.firstChildElement();
177 !ruleFilter.isNull();
178 ruleFilter = ruleFilter.nextSiblingElement() ) {
180 const QString nexttag = ruleFilter.tagName();
181 QString value = ruleFilter.text();
182 if ( nexttag == QLatin1String(
"move" ) ){
183 actionName = QLatin1String(
"transfer" );
184 value = ruleFilter.text();
185 }
else if ( nexttag == QLatin1String(
"copy" ) ) {
186 actionName = QLatin1String(
"copy" );
187 value = ruleFilter.text();
188 }
else if ( nexttag == QLatin1String(
"not-receive" ) ) {
190 }
else if ( nexttag == QLatin1String(
"delete" ) ) {
191 actionName = QLatin1String(
"delete" );
192 }
else if ( nexttag == QLatin1String(
"exec" ) ) {
193 actionName = QLatin1String(
"execute" );
194 value = ruleFilter.text();
195 }
else if ( nexttag == QLatin1String(
"exec-async" ) ) {
196 actionName = QLatin1String(
"filter app" );
197 value = ruleFilter.text();
198 }
else if ( nexttag == QLatin1String(
"mark" ) ) {
200 }
else if ( nexttag == QLatin1String(
"color-label" ) ) {
202 }
else if ( nexttag == QLatin1String(
"mark-as-read" ) ) {
203 actionName = QLatin1String(
"set status" );
204 value = QLatin1String(
"R" );
205 }
else if ( nexttag == QLatin1String(
"forward" ) ) {
206 actionName = QLatin1String(
"forward" );
207 value = ruleFilter.text();
208 }
else if ( nexttag == QLatin1String(
"forward-as-attachment" ) ) {
210 }
else if ( nexttag == QLatin1String(
"redirect" ) ) {
211 actionName = QLatin1String(
"redirect" );
212 value = ruleFilter.text();
213 }
else if ( nexttag == QLatin1String(
"stop-eval" ) ) {
218 if ( actionName.isEmpty() ) {
219 kDebug() <<
" tag not recognize " << nexttag;
225 void FilterImporterSylpheed::parseFilters(
const QDomElement &e )
228 if ( e.hasAttribute( QLatin1String(
"enabled") ) ) {
229 const QString attr = e.attribute( QLatin1String(
"enabled") );
230 if ( attr == QLatin1String(
"false" ) ) {
235 if ( e.hasAttribute( QLatin1String(
"name") ) ) {
236 const QString attr = e.attribute( QLatin1String(
"name") );
241 if ( e.hasAttribute( QLatin1String(
"timing") ) ) {
242 const QString attr = e.attribute( QLatin1String(
"timing") );
243 if ( attr == QLatin1String(
"any" ) ) {
246 }
else if ( attr == QLatin1String(
"receiver" ) ) {
248 }
else if ( attr == QLatin1String(
"manual" ) ) {
252 kDebug() <<
" timing not defined: " << attr;
256 for ( QDomElement ruleFilter = e.firstChildElement();
257 !ruleFilter.isNull();
258 ruleFilter = ruleFilter.nextSiblingElement() ) {
259 const QString nexttag = ruleFilter.tagName();
260 if ( nexttag == QLatin1String(
"condition-list" ) ){
261 parseConditions( ruleFilter, filter );
262 }
else if ( nexttag == QLatin1String(
"action-list" ) ) {
263 parseActions( ruleFilter, filter );
265 kDebug() <<
" next tag not implemented " << nexttag;
static QString defaultFiltersSettingsPath()
boost::shared_ptr< SearchRule > Ptr
Defines a pointer to a search rule.
~FilterImporterSylpheed()
void setStopProcessingHere(bool aStop)
Function
Describes operators for comparison of field and contents.
void setToolbarName(const QString &toolbarName)
This sets the toolbar name for this filter.
void appendFilter(MailCommon::MailFilter *filter)
void setOp(SearchPattern::Operator aOp)
Sets the filter operator.
bool loadDomElement(QDomDocument &doc, QFile *file)
void setApplyOnExplicit(bool aApply=true)
Set whether this filter should be applied on explicit (CTRL-J) filtering (aApply == true) or not...
void setApplyOnInbound(bool aApply=true)
Set whether this filter should be applied on inbound messages (aApply == true) or not...
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...
SearchPattern * pattern()
Provides a reference to the internal pattern.
void setName(const QString &newName)
Sets the name of the search pattern.
void createFilterAction(MailCommon::MailFilter *filter, const QString &actionName, const QString &value)
FilterImporterSylpheed(QFile *file)