Skip to content

Commit

Permalink
Merge pull request #111 from adimascio/master
Browse files Browse the repository at this point in the history
[utils] avoid stripping all lines when no signature is found
  • Loading branch information
GuillaumeSeren committed Jun 11, 2017
2 parents 1547209 + 086ff62 commit 9c8a4da
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
40 changes: 40 additions & 0 deletions afew/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
import unittest

from afew import utils


class TestUtils(unittest.TestCase):

def test_strip_signatures_base(self):
lines = ['Huhu', '--', 'Ikke']
self.assertEqual(['Huhu'], utils.strip_signatures(lines))

def test_strip_signatures_base_maxsig(self):
lines = [
'Huhu',
'--',
'Ikke',
'**',
"Sponsored by PowerDoh'",
"Sponsored by PowerDoh'",
"Sponsored by PowerDoh'",
"Sponsored by PowerDoh'",
"Sponsored by PowerDoh'",
]
self.assertEqual(['Huhu'],
utils.strip_signatures(lines, max_signature_size=5))

def test_strip_signatures_no_signature(self):
"""no signature, nothing should be stripped"""
lines = '''
bla
bla
bla
'''.splitlines()
self.assertEqual(lines,
utils.strip_signatures(lines, max_signature_size=2))


if __name__ == '__main__':
unittest.main()
6 changes: 5 additions & 1 deletion afew/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def strip_signatures(lines, max_signature_size = 10):

sigline_count += 1

return lines[:-siglines]
# a signature was found, strip it
if siglines:
return lines[:-siglines]
# otherwise, just return original content
return lines


def extract_mail_body(message):
Expand Down

0 comments on commit 9c8a4da

Please sign in to comment.