comparison python/quotemail.py @ 516:c78da6f7ca79

python/quotemail.py
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 19 Sep 2013 11:21:07 -0700
parents 6bbc4867a795
children
comparison
equal deleted inserted replaced
515:9ddab670f8c4 516:c78da6f7ca79
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 """ 3 """
4 quote as per email 4 quote as per email
5 """ 5 """
6 # TODO -> textshaper
6 7
7 def prefix(text, quote='> '): 8 def prefix(text, quote='> '):
8 return '\n'.join(['%s%s' % (quote, line.rstrip()) 9 return '\n'.join(['%s%s' % (quote, line.rstrip())
9 for line in text.strip().splitlines()]) 10 for line in text.strip().splitlines()])
10 11
11 if __name__ == '__main__': 12 if __name__ == '__main__':
12 import sys 13 import sys
13 print prefix(sys.stdin.read()) 14 import optparse
15 usage = '%prog [options] [file] <file2> <...>'
16 parser = optparse.OptionParser(usage=usage)
17 parser.add_option('-i', '--in-place', dest='in_place',
18 action='store_true', default=False,
19 help="")
20 options, args = parser.parse_args()
21 if args:
22 for arg in args:
23 with file(arg) as f:
24 contents = f.read()
25 quoted = prefix(contents)
26 if options.in_place:
27 with file(arg, 'w') as f:
28 f.write(quoted)
29 else:
30 print quoted
31 else:
32 print prefix(sys.stdin.read())