Add support to 'all addresses' Thunderbird condition field
Benjamin Renard

Benjamin Renard commited on 2014-08-25 23:08:12
Showing 1 changed files, with 30 additions and 3 deletions.

... ...
@@ -50,6 +50,11 @@ parser.add_option('--dont-warn-cc',
50 50
                   dest="dontwarncc",
51 51
                   help="Don't warn about cc -> to_or_cc convertion",
52 52
 		  default=False)
53
+parser.add_option('--dont-warn-all-addresses',
54
+                  action="store_true",
55
+                  dest="dontwarnalladdresses",
56
+                  help="Don't warn about all addresses -> from + to_or_cc convertion",
57
+		  default=False)
53 58
 parser.add_option('-r',
54 59
                   '--replace-accents',
55 60
 		  help='Remove accent in folder names',
... ...
@@ -115,9 +120,6 @@ for f in tbf:
115 120
 			sfr=[]
116 121
 			for c in fc:
117 122
 				r={}
118
-				if c['bool_operator'] not in bool_ops:
119
-					bool_ops.append(c['bool_operator'])
120
-		
121 123
 				if c['cri_operator']=='contains' or c['cri_operator']=='is':
122 124
 					r['operator']=c['cri_operator']
123 125
 				elif c['cri_operator']=="isn't":
... ...
@@ -134,11 +136,36 @@ for f in tbf:
134 136
 					r['field']='to_or_cc'
135 137
 					if not options.dontwarncc:
136 138
 						logging.warning('Filter %s : Condition operator cc convert to to_or_cc' % f['name'])
139
+				elif c['cri_operand']=='all addresses':
140
+					if c['cri_operator']=='contains' or c['cri_operator']=='is':
141
+						# bool operand must be OR
142
+						if c['bool_operator']=='AND':
143
+							if len(fc)==1:
144
+								c['bool_operator']='OR'
145
+							else:
146
+								raise Exception('Condition operand "all addresses" with condition operator "%s" and bool operator "AND" supported only if only one condition' % c['cri_operator'])
147
+					elif c['cri_operator']=="doesn't contain" or c['cri_operator']=="isn't":
148
+						# bool operand must be AND
149
+						if c['bool_operator']=='OR':
150
+							if len(fc)==1:
151
+								c['bool_operator']='AND'
152
+							else:
153
+								raise Exception('Condition operand "all addresses" with condition operator "%s" and bool operator "OR" supported only if only one condition' % c['cri_operator'])
154
+					sfr.append({
155
+						'field':	'from',
156
+						'operator':	r['operator'],
157
+						'value':	c['value']
158
+					})
159
+					if not options.dontwarnalladdresses:
160
+						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'])
161
+					r['field']='to_or_cc'
137 162
 				elif c['cri_operand'].startswith('"') and c['cri_operand'].endswith('"'):
138 163
 					r['field']='header'
139 164
 					r['custom_header']=re.sub('^"(.*)"$',r'\1',c['cri_operand'],count=1)
140 165
 				else:
141 166
 					raise Exception('Condition operand "%s" not recognized. Pass' % c['cri_operand'])
167
+				if c['bool_operator'] not in bool_ops:
168
+					bool_ops.append(c['bool_operator'])
142 169
 				r['value']=c['value']
143 170
 				sfr.append(r)
144 171
 			if len(sfr)==0:
145 172