1
- # -*- coding: utf-8 -*-
2
1
# quotequail
3
2
# a library that identifies quoted text in email messages
4
3
@@ -16,12 +15,14 @@ def quote(text, limit=1000):
16
15
17
16
Example: [(True, 'expanded text'), (False, '> Some quoted text')]
18
17
19
- Unless the limit param is set to None, the text will automatically be quoted
20
- starting at the line where the limit is reached.
18
+ Unless the limit param is set to None, the text will automatically be
19
+ quoted starting at the line where the limit is reached.
21
20
"""
22
21
lines = text .split ("\n " )
23
22
24
- found = _internal .find_quote_position (lines , _patterns .MAX_WRAP_LINES , limit )
23
+ found = _internal .find_quote_position (
24
+ lines , _patterns .MAX_WRAP_LINES , limit
25
+ )
25
26
26
27
if found is not None :
27
28
return [
@@ -49,11 +50,11 @@ def quote_html(html, limit=1000):
49
50
if found is None :
50
51
# No quoting found and we're below limit. We're done.
51
52
return [(True , _html .render_html_tree (tree ))]
52
- else :
53
- start_tree = _html .slice_tree (
54
- tree , start_refs , end_refs , (0 , found + 1 ), html_copy = html
55
- )
56
- end_tree = _html .slice_tree (tree , start_refs , end_refs , (found + 1 , None ))
53
+
54
+ start_tree = _html .slice_tree (
55
+ tree , start_refs , end_refs , (0 , found + 1 ), html_copy = html
56
+ )
57
+ end_tree = _html .slice_tree (tree , start_refs , end_refs , (found + 1 , None ))
57
58
58
59
return [
59
60
(True , _html .render_html_tree (start_tree )),
@@ -83,35 +84,37 @@ def unwrap(text):
83
84
_patterns .MIN_HEADER_LINES ,
84
85
_patterns .MIN_QUOTED_LINES ,
85
86
)
86
- if result :
87
- typ , top_range , hdrs , main_range , bottom_range , needs_unindent = result
87
+ if not result :
88
+ return None
88
89
89
- text_top = lines [slice (* top_range )] if top_range else ""
90
- text = lines [slice (* main_range )] if main_range else ""
91
- text_bottom = lines [slice (* bottom_range )] if bottom_range else ""
90
+ typ , top_range , hdrs , main_range , bottom_range , needs_unindent = result
92
91
93
- if needs_unindent :
94
- text = _internal .unindent_lines (text )
92
+ text_top = lines [slice (* top_range )] if top_range else ""
93
+ text = lines [slice (* main_range )] if main_range else ""
94
+ text_bottom = lines [slice (* bottom_range )] if bottom_range else ""
95
95
96
- result = {
97
- "type" : typ ,
98
- }
96
+ if needs_unindent :
97
+ text = _internal .unindent_lines (text )
99
98
100
- text = " \n " . join ( text ). strip ()
101
- text_top = " \n " . join ( text_top ). strip ()
102
- text_bottom = " \n " . join ( text_bottom ). strip ()
99
+ result = {
100
+ "type" : typ ,
101
+ }
103
102
104
- if text :
105
- result ["text" ] = text
106
- if text_top :
107
- result ["text_top" ] = text_top
108
- if text_bottom :
109
- result ["text_bottom" ] = text_bottom
103
+ text = "\n " .join (text ).strip ()
104
+ text_top = "\n " .join (text_top ).strip ()
105
+ text_bottom = "\n " .join (text_bottom ).strip ()
110
106
111
- if hdrs :
112
- result .update (hdrs )
107
+ if text :
108
+ result ["text" ] = text
109
+ if text_top :
110
+ result ["text_top" ] = text_top
111
+ if text_bottom :
112
+ result ["text_bottom" ] = text_bottom
113
113
114
- return result
114
+ if hdrs :
115
+ result .update (hdrs )
116
+
117
+ return result
115
118
116
119
117
120
def unwrap_html (html ):
@@ -164,7 +167,9 @@ def unwrap_html(html):
164
167
result ["html_bottom" ] = html_bottom
165
168
166
169
if main_range :
167
- main_tree = _html .slice_tree (tree , start_refs , end_refs , main_range )
170
+ main_tree = _html .slice_tree (
171
+ tree , start_refs , end_refs , main_range
172
+ )
168
173
if needs_unindent :
169
174
_html .unindent_tree (main_tree )
170
175
html = _html .render_html_tree (main_tree )
0 commit comments