26 using namespace MailCommon;
36 QDomElement filters = doc.documentElement();
38 if ( filters.isNull() ) {
39 kDebug() <<
"No filters defined";
42 filters = filters.firstChildElement( QLatin1String(
"ruleset") );
43 for ( QDomElement e = filters.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() ) {
44 const QString tag = e.tagName();
45 if ( tag == QLatin1String(
"rule" ) ) {
48 kDebug() <<
" unknown tag " << tag;
59 return QString::fromLatin1(
"%1/.config/evolution/mail/filters.xml" ).arg( QDir::homePath() );
62 void FilterImporterEvolution::parsePartAction(
const QDomElement &ruleFilter,
66 for ( QDomElement partFilter = ruleFilter.firstChildElement();
68 partFilter = partFilter.nextSiblingElement() ) {
69 const QString nexttag = partFilter.tagName();
70 if ( nexttag == QLatin1String(
"part" ) ) {
71 if ( partFilter.hasAttribute( QLatin1String(
"name") ) ) {
72 const QString name = partFilter.attribute( QLatin1String(
"name") );
73 kDebug() <<
" parsePartAction name attribute :" << name;
74 if ( type == FilterImporterEvolution::PartType ) {
77 if ( name == QLatin1String(
"to" ) ) {
79 }
else if ( name == QLatin1String(
"sender" ) ) {
81 }
else if ( name == QLatin1String(
"cc" ) ) {
83 }
else if ( name == QLatin1String(
"bcc" ) ) {
86 }
else if ( name == QLatin1String(
"senderto" ) ) {
88 }
else if ( name == QLatin1String(
"subject" ) ) {
89 fieldName =
"subject";
90 }
else if ( name == QLatin1String(
"header" ) ) {
91 fieldName =
"<any header>";
92 }
else if ( name == QLatin1String(
"body" ) ) {
94 }
else if ( name == QLatin1String(
"sexp" ) ) {
96 }
else if ( name == QLatin1String(
"sent-date" ) ) {
98 }
else if ( name == QLatin1String(
"recv-date" ) ) {
100 }
else if ( name == QLatin1String(
"label" ) ) {
102 }
else if ( name == QLatin1String(
"score" ) ) {
104 }
else if ( name == QLatin1String(
"size" ) ) {
105 fieldName =
"<size>";
106 }
else if ( name == QLatin1String(
"status" ) ) {
107 fieldName =
"<status>";
108 }
else if ( name == QLatin1String(
"follow-up" ) ) {
110 }
else if ( name == QLatin1String(
"completed-on" ) ) {
112 }
else if ( name == QLatin1String(
"attachments" ) ) {
114 }
else if ( name == QLatin1String(
"mlist" ) ) {
115 fieldName =
"list-id";
116 }
else if ( name == QLatin1String(
"regex" ) ) {
118 }
else if ( name == QLatin1String(
"source" ) ) {
120 }
else if ( name == QLatin1String(
"pipe" ) ) {
122 }
else if ( name == QLatin1String(
"junk" ) ) {
124 }
else if ( name == QLatin1String(
"all" ) ) {
128 kDebug() <<
" parttype part : name : not implemented :" << name;
130 if (fieldName.isEmpty()) {
131 kDebug()<<
" parttype part : name : not implemented :" << name;
137 for ( QDomElement valueFilter = partFilter.firstChildElement();
138 !valueFilter.isNull();
139 valueFilter = valueFilter.nextSiblingElement() ) {
140 const QString valueTag = valueFilter.tagName();
142 if ( valueTag == QLatin1String(
"value" ) ) {
144 if ( valueFilter.hasAttribute( QLatin1String(
"name") ) ) {
145 const QString name = valueFilter.attribute( QLatin1String(
"name") );
146 if (name==QLatin1String(
"flag")) {
148 const QString flag = valueFilter.attribute( QLatin1String(
"value") );
149 kDebug()<<
" flag :"<<flag;
150 if (flag==QLatin1String(
"Seen")) {
151 contents = QLatin1String(
"Read");
152 }
else if (flag==QLatin1String(
"Answered")) {
153 contents = QLatin1String(
"Sent");
154 }
else if (flag==QLatin1String(
"Draft")) {
156 }
else if (flag==QLatin1String(
"Flagged")) {
157 contents = QLatin1String(
"Important");
158 }
else if (flag==QLatin1String(
"Junk")) {
159 contents = QLatin1String(
"Spam");
161 kDebug()<<
" unknown status flags "<<flag;
164 kDebug() <<
" value filter name :" << name;
166 if ( valueFilter.hasAttribute( QLatin1String(
"type") ) ) {
167 const QString name = valueFilter.attribute( QLatin1String(
"type") );
168 if ( name == QLatin1String(
"option" ) ){
170 }
else if ( name == QLatin1String(
"string" ) ) {
171 QDomElement
string = valueFilter.firstChildElement();
172 contents =
string.text();
173 }
else if ( name == QLatin1String(
"folder" ) ) {
174 QDomElement folder = valueFilter.firstChildElement();
175 if ( folder.hasAttribute( QLatin1String(
"uri") ) ) {
176 contents = folder.attribute( QLatin1String(
"uri") );
177 if ( !contents.isEmpty() ) {
178 contents.remove( QLatin1String(
"folder://" ) );
181 }
else if ( name == QLatin1String(
"address" ) ) {
182 QDomElement address = valueFilter.firstChildElement();
183 contents = address.text();
184 }
else if ( name == QLatin1String(
"integer" ) ) {
185 if ( valueFilter.hasAttribute( QLatin1String(
"integer") ) ) {
186 contents = valueFilter.attribute( QLatin1String(
"integer") );
187 int val = contents.toInt();
189 contents = QString::number(val);
192 kDebug() <<
" type not implemented " << name;
196 if ( valueFilter.hasAttribute( QLatin1String(
"value") ) ) {
197 const QString value = valueFilter.attribute( QLatin1String(
"value") );
198 kDebug() <<
" value filter value :" << name;
199 if ( value == QLatin1String(
"contains" ) ) {
201 }
else if ( value == QLatin1String(
"not contains" ) ) {
203 }
else if ( value == QLatin1String(
"is not" ) ) {
205 }
else if ( value == QLatin1String(
"is" ) ) {
207 }
else if ( value == QLatin1String(
"exist" ) ) {
209 }
else if ( value == QLatin1String(
"not exist" ) ) {
211 }
else if ( value == QLatin1String(
"not starts with" ) ) {
213 }
else if ( value == QLatin1String(
"ends with" ) ) {
215 }
else if ( value == QLatin1String(
"not ends with" ) ) {
217 }
else if ( value == QLatin1String(
"matches soundex" ) ) {
219 }
else if ( value == QLatin1String(
"not match soundex" ) ) {
221 }
else if ( value == QLatin1String(
"before" ) ) {
223 }
else if ( value == QLatin1String(
"after" ) ) {
225 }
else if ( value == QLatin1String(
"greater-than" ) ) {
227 }
else if ( value == QLatin1String(
"less-than" ) ) {
229 }
else if ( value == QLatin1String(
"starts with" ) ) {
236 filter->
pattern()->append( rule );
238 }
else if ( type == FilterImporterEvolution::ActionType ) {
240 if ( name == QLatin1String(
"stop" ) ) {
243 }
else if ( name == QLatin1String(
"move-to-folder" ) ) {
244 actionName = QLatin1String(
"transfer" );
245 }
else if ( name == QLatin1String(
"copy-to-folder" ) ) {
246 actionName = QLatin1String(
"copy" );
247 }
else if ( name == QLatin1String(
"delete" ) ) {
248 actionName = QLatin1String(
"delete" );
249 }
else if ( name == QLatin1String(
"label" ) ) {
251 }
else if ( name == QLatin1String(
"colour" ) ) {
253 }
else if ( name == QLatin1String(
"score" ) ) {
255 }
else if ( name == QLatin1String(
"adj-score" ) ) {
257 }
else if ( name == QLatin1String(
"set-status" ) ) {
258 actionName = QLatin1String(
"set status" );
259 }
else if ( name == QLatin1String(
"unset-status" ) ) {
260 actionName = QLatin1String(
"unset status" );
261 }
else if ( name == QLatin1String(
"beep" ) ) {
262 actionName = QLatin1String(
"beep" );
263 }
else if ( name == QLatin1String(
"play-sound" ) ) {
264 actionName = QLatin1String(
"play sound" );
265 }
else if ( name == QLatin1String(
"shell" ) ) {
266 actionName = QLatin1String(
"execute" );
267 }
else if ( name == QLatin1String(
"pipe" ) ) {
268 actionName = QLatin1String(
"filter app" );
269 }
else if ( name == QLatin1String(
"forward" ) ) {
270 actionName = QLatin1String(
"forward" );
272 if ( actionName.isEmpty() ){
273 kDebug() <<
" actiontype part : name : not implemented :" << name;
276 for ( QDomElement valueFilter = partFilter.firstChildElement();
277 !valueFilter.isNull();
278 valueFilter = valueFilter.nextSiblingElement() ) {
279 const QString valueTag = valueFilter.tagName();
280 if ( valueTag == QLatin1String(
"value" ) ) {
281 if ( valueFilter.hasAttribute( QLatin1String(
"name") ) ) {
282 const QString name = valueFilter.attribute( QLatin1String(
"name") );
283 kDebug() <<
" value filter name :" << name;
285 if ( valueFilter.hasAttribute( QLatin1String(
"type") ) ) {
286 const QString name = valueFilter.attribute( QLatin1String(
"type" ));
287 kDebug() <<
" value filter type :" << name;
288 if ( name == QLatin1String(
"option" ) ){
290 }
else if ( name == QLatin1String(
"string" ) ) {
292 }
else if ( name == QLatin1String(
"folder" ) ) {
293 QDomElement folder = valueFilter.firstChildElement();
295 if ( folder.hasAttribute( QLatin1String(
"uri") ) ) {
296 value = folder.attribute( QLatin1String(
"uri") );
297 if ( !value.isEmpty() ) {
298 value.remove( QLatin1String(
"folder://" ) );
300 kDebug() <<
" contents folder :" << value;
302 }
else if ( name == QLatin1String(
"address" ) ) {
307 if ( valueFilter.hasAttribute( QLatin1String(
"value") ) ) {
308 const QString name = valueFilter.attribute( QLatin1String(
"value") );
309 kDebug() <<
" value filter value :" << name;
310 if ( value == QLatin1String(
"contains" ) ) {
323 void FilterImporterEvolution::parseFilters(
const QDomElement &e )
326 if ( e.hasAttribute( QLatin1String(
"enabled") ) ) {
327 const QString attr = e.attribute( QLatin1String(
"enabled") );
328 if ( attr == QLatin1String(
"false" ) ) {
333 if ( e.hasAttribute( QLatin1String(
"grouping") ) ) {
334 const QString attr = e.attribute( QLatin1String(
"grouping") );
335 if ( attr == QLatin1String(
"all" ) ) {
337 }
else if ( attr == QLatin1String(
"any" ) ) {
340 kDebug() <<
" grouping not implemented: " << attr;
345 if ( e.hasAttribute( QLatin1String(
"source") ) ) {
346 const QString attr = e.attribute( QLatin1String(
"source") );
347 if ( attr == QLatin1String(
"incoming" ) ) {
349 }
else if ( attr == QLatin1String(
"outgoing" ) ) {
353 kDebug() <<
" source not implemented :" << attr;
356 for ( QDomElement ruleFilter = e.firstChildElement();
357 !ruleFilter.isNull();
358 ruleFilter = ruleFilter.nextSiblingElement() )
360 const QString nexttag = ruleFilter.tagName();
361 if ( nexttag == QLatin1String(
"title" ) ) {
364 }
else if ( nexttag == QLatin1String(
"partset" ) ) {
365 parsePartAction ( ruleFilter, filter, PartType );
366 }
else if ( nexttag == QLatin1String(
"actionset" ) ) {
367 parsePartAction( ruleFilter, filter, ActionType );
369 kDebug() <<
" tag not implemented : " << nexttag;
~FilterImporterEvolution()
void setApplyOnOutbound(bool aApply=true)
Set whether this filter should be applied on outbound messages (aApply == true) or not...
boost::shared_ptr< SearchRule > Ptr
Defines a pointer to a search rule.
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)
static QString defaultFiltersSettingsPath()
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...
FilterImporterEvolution(QFile *file)
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)