|
@@ -0,0 +1,759 @@
|
|
1
|
+from bs4 import BeautifulSoup
|
|
2
|
+from nose.tools import raises
|
|
3
|
+
|
|
4
|
+from tracim.lib.email_processing.checkers import HtmlMailQuoteChecker
|
|
5
|
+from tracim.lib.email_processing.checkers import HtmlMailSignatureChecker
|
|
6
|
+from tracim.lib.email_processing.parser import ParsedHTMLMail
|
|
7
|
+from tracim.lib.email_processing.models import BodyMailPartType
|
|
8
|
+from tracim.lib.email_processing.models import BodyMailPart
|
|
9
|
+from tracim.lib.email_processing.models import BodyMailParts
|
|
10
|
+from tracim.tests import TestStandard
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+class TestHtmlMailQuoteChecker(TestStandard):
|
|
14
|
+ def test_unit__is_standard_quote_ok(self):
|
|
15
|
+ soup = BeautifulSoup('<blockquote></blockquote>', 'html.parser')
|
|
16
|
+ main_elem = soup.find()
|
|
17
|
+ assert HtmlMailQuoteChecker._is_standard_quote(main_elem) is True
|
|
18
|
+
|
|
19
|
+ def test_unit__is_standard_quote_no(self):
|
|
20
|
+ soup = BeautifulSoup('<a></a>', 'html.parser')
|
|
21
|
+ main_elem = soup.find()
|
|
22
|
+ assert HtmlMailQuoteChecker._is_standard_quote(main_elem) is False
|
|
23
|
+
|
|
24
|
+ def test_unit__is_thunderbird_quote_ok(self):
|
|
25
|
+ soup = BeautifulSoup('<div class="moz-cite-prefix"></div>',
|
|
26
|
+ 'html.parser')
|
|
27
|
+ main_elem = soup.find()
|
|
28
|
+ assert HtmlMailQuoteChecker._is_thunderbird_quote(main_elem) is True
|
|
29
|
+
|
|
30
|
+ def test_unit__is_thunderbird_quote_no(self):
|
|
31
|
+ soup = BeautifulSoup('<div class="nothing"></div>', 'html.parser')
|
|
32
|
+ main_elem = soup.find()
|
|
33
|
+ assert HtmlMailQuoteChecker._is_thunderbird_quote(main_elem) is False
|
|
34
|
+
|
|
35
|
+ def test_unit__is_gmail_quote_ok(self):
|
|
36
|
+ html = '<div class="gmail_extra">' + \
|
|
37
|
+ '<a></a><div class="gmail_quote"></div>' + \
|
|
38
|
+ '</div>'
|
|
39
|
+ soup = BeautifulSoup(html, 'html.parser')
|
|
40
|
+ main_elem = soup.find()
|
|
41
|
+ assert HtmlMailQuoteChecker._is_gmail_quote(main_elem) is True
|
|
42
|
+
|
|
43
|
+ def test_unit__is_gmail_quote_no(self):
|
|
44
|
+ soup = BeautifulSoup('<div class="nothing"></div>', 'html.parser')
|
|
45
|
+ main_elem = soup.find()
|
|
46
|
+ assert HtmlMailQuoteChecker._is_gmail_quote(main_elem) is False
|
|
47
|
+
|
|
48
|
+ def test_unit__is_gmail_quote_no_2(self):
|
|
49
|
+ html = '<div class="gmail_extra">' + \
|
|
50
|
+ '<a></a><div class="gmail_signature"></div>' + \
|
|
51
|
+ '</div>'
|
|
52
|
+ soup = BeautifulSoup(html, 'html.parser')
|
|
53
|
+ main_elem = soup.find()
|
|
54
|
+ assert HtmlMailQuoteChecker._is_gmail_quote(main_elem) is False
|
|
55
|
+
|
|
56
|
+ def test_unit__is_outlook_com_quote_ok(self):
|
|
57
|
+ soup = BeautifulSoup('<div id="divRplyFwdMsg"></div>', 'html.parser')
|
|
58
|
+ main_elem = soup.find()
|
|
59
|
+ assert HtmlMailQuoteChecker._is_outlook_com_quote(main_elem) is True
|
|
60
|
+
|
|
61
|
+ def test_unit__is_outlook_com_quote_no(self):
|
|
62
|
+ soup = BeautifulSoup('<div id="Signature"></div>', 'html.parser')
|
|
63
|
+ main_elem = soup.find()
|
|
64
|
+ assert HtmlMailQuoteChecker._is_outlook_com_quote(main_elem) is False
|
|
65
|
+
|
|
66
|
+ # TODO - G.M - 2017-11-24 - Check Yahoo and New roundcube html mail with
|
|
67
|
+ # correct mail example
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+class TestHtmlMailSignatureChecker(TestStandard):
|
|
71
|
+ def test_unit__is_thunderbird_signature_ok(self):
|
|
72
|
+ soup = BeautifulSoup('<div class="moz-signature"></div>', 'html.parser')
|
|
73
|
+ main_elem = soup.find()
|
|
74
|
+ assert HtmlMailSignatureChecker._is_thunderbird_signature(main_elem) is True # nopep8
|
|
75
|
+
|
|
76
|
+ def test_unit__is_thunderbird_signature_no(self):
|
|
77
|
+ soup = BeautifulSoup('<div class="other"></div>', 'html.parser')
|
|
78
|
+ main_elem = soup.find()
|
|
79
|
+ assert HtmlMailSignatureChecker._is_thunderbird_signature(main_elem) is False # nopep8
|
|
80
|
+
|
|
81
|
+ def test_unit__is_gmail_signature_ok(self):
|
|
82
|
+ html = '<div class="gmail_extra">' + \
|
|
83
|
+ '<a></a><div class="gmail_quote"></div>' + \
|
|
84
|
+ '</div>'
|
|
85
|
+ soup = BeautifulSoup(html, 'html.parser')
|
|
86
|
+ main_elem = soup.find()
|
|
87
|
+ assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is False
|
|
88
|
+
|
|
89
|
+ def test_unit__is_gmail_signature_no(self):
|
|
90
|
+ soup = BeautifulSoup('<div class="nothing"></div>', 'html.parser')
|
|
91
|
+ main_elem = soup.find()
|
|
92
|
+ assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is False
|
|
93
|
+
|
|
94
|
+ def test_unit__is_gmail_signature_yes(self):
|
|
95
|
+ html = '<div class="gmail_extra">' + \
|
|
96
|
+ '<a></a><div class="gmail_signature"></div>' + \
|
|
97
|
+ '</div>'
|
|
98
|
+ soup = BeautifulSoup(html, 'html.parser')
|
|
99
|
+ main_elem = soup.find()
|
|
100
|
+ assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is True
|
|
101
|
+
|
|
102
|
+ def test_unit__is_gmail_signature_yes_2(self):
|
|
103
|
+ html = '<div class="gmail_signature">' + \
|
|
104
|
+ '</div>'
|
|
105
|
+ soup = BeautifulSoup(html, 'html.parser')
|
|
106
|
+ main_elem = soup.find()
|
|
107
|
+ assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is True
|
|
108
|
+
|
|
109
|
+ def test_unit__is_outlook_com_signature_no(self):
|
|
110
|
+ soup = BeautifulSoup('<div id="divRplyFwdMsg"></div>', 'html.parser')
|
|
111
|
+ main_elem = soup.find()
|
|
112
|
+ assert HtmlMailSignatureChecker._is_outlook_com_signature(main_elem) \
|
|
113
|
+ is False
|
|
114
|
+
|
|
115
|
+ def test_unit__is_outlook_com_signature_ok(self):
|
|
116
|
+ soup = BeautifulSoup('<div id="Signature"></div>', 'html.parser')
|
|
117
|
+ main_elem = soup.find()
|
|
118
|
+ assert HtmlMailSignatureChecker._is_outlook_com_signature(main_elem) \
|
|
119
|
+ is True
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+class TestBodyMailsParts(TestStandard):
|
|
123
|
+
|
|
124
|
+ def test_unit__std_list_methods(self):
|
|
125
|
+ mail_parts = BodyMailParts()
|
|
126
|
+ assert len(mail_parts) == 0
|
|
127
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
128
|
+ mail_parts._list.append(a)
|
|
129
|
+ assert len(mail_parts) == 1
|
|
130
|
+ assert mail_parts[0] == a
|
|
131
|
+ del mail_parts[0]
|
|
132
|
+ assert len(mail_parts) == 0
|
|
133
|
+
|
|
134
|
+ def test_unit__append_same_type(self):
|
|
135
|
+ mail_parts = BodyMailParts()
|
|
136
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
137
|
+ mail_parts._append(a)
|
|
138
|
+ b = BodyMailPart('b', BodyMailPartType.Main)
|
|
139
|
+ mail_parts._append(b)
|
|
140
|
+ assert len(mail_parts) == 1
|
|
141
|
+ assert mail_parts[0].part_type == BodyMailPartType.Main
|
|
142
|
+ assert mail_parts[0].text == 'ab'
|
|
143
|
+
|
|
144
|
+ def test_unit__append_different_type(self):
|
|
145
|
+ mail_parts = BodyMailParts()
|
|
146
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
147
|
+ mail_parts.append(a)
|
|
148
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
149
|
+ mail_parts._append(b)
|
|
150
|
+ assert len(mail_parts) == 2
|
|
151
|
+ assert mail_parts[0] == a
|
|
152
|
+ assert mail_parts[1] == b
|
|
153
|
+
|
|
154
|
+ def test_unit__append_follow(self):
|
|
155
|
+ mail_parts = BodyMailParts()
|
|
156
|
+ mail_parts.follow = True
|
|
157
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
158
|
+ mail_parts._append(a)
|
|
159
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
160
|
+ mail_parts._append(b)
|
|
161
|
+ assert len(mail_parts) == 1
|
|
162
|
+ assert mail_parts[0].part_type == BodyMailPartType.Main
|
|
163
|
+ assert mail_parts[0].text == 'ab'
|
|
164
|
+
|
|
165
|
+ def test_unit__append_dont_follow_when_first(self):
|
|
166
|
+ mail_parts = BodyMailParts()
|
|
167
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
168
|
+ mail_parts._append(a, follow=True)
|
|
169
|
+ assert len(mail_parts) == 1
|
|
170
|
+ assert mail_parts[0].part_type == BodyMailPartType.Main
|
|
171
|
+ assert mail_parts[0].text == 'a'
|
|
172
|
+
|
|
173
|
+ @raises(TypeError)
|
|
174
|
+ def test_unit__check_value__type_error(self):
|
|
175
|
+ mail_parts = BodyMailParts()
|
|
176
|
+ mail_parts._check_value('a')
|
|
177
|
+
|
|
178
|
+ def test_unit__check_value__ok(self):
|
|
179
|
+ mail_parts = BodyMailParts()
|
|
180
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
181
|
+ mail_parts._check_value(a)
|
|
182
|
+
|
|
183
|
+ def test_unit__drop_part_type(self):
|
|
184
|
+ mail_parts = BodyMailParts()
|
|
185
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
186
|
+ mail_parts._list.append(a)
|
|
187
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
188
|
+ mail_parts._list.append(b)
|
|
189
|
+ c = BodyMailPart('c', BodyMailPartType.Signature)
|
|
190
|
+ mail_parts._list.append(c)
|
|
191
|
+ mail_parts.drop_part_type(BodyMailPartType.Quote)
|
|
192
|
+ assert len(mail_parts) == 2
|
|
193
|
+ assert mail_parts[0].text == 'a'
|
|
194
|
+ assert mail_parts[0].part_type == BodyMailPartType.Main
|
|
195
|
+ assert len(mail_parts) == 2
|
|
196
|
+ assert mail_parts[1].text == 'c'
|
|
197
|
+ assert mail_parts[1].part_type == BodyMailPartType.Signature
|
|
198
|
+
|
|
199
|
+ def test_unit__drop_part_type_verify_no_follow_incidence(self):
|
|
200
|
+ mail_parts = BodyMailParts()
|
|
201
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
202
|
+ mail_parts._list.append(a)
|
|
203
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
204
|
+ mail_parts._list.append(b)
|
|
205
|
+ c = BodyMailPart('c', BodyMailPartType.Signature)
|
|
206
|
+ mail_parts._list.append(c)
|
|
207
|
+ mail_parts.follow = True
|
|
208
|
+ mail_parts.drop_part_type(BodyMailPartType.Quote)
|
|
209
|
+ assert len(mail_parts) == 2
|
|
210
|
+ assert mail_parts[0].text == 'a'
|
|
211
|
+ assert mail_parts[0].part_type == BodyMailPartType.Main
|
|
212
|
+ assert len(mail_parts) == 2
|
|
213
|
+ assert mail_parts[1].text == 'c'
|
|
214
|
+ assert mail_parts[1].part_type == BodyMailPartType.Signature
|
|
215
|
+
|
|
216
|
+ def test_unit__drop_part_type_consistence(self):
|
|
217
|
+ mail_parts = BodyMailParts()
|
|
218
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
219
|
+ mail_parts._list.append(a)
|
|
220
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
221
|
+ mail_parts._list.append(b)
|
|
222
|
+ c = BodyMailPart('c', BodyMailPartType.Main)
|
|
223
|
+ mail_parts._list.append(c)
|
|
224
|
+ mail_parts.drop_part_type(BodyMailPartType.Quote)
|
|
225
|
+ assert len(mail_parts) == 1
|
|
226
|
+ assert mail_parts[0].text == 'ac'
|
|
227
|
+ assert mail_parts[0].part_type == BodyMailPartType.Main
|
|
228
|
+
|
|
229
|
+ def test_unit__get_nb_part_type(self):
|
|
230
|
+ mail_parts = BodyMailParts()
|
|
231
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 0
|
|
232
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 0
|
|
233
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Signature) == 0
|
|
234
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
235
|
+ mail_parts._list.append(a)
|
|
236
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 1
|
|
237
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
238
|
+ mail_parts._list.append(b)
|
|
239
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 1
|
|
240
|
+ c = BodyMailPart('c', BodyMailPartType.Signature)
|
|
241
|
+ mail_parts._list.append(c)
|
|
242
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 1
|
|
243
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 1
|
|
244
|
+ assert mail_parts.get_nb_part_type(BodyMailPartType.Signature) == 1
|
|
245
|
+
|
|
246
|
+ def test_unit__str(self):
|
|
247
|
+ mail_parts = BodyMailParts()
|
|
248
|
+ a = BodyMailPart('a', BodyMailPartType.Main)
|
|
249
|
+ mail_parts._list.append(a)
|
|
250
|
+ b = BodyMailPart('b', BodyMailPartType.Quote)
|
|
251
|
+ mail_parts._list.append(b)
|
|
252
|
+ c = BodyMailPart('c', BodyMailPartType.Signature)
|
|
253
|
+ mail_parts._list.append(c)
|
|
254
|
+ assert str(mail_parts) == 'abc'
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+class TestParsedMail(TestStandard):
|
|
258
|
+
|
|
259
|
+ def test_other__check_gmail_mail_text_only(self):
|
|
260
|
+ text_only = '''<div dir="ltr">Voici le texte<br></div>'''
|
|
261
|
+ mail = ParsedHTMLMail(text_only)
|
|
262
|
+ elements = mail.get_elements()
|
|
263
|
+ assert len(elements) == 1
|
|
264
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
265
|
+
|
|
266
|
+ def test_other__check_gmail_mail_text_signature(self):
|
|
267
|
+ text_and_signature = '''
|
|
268
|
+ <div dir="ltr">POF<br clear="all"><div><br>-- <br>
|
|
269
|
+ <div class="gmail_signature" data-smartmail="gmail_signature">
|
|
270
|
+ <div dir="ltr">Voici Ma signature. En HTML <br><ol>
|
|
271
|
+ <li>Plop</li>
|
|
272
|
+ <li>Plip</li>
|
|
273
|
+ <li>Plop<br>
|
|
274
|
+ </li></ol></div></div></div></div>
|
|
275
|
+ '''
|
|
276
|
+ mail = ParsedHTMLMail(text_and_signature)
|
|
277
|
+ elements = mail.get_elements()
|
|
278
|
+ assert len(elements) == 2
|
|
279
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
280
|
+ assert elements[1].part_type == BodyMailPartType.Signature
|
|
281
|
+
|
|
282
|
+ def test_other__check_gmail_mail_text_quote(self):
|
|
283
|
+ text_and_quote = '''
|
|
284
|
+ <div dir="ltr">Réponse<br>
|
|
285
|
+ <div class="gmail_extra"><br>
|
|
286
|
+ <div class="gmail_quote">Le 28 novembre 2017 à 10:29, John Doe <span
|
|
287
|
+ dir="ltr"><<a href="mailto:bidule@localhost.fr"
|
|
288
|
+ target="_blank">bidule@localhost.fr</a>></span>
|
|
289
|
+ a écrit :<br>
|
|
290
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
291
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma réponse<br>
|
|
292
|
+ <br><br>
|
|
293
|
+ Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
|
|
294
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
295
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">
|
|
296
|
+ Voici le texte<span class="HOEnZb"><font color="#888888"><br>
|
|
297
|
+ </font></span></blockquote>
|
|
298
|
+ <span class="HOEnZb"><font color="#888888">
|
|
299
|
+ <br>
|
|
300
|
+ -- <br>
|
|
301
|
+ TEST DE signature<br>
|
|
302
|
+ </font></span></blockquote>
|
|
303
|
+ </div><br></div></div>
|
|
304
|
+ '''
|
|
305
|
+ mail = ParsedHTMLMail(text_and_quote)
|
|
306
|
+ elements = mail.get_elements()
|
|
307
|
+ assert len(elements) == 2
|
|
308
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
309
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
310
|
+
|
|
311
|
+ def test_other__check_gmail_mail_text_quote_text(self):
|
|
312
|
+ text_quote_text = '''
|
|
313
|
+ <div dir="ltr">Avant<br>
|
|
314
|
+ <div class="gmail_extra"><br>
|
|
315
|
+ <div class="gmail_quote">Le 28 novembre 2017 à 10:29, John Doe
|
|
316
|
+ <span dir="ltr"><<a href="mailto:bidule@localhost.fr"
|
|
317
|
+ target="_blank">bidule@localhost.fr</a>></span>
|
|
318
|
+ a écrit :<br>
|
|
319
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
320
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma
|
|
321
|
+ réponse<br>
|
|
322
|
+ <br>
|
|
323
|
+ <br>
|
|
324
|
+ Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
|
|
325
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
326
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">
|
|
327
|
+ Voici le texte<span class="HOEnZb"><font color="#888888"><br>
|
|
328
|
+ </font></span></blockquote>
|
|
329
|
+ <span class="HOEnZb"><font color="#888888">
|
|
330
|
+ <br>
|
|
331
|
+ -- <br>
|
|
332
|
+ TEST DE signature<br>
|
|
333
|
+ </font></span></blockquote>
|
|
334
|
+ </div>
|
|
335
|
+ <br>
|
|
336
|
+ </div>
|
|
337
|
+ <div class="gmail_extra">Aprés<br>
|
|
338
|
+ </div>
|
|
339
|
+ </div>
|
|
340
|
+ '''
|
|
341
|
+
|
|
342
|
+ mail = ParsedHTMLMail(text_quote_text)
|
|
343
|
+ elements = mail.get_elements()
|
|
344
|
+ assert len(elements) == 3
|
|
345
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
346
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
347
|
+ assert elements[2].part_type == BodyMailPartType.Main
|
|
348
|
+
|
|
349
|
+ def test_other__check_gmail_mail_text_quote_signature(self):
|
|
350
|
+ text_quote_signature = '''
|
|
351
|
+ <div dir="ltr">Hey !<br>
|
|
352
|
+ </div>
|
|
353
|
+ <div class="gmail_extra"><br>
|
|
354
|
+ <div class="gmail_quote">Le 28 novembre 2017 à 10:29,
|
|
355
|
+ John Doe <span
|
|
356
|
+ dir="ltr"><<a href="mailto:bidule@localhost.fr"
|
|
357
|
+ target="_blank">bidule@localhost.fr</a>></span>
|
|
358
|
+ a écrit :<br>
|
|
359
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
360
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma
|
|
361
|
+ réponse<br>
|
|
362
|
+ <br>
|
|
363
|
+ <br>
|
|
364
|
+ Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
|
|
365
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
366
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">
|
|
367
|
+ Voici le texte<span class="HOEnZb"><font color="#888888"><br>
|
|
368
|
+ </font></span></blockquote>
|
|
369
|
+ <span class="HOEnZb"><font color="#888888">
|
|
370
|
+ <br>
|
|
371
|
+ -- <br>
|
|
372
|
+ TEST DE signature<br>
|
|
373
|
+ </font></span></blockquote>
|
|
374
|
+ </div>
|
|
375
|
+ <br>
|
|
376
|
+ <br clear="all">
|
|
377
|
+ <br>
|
|
378
|
+ -- <br>
|
|
379
|
+ <div class="gmail_signature" data-smartmail="gmail_signature">
|
|
380
|
+ <div dir="ltr">Voici Ma signature. En HTML <br>
|
|
381
|
+ <ol>
|
|
382
|
+ <li>Plop</li>
|
|
383
|
+ <li>Plip</li>
|
|
384
|
+ <li>Plop<br>
|
|
385
|
+ </li>
|
|
386
|
+ </ol>
|
|
387
|
+ </div>
|
|
388
|
+ </div>
|
|
389
|
+ </div>
|
|
390
|
+ '''
|
|
391
|
+
|
|
392
|
+ # INFO - G.M - 2017-11-28 -
|
|
393
|
+ # Now Quote + Signature block in Gmail is considered as one Quote
|
|
394
|
+ # Block.
|
|
395
|
+ mail = ParsedHTMLMail(text_quote_signature)
|
|
396
|
+ elements = mail.get_elements()
|
|
397
|
+ assert len(elements) == 2
|
|
398
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
399
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
400
|
+
|
|
401
|
+ def test_other__check_gmail_mail_text_quote_text_signature(self):
|
|
402
|
+ text_quote_text_sign = '''
|
|
403
|
+ <div dir="ltr">Test<br>
|
|
404
|
+ <div class="gmail_extra"><br>
|
|
405
|
+ <div class="gmail_quote">Le 28 novembre 2017 à 10:29, John Doe <span
|
|
406
|
+ dir="ltr"><<a href="mailto:bidule@localhost.fr"
|
|
407
|
+ target="_blank">bidule@localhost.fr</a>></span>
|
|
408
|
+ a écrit :<br>
|
|
409
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
410
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma
|
|
411
|
+ réponse<br>
|
|
412
|
+ <br>
|
|
413
|
+ <br>
|
|
414
|
+ Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
|
|
415
|
+ <blockquote class="gmail_quote" style="margin:0 0 0
|
|
416
|
+ .8ex;border-left:1px #ccc solid;padding-left:1ex">
|
|
417
|
+ Voici le texte<span class="HOEnZb"><font color="#888888"><br>
|
|
418
|
+ </font></span></blockquote>
|
|
419
|
+ <span class="HOEnZb"><font color="#888888">
|
|
420
|
+ <br>
|
|
421
|
+ -- <br>
|
|
422
|
+ TEST DE signature<br>
|
|
423
|
+ </font></span></blockquote>
|
|
424
|
+ </div>
|
|
425
|
+ <br>
|
|
426
|
+ <br>
|
|
427
|
+ </div>
|
|
428
|
+ <div class="gmail_extra">RE test<br clear="all">
|
|
429
|
+ </div>
|
|
430
|
+ <div class="gmail_extra"><br>
|
|
431
|
+ -- <br>
|
|
432
|
+ <div class="gmail_signature" data-smartmail="gmail_signature">
|
|
433
|
+ <div dir="ltr">Voici Ma signature. En HTML <br>
|
|
434
|
+ <ol>
|
|
435
|
+ <li>Plop</li>
|
|
436
|
+ <li>Plip</li>
|
|
437
|
+ <li>Plop<br>
|
|
438
|
+ </li>
|
|
439
|
+ </ol>
|
|
440
|
+ </div>
|
|
441
|
+ </div>
|
|
442
|
+ </div>
|
|
443
|
+ </div>
|
|
444
|
+ '''
|
|
445
|
+
|
|
446
|
+ mail = ParsedHTMLMail(text_quote_text_sign)
|
|
447
|
+ elements = mail.get_elements()
|
|
448
|
+ assert len(elements) == 4
|
|
449
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
450
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
451
|
+ assert elements[2].part_type == BodyMailPartType.Main
|
|
452
|
+ assert elements[3].part_type == BodyMailPartType.Signature
|
|
453
|
+
|
|
454
|
+ def test_other__check_thunderbird_mail_text_only(self):
|
|
455
|
+
|
|
456
|
+ text_only = '''Coucou<br><br><br>'''
|
|
457
|
+ mail = ParsedHTMLMail(text_only)
|
|
458
|
+ elements = mail.get_elements()
|
|
459
|
+ assert len(elements) == 1
|
|
460
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
461
|
+
|
|
462
|
+ def test_other__check_thunderbird_mail_text_signature(self):
|
|
463
|
+ text_and_signature = '''
|
|
464
|
+ <p>Test<br>
|
|
465
|
+ </p>
|
|
466
|
+ <div class="moz-signature">-- <br>
|
|
467
|
+ TEST DE signature</div>
|
|
468
|
+ '''
|
|
469
|
+ mail = ParsedHTMLMail(text_and_signature)
|
|
470
|
+ elements = mail.get_elements()
|
|
471
|
+ assert len(elements) == 2
|
|
472
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
473
|
+ assert elements[1].part_type == BodyMailPartType.Signature
|
|
474
|
+
|
|
475
|
+ def test_other__check_thunderbird_mail_text_quote(self):
|
|
476
|
+ text_and_quote = '''
|
|
477
|
+ <p>Pof<br>
|
|
478
|
+ </p>
|
|
479
|
+ <br>
|
|
480
|
+ <div class="moz-cite-prefix">Le 28/11/2017 à 11:21, John Doe a
|
|
481
|
+ écrit :<br>
|
|
482
|
+ </div>
|
|
483
|
+ <blockquote type="cite"
|
|
484
|
+ cite="mid:658592c1-14de-2958-5187-3571edea0aac@localhost.fr">
|
|
485
|
+ <meta http-equiv="Context-Type"
|
|
486
|
+ content="text/html; charset=utf-8">
|
|
487
|
+ <p>Test<br>
|
|
488
|
+ </p>
|
|
489
|
+ <div class="moz-signature">-- <br>
|
|
490
|
+ TEST DE signature</div>
|
|
491
|
+ </blockquote>
|
|
492
|
+ <br>
|
|
493
|
+ '''
|
|
494
|
+ mail = ParsedHTMLMail(text_and_quote)
|
|
495
|
+ elements = mail.get_elements()
|
|
496
|
+ assert len(elements) == 2
|
|
497
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
498
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
499
|
+
|
|
500
|
+ def test_other__check_thunderbird_mail_text_quote_text(self):
|
|
501
|
+ text_quote_text = '''
|
|
502
|
+ <p>Pof<br>
|
|
503
|
+ </p>
|
|
504
|
+ <br>
|
|
505
|
+ <div class="moz-cite-prefix">Le 28/11/2017 à 11:54,
|
|
506
|
+ Bidule a
|
|
507
|
+ écrit :<br>
|
|
508
|
+ </div>
|
|
509
|
+ <blockquote type="cite"
|
|
510
|
+ cite="mid:b541b451-bb31-77a4-45b9-ad89969d7962@localhost.fr">
|
|
511
|
+ <meta http-equiv="Context-Type"
|
|
512
|
+ content="text/html; charset=utf-8">
|
|
513
|
+ <p>Pof<br>
|
|
514
|
+ </p>
|
|
515
|
+ <br>
|
|
516
|
+ <div class="moz-cite-prefix">Le 28/11/2017 à 11:21, John Doe a
|
|
517
|
+ écrit :<br>
|
|
518
|
+ </div>
|
|
519
|
+ <blockquote type="cite"
|
|
520
|
+ cite="mid:658592c1-14de-2958-5187-3571edea0aac@localhost.fr">
|
|
521
|
+ <p>Test<br>
|
|
522
|
+ </p>
|
|
523
|
+ <div class="moz-signature">-- <br>
|
|
524
|
+ TEST DE signature</div>
|
|
525
|
+ </blockquote>
|
|
526
|
+ <br>
|
|
527
|
+ </blockquote>
|
|
528
|
+ Pif<br>
|
|
529
|
+ '''
|
|
530
|
+
|
|
531
|
+ mail = ParsedHTMLMail(text_quote_text)
|
|
532
|
+ elements = mail.get_elements()
|
|
533
|
+ assert len(elements) == 3
|
|
534
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
535
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
536
|
+ assert elements[2].part_type == BodyMailPartType.Main
|
|
537
|
+
|
|
538
|
+ def test_other__check_thunderbird_mail_text_quote_signature(self):
|
|
539
|
+ text_quote_signature = '''
|
|
540
|
+ <p>Coucou<br>
|
|
541
|
+ </p>
|
|
542
|
+ <br>
|
|
543
|
+ <div class="moz-cite-prefix">Le 28/11/2017 à 11:22, Bidule a
|
|
544
|
+ écrit :<br>
|
|
545
|
+ </div>
|
|
546
|
+ <blockquote type="cite"
|
|
547
|
+ cite="mid:4e6923e2-796d-eccf-84b7-6824da4151ee@localhost.fr">Réponse<br>
|
|
548
|
+ <br>
|
|
549
|
+ Le 28/11/2017 à 11:21, John Doe a écrit : <br>
|
|
550
|
+ <blockquote type="cite"> <br>
|
|
551
|
+ Test <br>
|
|
552
|
+ <br>
|
|
553
|
+ -- <br>
|
|
554
|
+ TEST DE signature <br>
|
|
555
|
+ </blockquote>
|
|
556
|
+ <br>
|
|
557
|
+ </blockquote>
|
|
558
|
+ <br>
|
|
559
|
+ <div class="moz-signature">-- <br>
|
|
560
|
+ TEST DE signature</div>
|
|
561
|
+ '''
|
|
562
|
+
|
|
563
|
+ mail = ParsedHTMLMail(text_quote_signature)
|
|
564
|
+ elements = mail.get_elements()
|
|
565
|
+ assert len(elements) == 3
|
|
566
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
567
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
568
|
+ assert elements[2].part_type == BodyMailPartType.Signature
|
|
569
|
+
|
|
570
|
+ def test_other__check_thunderbird_mail_text_quote_text_signature(self):
|
|
571
|
+ text_quote_text_sign = '''
|
|
572
|
+ <p>Avant<br>
|
|
573
|
+ </p>
|
|
574
|
+ <br>
|
|
575
|
+ <div class="moz-cite-prefix">Le 28/11/2017 à 11:19, Bidule a
|
|
576
|
+ écrit :<br>
|
|
577
|
+ </div>
|
|
578
|
+ <blockquote type="cite"
|
|
579
|
+ cite="mid:635df73c-d3c9-f2e9-2304-24ff536bfa16@localhost.fr">Coucou
|
|
580
|
+ <br><br>
|
|
581
|
+ </blockquote>
|
|
582
|
+ Aprés<br>
|
|
583
|
+ <br>
|
|
584
|
+ <div class="moz-signature">-- <br>
|
|
585
|
+ TEST DE signature</div>
|
|
586
|
+ '''
|
|
587
|
+
|
|
588
|
+ mail = ParsedHTMLMail(text_quote_text_sign)
|
|
589
|
+ elements = mail.get_elements()
|
|
590
|
+ assert len(elements) == 4
|
|
591
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
592
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
593
|
+ assert elements[2].part_type == BodyMailPartType.Main
|
|
594
|
+ assert elements[3].part_type == BodyMailPartType.Signature
|
|
595
|
+
|
|
596
|
+ # INFO - G.M - 2017-11-28 - Test for outlook.com webapp html mail
|
|
597
|
+ # outlook.com ui doesn't seems to allow complex reply, new message
|
|
598
|
+ # and signature are always before quoted one.
|
|
599
|
+
|
|
600
|
+ def test_other__check_outlook_com_mail_text_only(self):
|
|
601
|
+
|
|
602
|
+ text_only = '''
|
|
603
|
+ <div id="divtagdefaultwrapper"
|
|
604
|
+ style="font-size:12pt;color:#000000;
|
|
605
|
+ font-family:Calibri,Helvetica,sans-serif;"
|
|
606
|
+ dir="ltr">
|
|
607
|
+ <p style="margin-top:0;margin-bottom:0">message<br>
|
|
608
|
+ </p>
|
|
609
|
+ </div>
|
|
610
|
+ '''
|
|
611
|
+ mail = ParsedHTMLMail(text_only)
|
|
612
|
+ elements = mail.get_elements()
|
|
613
|
+ assert len(elements) == 1
|
|
614
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
615
|
+
|
|
616
|
+ def test_other__check_outlook_com_mail_text_signature(self):
|
|
617
|
+ text_and_signature = '''
|
|
618
|
+ <div id="divtagdefaultwrapper"
|
|
619
|
+ style="font-size:12pt;color:#000000;
|
|
620
|
+ font-family:Calibri,Helvetica,sans-serif;"
|
|
621
|
+ dir="ltr">
|
|
622
|
+ <p style="margin-top:0;margin-bottom:0">Test<br>
|
|
623
|
+ </p>
|
|
624
|
+ <p style="margin-top:0;margin-bottom:0"><br>
|
|
625
|
+ </p>
|
|
626
|
+ <div id="Signature">
|
|
627
|
+ <div id="divtagdefaultwrapper" style="font-size: 12pt; color:
|
|
628
|
+ rgb(0, 0, 0); background-color: rgb(255, 255, 255);
|
|
629
|
+ font-family:
|
|
630
|
+ Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple
|
|
631
|
+ Color Emoji","Segoe UI
|
|
632
|
+ Emoji",NotoColorEmoji,"Segoe UI
|
|
633
|
+ Symbol","Android Emoji",EmojiSymbols;">
|
|
634
|
+ Envoyé à partir de <a href="http://aka.ms/weboutlook"
|
|
635
|
+ id="LPNoLP">Outlook</a></div>
|
|
636
|
+ </div>
|
|
637
|
+ </div>
|
|
638
|
+ '''
|
|
639
|
+ mail = ParsedHTMLMail(text_and_signature)
|
|
640
|
+ elements = mail.get_elements()
|
|
641
|
+ assert len(elements) == 2
|
|
642
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
643
|
+ assert elements[1].part_type == BodyMailPartType.Signature
|
|
644
|
+
|
|
645
|
+ def test_other__check_outlook_com_mail_text_quote(self):
|
|
646
|
+ text_and_quote = '''
|
|
647
|
+ <div id="divtagdefaultwrapper"
|
|
648
|
+ style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
|
|
649
|
+ dir="ltr">
|
|
650
|
+ <p style="margin-top:0;margin-bottom:0">Salut !<br>
|
|
651
|
+ </p>
|
|
652
|
+ </div>
|
|
653
|
+ <hr style="display:inline-block;width:98%" tabindex="-1">
|
|
654
|
+ <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
|
|
655
|
+ color="#000000" face="Calibri, sans-serif"><b>De :</b> John Doe<br>
|
|
656
|
+ <b>Envoyé :</b> mardi 28 novembre 2017 12:44:59<br>
|
|
657
|
+ <b>À :</b> dev.bidule@localhost.fr<br>
|
|
658
|
+ <b>Objet :</b> voila</font>
|
|
659
|
+ <div> </div>
|
|
660
|
+ </div>
|
|
661
|
+ <style type="text/css" style="display:none">
|
|
662
|
+ <!--
|
|
663
|
+ p
|
|
664
|
+ 	{margin-top:0;
|
|
665
|
+ 	margin-bottom:0}
|
|
666
|
+ -->
|
|
667
|
+ </style>
|
|
668
|
+ <div dir="ltr">
|
|
669
|
+ <div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt;
|
|
670
|
+ color:#000000; font-family:Calibri,Helvetica,sans-serif">
|
|
671
|
+ Contenu
|
|
672
|
+ <p style="margin-top:0; margin-bottom:0"><br>
|
|
673
|
+ </p>
|
|
674
|
+ <div id="x_Signature">
|
|
675
|
+ <div id="x_divtagdefaultwrapper" dir="ltr"
|
|
676
|
+ style="font-size:12pt; color:rgb(0,0,0);
|
|
677
|
+ background-color:rgb(255,255,255);
|
|
678
|
+ font-family:Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple
|
|
679
|
+ Color Emoji","Segoe UI
|
|
680
|
+ Emoji",NotoColorEmoji,"Segoe UI
|
|
681
|
+ Symbol","Android Emoji",EmojiSymbols">
|
|
682
|
+ DLMQDNLQNDMLQS<br>
|
|
683
|
+ qs<br>
|
|
684
|
+ dqsd<br>
|
|
685
|
+ d<br>
|
|
686
|
+ qsd<br>
|
|
687
|
+ </div>
|
|
688
|
+ </div>
|
|
689
|
+ </div>
|
|
690
|
+ </div>
|
|
691
|
+ '''
|
|
692
|
+ mail = ParsedHTMLMail(text_and_quote)
|
|
693
|
+ elements = mail.get_elements()
|
|
694
|
+ assert len(elements) == 2
|
|
695
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
696
|
+ assert elements[1].part_type == BodyMailPartType.Quote
|
|
697
|
+
|
|
698
|
+ def test_other__check_outlook_com_mail_text_signature_quote(self):
|
|
699
|
+ text_signature_quote = '''
|
|
700
|
+ <div id="divtagdefaultwrapper"
|
|
701
|
+ style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
|
|
702
|
+ dir="ltr">
|
|
703
|
+ <p style="margin-top:0;margin-bottom:0">Salut !<br>
|
|
704
|
+ </p>
|
|
705
|
+ <p style="margin-top:0;margin-bottom:0"><br>
|
|
706
|
+ </p>
|
|
707
|
+ <div id="Signature">
|
|
708
|
+ <div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt;
|
|
709
|
+ color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);
|
|
710
|
+ font-family:
|
|
711
|
+ Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple
|
|
712
|
+ Color Emoji","Segoe UI
|
|
713
|
+ Emoji",NotoColorEmoji,"Segoe UI
|
|
714
|
+ Symbol","Android Emoji",EmojiSymbols;">
|
|
715
|
+ Envoyée depuis Outlook<br>
|
|
716
|
+ </div>
|
|
717
|
+ </div>
|
|
718
|
+ </div>
|
|
719
|
+ <hr style="display:inline-block;width:98%" tabindex="-1">
|
|
720
|
+ <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
|
|
721
|
+ color="#000000" face="Calibri, sans-serif"><b>De :</b> John Doe
|
|
722
|
+ <dev.bidule@localhost.fr><br>
|
|
723
|
+ <b>Envoyé :</b> mardi 28 novembre 2017 12:51:42<br>
|
|
724
|
+ <b>À :</b> John Doe<br>
|
|
725
|
+ <b>Objet :</b> Re: Test</font>
|
|
726
|
+ <div> </div>
|
|
727
|
+ </div>
|
|
728
|
+ <div style="background-color:#FFFFFF">
|
|
729
|
+ <p>Coucou<br>
|
|
730
|
+ </p>
|
|
731
|
+ <br>
|
|
732
|
+ <div class="x_moz-cite-prefix">Le 28/11/2017 à 12:39, John Doe a
|
|
733
|
+ écrit :<br>
|
|
734
|
+ </div>
|
|
735
|
+ <blockquote type="cite">
|
|
736
|
+ <div id="x_divtagdefaultwrapper" dir="ltr">
|
|
737
|
+ <p>Test<br>
|
|
738
|
+ </p>
|
|
739
|
+ <p><br>
|
|
740
|
+ </p>
|
|
741
|
+ <div id="x_Signature">
|
|
742
|
+ <div id="x_divtagdefaultwrapper">Envoyé à partir de <a
|
|
743
|
+ href="http://aka.ms/weboutlook" id="LPNoLP">
|
|
744
|
+ Outlook</a></div>
|
|
745
|
+ </div>
|
|
746
|
+ </div>
|
|
747
|
+ </blockquote>
|
|
748
|
+ <br>
|
|
749
|
+ <div class="x_moz-signature">-- <br>
|
|
750
|
+ TEST DE signature</div>
|
|
751
|
+ </div>
|
|
752
|
+ '''
|
|
753
|
+
|
|
754
|
+ mail = ParsedHTMLMail(text_signature_quote)
|
|
755
|
+ elements = mail.get_elements()
|
|
756
|
+ assert len(elements) == 3
|
|
757
|
+ assert elements[0].part_type == BodyMailPartType.Main
|
|
758
|
+ assert elements[1].part_type == BodyMailPartType.Signature
|
|
759
|
+ assert elements[2].part_type == BodyMailPartType.Quote
|