+

Add support to 'all addresses' Thunderbird condition field

Benjamin Renard [2014-08-25 23:08:12]
Add support to 'all addresses' Thunderbird condition field
Filename
convertFilters
diff --git a/convertFilters b/convertFilters
index 43bd170..f32301d 100755
--- a/convertFilters
+++ b/convertFilters
@@ -50,6 +50,11 @@ parser.add_option('--dont-warn-cc',
                   dest="dontwarncc",
                   help="Don't warn about cc -> to_or_cc convertion",
 		  default=False)
+parser.add_option('--dont-warn-all-addresses',
+                  action="store_true",
+                  dest="dontwarnalladdresses",
+                  help="Don't warn about all addresses -> from + to_or_cc convertion",
+		  default=False)
 parser.add_option('-r',
                   '--replace-accents',
 		  help='Remove accent in folder names',
@@ -115,9 +120,6 @@ for f in tbf:
 			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":
@@ -134,11 +136,36 @@ for f in tbf:
 					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']=='all addresses':
+					if c['cri_operator']=='contains' or c['cri_operator']=='is':
+						# bool operand must be OR
+						if c['bool_operator']=='AND':
+							if len(fc)==1:
+								c['bool_operator']='OR'
+							else:
+								raise Exception('Condition operand "all addresses" with condition operator "%s" and bool operator "AND" supported only if only one condition' % c['cri_operator'])
+					elif c['cri_operator']=="doesn't contain" or c['cri_operator']=="isn't":
+						# bool operand must be AND
+						if c['bool_operator']=='OR':
+							if len(fc)==1:
+								c['bool_operator']='AND'
+							else:
+								raise Exception('Condition operand "all addresses" with condition operator "%s" and bool operator "OR" supported only if only one condition' % c['cri_operator'])
+					sfr.append({
+						'field':	'from',
+						'operator':	r['operator'],
+						'value':	c['value']
+					})
+					if not options.dontwarnalladdresses:
+						logging.warning('Filter %s : Condition operator "all addresses" convert to two filters matching from, to or cc but not bcc field as Thunderbird' % f['name'])
+					r['field']='to_or_cc'
 				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'])
+				if c['bool_operator'] not in bool_ops:
+					bool_ops.append(c['bool_operator'])
 				r['value']=c['value']
 				sfr.append(r)
 			if len(sfr)==0:
ViewGit