26 using namespace MailCommon;
31 QTextStream stream(file);
38 QTextStream stream(&
string);
46 void FilterImporterThunderbird::readStream(QTextStream &stream)
49 while ( !stream.atEnd() ) {
50 QString line = stream.readLine();
51 kDebug() <<
" line :" << line <<
" filter " << filter;
52 filter = parseLine( stream, line, filter );
59 return QString::fromLatin1(
"%1/.thunderbird/" ).arg( QDir::homePath() );
66 if ( line.startsWith( QLatin1String(
"name=" ) ) ) {
69 line = cleanArgument( line, QLatin1String(
"name=" ) );
72 }
else if ( line.startsWith( QLatin1String(
"action=" ) ) ) {
73 line = cleanArgument( line, QLatin1String(
"action=" ) );
75 QString actionName = extractActions( line, filter, value );
76 if ( !stream.atEnd() ) {
77 line = stream.readLine();
78 if ( line.startsWith( QLatin1String(
"actionValue=" ) ) ) {
79 value = cleanArgument( line, QLatin1String(
"actionValue=" ) );
81 if (actionName == QLatin1String(
"Change priority")) {
83 lstValue << QLatin1String(
"X-Priority");
84 if (value == QLatin1String(
"Highest")) {
85 value = QLatin1String(
"1 (Highest)");
86 }
else if (value == QLatin1String(
"High")) {
87 value = QLatin1String(
"2 (High)");
88 }
else if (value == QLatin1String(
"Normal")) {
89 value = QLatin1String(
"3 (Normal)");
90 }
else if (value == QLatin1String(
"Low")) {
91 value = QLatin1String(
"4 (Low)");
92 }
else if (value == QLatin1String(
"Lowest")) {
93 value = QLatin1String(
"5 (Lowest)");
96 value = lstValue.join(QLatin1String(
"\t"));
97 actionName = QLatin1String(
"add header");
98 }
else if (actionName == QLatin1String(
"copy") || actionName == QLatin1String(
"transfer")) {
101 QString path = url.path();
102 if (path.startsWith(QLatin1Char(
'/'))) {
111 filter = parseLine( stream, line, filter );
116 }
else if ( line.startsWith( QLatin1String(
"enabled=" ) ) ) {
117 line = cleanArgument( line, QLatin1String(
"enabled=" ) );
118 if ( line == QLatin1String(
"no" ) ) {
121 }
else if ( line.startsWith( QLatin1String(
"condition=" ) ) ) {
122 line = cleanArgument( line, QLatin1String(
"condition=" ) );
123 extractConditions( line, filter );
124 }
else if ( line.startsWith( QLatin1String(
"type=" ) ) ) {
125 line = cleanArgument( line, QLatin1String(
"type=" ) );
126 extractType( line, filter );
127 }
else if ( line.startsWith( QLatin1String(
"version=" ) ) ) {
128 line = cleanArgument( line, QLatin1String(
"version=" ) );
129 if ( line.toInt() != 9 ) {
130 kDebug() <<
" thunderbird filter version different of 9 need to look at if it changed";
132 }
else if ( line.startsWith( QLatin1String(
"logging=" ) ) ) {
133 line = cleanArgument( line, QLatin1String(
"logging=" ) );
134 if ( line == QLatin1String(
"no" ) ) {
136 }
else if ( line == QLatin1String(
"yes" ) ) {
139 kDebug() <<
" Logging option not implemented " << line;
142 kDebug() <<
"unknown tag : " << line;
147 void FilterImporterThunderbird::extractConditions(
const QString &line,
150 if ( line.startsWith( QLatin1String(
"AND" ) ) ) {
152 const QStringList conditionsList = line.split( QLatin1String(
"AND " ) );
153 const int numberOfCond( conditionsList.count() );
154 for (
int i = 0; i < numberOfCond; ++i ) {
155 if ( !conditionsList.at( i ).trimmed().isEmpty() ) {
156 splitConditions( conditionsList.at( i ), filter );
159 }
else if ( line.startsWith( QLatin1String(
"OR" ) ) ) {
161 const QStringList conditionsList = line.split( QLatin1String(
"OR " ) );
162 const int numberOfCond( conditionsList.count() );
163 for (
int i = 0; i < numberOfCond; ++i ) {
164 if ( !conditionsList.at( i ).trimmed().isEmpty() ) {
165 splitConditions( conditionsList.at( i ), filter );
168 }
else if ( line.startsWith( QLatin1String(
"ALL" ) ) ){
171 kDebug() <<
" missing extract condition" << line;
175 bool FilterImporterThunderbird::splitConditions(
const QString &cond,
205 QString str = cond.trimmed();
206 str.remove( QLatin1Char(
'(') );
207 str.remove( str.length() - 1, 1 );
209 const QStringList listOfCond = str.split( QLatin1Char(
',' ) );
210 if ( listOfCond.count() < 3 ) {
211 kDebug() <<
"We have a pb in cond:" << cond;
214 const QString field = listOfCond.at( 0 );
215 const QString
function = listOfCond.at( 1 );
216 const QString contents = listOfCond.at( 2 );
218 QByteArray fieldName;
219 if ( field == QLatin1String(
"subject" ) ) {
220 fieldName =
"subject";
221 }
else if ( field == QLatin1String(
"from" ) ) {
223 }
else if ( field == QLatin1String(
"body" ) ) {
224 fieldName =
"<body>";
225 }
else if ( field == QLatin1String(
"date" ) ) {
226 fieldName =
"<date>";
227 }
else if ( field == QLatin1String(
"priority" ) ) {
229 }
else if ( field == QLatin1String(
"status" ) ) {
230 fieldName =
"<status>";
231 }
else if ( field == QLatin1String(
"to" ) ) {
233 }
else if ( field == QLatin1String(
"cc" ) ) {
235 }
else if ( field == QLatin1String(
"to or cc" ) ) {
236 fieldName =
"<recipients>";
237 }
else if ( field == QLatin1String(
"all addresses" ) ) {
238 fieldName =
"<recipients>";
239 }
else if ( field == QLatin1String(
"age in days" ) ) {
240 fieldName =
"<age in days>";
241 }
else if ( field == QLatin1String(
"label" ) ) {
243 }
else if ( field == QLatin1String(
"tag" ) ) {
245 }
else if ( field == QLatin1String(
"size" ) ) {
246 fieldName =
"<size>";
247 }
else if ( field == QLatin1String(
"from in ab" ) ) {
249 }
else if ( field == QLatin1String(
"junk status" ) ) {
251 }
else if ( field == QLatin1String(
"junk percent" ) ) {
253 }
else if ( field == QLatin1String(
"junk score origin" ) ) {
255 }
else if ( field == QLatin1String(
"has attachment status" ) ) {
259 if ( fieldName.isEmpty() ) {
260 kDebug() <<
" Field not implemented: " << field;
284 if (
function == QLatin1String(
"contains" ) ) {
286 }
else if (
function == QLatin1String(
"doesn't contain" ) ) {
288 }
else if (
function == QLatin1String(
"is" ) ) {
290 }
else if (
function == QLatin1String(
"isn't" ) ) {
292 }
else if (
function == QLatin1String(
"is empty" ) ) {
294 }
else if (
function == QLatin1String(
"isn't empty" ) ) {
296 }
else if (
function == QLatin1String(
"is before" ) ) {
298 }
else if (
function == QLatin1String(
"is after" ) ) {
300 }
else if (
function == QLatin1String(
"is higher than" ) ) {
302 }
else if (
function == QLatin1String(
"is lower than" ) ) {
304 }
else if (
function == QLatin1String(
"begins with" ) ) {
306 }
else if (
function == QLatin1String(
"ends with" ) ) {
308 }
else if (
function == QLatin1String(
"is in ab" ) ) {
310 }
else if (
function == QLatin1String(
"isn't in ab" ) ) {
312 }
else if (
function == QLatin1String(
"is greater than" ) ) {
314 }
else if (
function == QLatin1String(
"is less than" ) ) {
316 }
else if (
function == QLatin1String(
"matches" ) ) {
318 }
else if (
function == QLatin1String(
"doesn't match" ) ) {
323 kDebug() <<
" functionName not implemented: " <<
function;
325 QString contentsName;
326 if ( fieldName ==
"<status>" ) {
327 if ( contents == QLatin1String(
"read" ) ) {
328 contentsName = QLatin1String(
"Read" );
329 }
else if ( contents == QLatin1String(
"unread" ) ) {
330 contentsName = QLatin1String(
"Unread" );
331 }
else if ( contents == QLatin1String(
"new" ) ) {
332 contentsName = QLatin1String(
"New" );
333 }
else if ( contents == QLatin1String(
"forwarded" ) ) {
334 contentsName = QLatin1String(
"Forwarded" );
336 kDebug() <<
" contents for status not implemented " << contents;
338 }
else if ( fieldName ==
"<size>" ) {
339 int value = contents.toInt();
340 value = value * 1024;
341 contentsName = QString::number( value );
342 }
else if ( fieldName ==
"<date>" ) {
343 QLocale locale(QLocale::C);
344 const QDate date = locale.toDate(contents,QString::fromLatin1(
"dd-MMM-yyyy"));
345 contentsName = date.toString(Qt::ISODate);
347 contentsName = contents;
351 filter->
pattern()->append( rule );
357 QString FilterImporterThunderbird::extractActions(
const QString &line,
384 if ( line == QLatin1String(
"Move to folder" ) ) {
385 actionName = QLatin1String(
"transfer" );
386 }
else if ( line == QLatin1String(
"Forward" ) ) {
387 actionName = QLatin1String(
"forward" );
388 }
else if ( line == QLatin1String(
"Mark read" ) ) {
389 actionName = QLatin1String(
"set status" );
390 value = QLatin1String(
"R" );
391 }
else if ( line == QLatin1String(
"Mark unread" ) ) {
392 actionName = QLatin1String(
"set status" );
393 value = QLatin1String(
"U" );
394 }
else if ( line == QLatin1String(
"Copy to folder" ) ) {
395 actionName = QLatin1String(
"copy" );
396 }
else if ( line == QLatin1String(
"AddTag" ) ) {
397 actionName = QLatin1String(
"add tag" );
398 }
else if ( line == QLatin1String(
"Delete" ) ) {
399 actionName = QLatin1String(
"delete" );
400 }
else if ( line == QLatin1String(
"Change priority" ) ) {
401 actionName = QLatin1String(
"Change priority");
402 }
else if ( line == QLatin1String(
"Ignore thread" ) ) {
403 }
else if ( line == QLatin1String(
"Ignore subthread" ) ) {
404 }
else if ( line == QLatin1String(
"Watch thread" ) ) {
405 }
else if ( line == QLatin1String(
"Mark flagged" ) ) {
406 }
else if ( line == QLatin1String(
"Label" ) ) {
407 }
else if ( line == QLatin1String(
"Reply" ) ) {
408 actionName = QLatin1String(
"set Reply-To" );
409 }
else if ( line == QLatin1String(
"Stop execution" ) ) {
412 }
else if ( line == QLatin1String(
"Delete from Pop3 server" ) ) {
413 }
else if ( line == QLatin1String(
"JunkScore" ) ) {
414 }
else if ( line == QLatin1String(
"Fetch body from Pop3Server" ) ) {
415 }
else if ( line == QLatin1String(
"Custom" ) ) {
417 if ( actionName.isEmpty() ) {
418 kDebug() << QString::fromLatin1(
" missing convert method: %1" ).arg( line );
425 const int value = line.toInt();
430 }
else if ( value == 16 ) {
434 }
else if ( value == 17 ) {
438 }
else if ( value == 32 ) {
443 }
else if ( value == 48 ) {
449 kDebug() <<
" type value is not valid :" << value;
453 QString FilterImporterThunderbird::cleanArgument(
const QString &line,
const QString &removeStr )
456 str.remove( removeStr );
457 str.remove( QLatin1String(
"\"" ) );
458 str.remove( str.length(), 1 );
~FilterImporterThunderbird()
void setApplyOnOutbound(bool aApply=true)
Set whether this filter should be applied on outbound messages (aApply == true) or not...
FilterImporterThunderbird(QFile *file, bool interactive=true)
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.
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...
static QString defaultFiltersSettingsPath()
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)