# HG changeset patch # User Jeff Hammel # Date 1379614867 25200 # Node ID c78da6f7ca79383af8aeea7e5fbd8684628780d7 # Parent 9ddab670f8c46073c69c067068982bc03b19a859 python/quotemail.py diff -r 9ddab670f8c4 -r c78da6f7ca79 python/quotemail.py --- a/python/quotemail.py Wed Sep 18 12:45:13 2013 -0700 +++ b/python/quotemail.py Thu Sep 19 11:21:07 2013 -0700 @@ -3,6 +3,7 @@ """ quote as per email """ +# TODO -> textshaper def prefix(text, quote='> '): return '\n'.join(['%s%s' % (quote, line.rstrip()) @@ -10,4 +11,22 @@ if __name__ == '__main__': import sys - print prefix(sys.stdin.read()) + import optparse + usage = '%prog [options] [file] <...>' + parser = optparse.OptionParser(usage=usage) + parser.add_option('-i', '--in-place', dest='in_place', + action='store_true', default=False, + help="") + options, args = parser.parse_args() + if args: + for arg in args: + with file(arg) as f: + contents = f.read() + quoted = prefix(contents) + if options.in_place: + with file(arg, 'w') as f: + f.write(quoted) + else: + print quoted + else: + print prefix(sys.stdin.read())