+

Add support to 'ALL' Thunderbird condition

Benjamin Renard [2014-08-25 22:34:38]
Add support to 'ALL' Thunderbird condition
Filename
convertFilters
diff --git a/convertFilters b/convertFilters
index 2f28431..0e92802 100755
--- a/convertFilters
+++ b/convertFilters
@@ -106,49 +106,53 @@ for f in tbf:
 			logging.error('Thunderbird filter does not have name ! Pass this filter : %s' % f)
 			continue
 		sf['name']=f['name']
-		fc=thunderbirdFilters.convert_conditions(f["condition"])
-		bool_ops=[]
-		sfr=[]
-		for c in fc:
-			r={}
-			if c['bool_operator'] not in bool_ops:
-				bool_ops.append(c['bool_operator'])

-			if c['cri_operator']=='contains' or c['cri_operator']=='is':
-				r['operator']=c['cri_operator']
-			elif c['cri_operator']=="isn't":
-				r['operator']='is_not'
-			else:
-				raise Exception('Condition operator "%s" not recognized. Pass' % c['cri_operator'])
-			if c['cri_operand'] in ['subject','to','from']:
-				r['field']=c['cri_operand']
-			elif c['cri_operand']=='cc':
-				r['field']='to_or_cc'
-				if not options.dontwarncc:
-					logging.warning('Filter %s : Condition operator cc convert to to_or_cc' % f['name'])
-			elif c['cri_operand'].startswith('"') and c['cri_operand'].endswith('"'):
-				r['field']='header'
-				r['custom_header']=re.sub('^"(.*)"$',r'\1',c['cri_operand'],count=1)
-			else:
-				raise Exception('Condition operand "%s" not recognized. Pass' % c['cri_operand'])
-			r['value']=c['value']
-			sfr.append(r)
-		if len(sfr)==0:
-			logging.error('Filter %s : No condition found ! Pass this filter' % f['name'])
-			continue
-		sf['rules']=sfr
-
-		if len(bool_ops)==1:
-			if bool_ops[0]=='AND':
-				sf['match']='all'
-			elif bool_ops[0]=='OR':
-				sf['match']='any'
+		if f["condition"]=='ALL':
+			sf['match']='allmessages'
+		else:
+			fc=thunderbirdFilters.convert_conditions(f["condition"])
+			bool_ops=[]
+			sfr=[]
+			for c in fc:
+				r={}
+				if c['bool_operator'] not in bool_ops:
+					bool_ops.append(c['bool_operator'])
+
+				if c['cri_operator']=='contains' or c['cri_operator']=='is':
+					r['operator']=c['cri_operator']
+				elif c['cri_operator']=="isn't":
+					r['operator']='is_not'
+				else:
+					raise Exception('Condition operator "%s" not recognized. Pass' % c['cri_operator'])
+				if c['cri_operand'] in ['subject','to','from']:
+					r['field']=c['cri_operand']
+				elif c['cri_operand']=='cc':
+					r['field']='to_or_cc'
+					if not options.dontwarncc:
+						logging.warning('Filter %s : Condition operator cc convert to to_or_cc' % f['name'])
+				elif c['cri_operand'].startswith('"') and c['cri_operand'].endswith('"'):
+					r['field']='header'
+					r['custom_header']=re.sub('^"(.*)"$',r'\1',c['cri_operand'],count=1)
+				else:
+					raise Exception('Condition operand "%s" not recognized. Pass' % c['cri_operand'])
+				r['value']=c['value']
+				sfr.append(r)
+			if len(sfr)==0:
+				logging.error('Filter %s : No condition found ! Pass this filter' % f['name'])
+				continue
+			sf['rules']=sfr
+
+			if len(bool_ops)==1:
+				if bool_ops[0]=='AND':
+					sf['match']='all'
+				elif bool_ops[0]=='OR':
+					sf['match']='any'
+				else:
+					logging.error("Filter %s : Boolean operator not recognized %s, pass this filter." % (f['name'],bool_ops[0]))
+					continue
 			else:
-				logging.error("Filter %s : Boolean operator not recognized %s, pass this filter." % (f['name'],bool_ops[0]))
+				logging.error('Filter %s : Multiple boolean operator not supported (%s). Pass this filter.' % (f['name'],','.join(bool_ops)))
 				continue
-		else:
-			logging.error('Filter %s : Multiple boolean operator not supported (%s). Pass this filter.' % (f['name'],','.join(bool_ops)))
-			continue
 		sfa=[]
 		for a in f['actions']:
 			if a[0]=='Move to folder':
ViewGit