view python/quotemail.py @ 839:0bc7ec47bf0f

python litters so much, but lets turn a blind eye
author Jeff Hammel <k0scist@gmail.com>
date Fri, 31 Mar 2017 16:52:35 -0700
parents c78da6f7ca79
children
line wrap: on
line source

#!/usr/bin/env python

"""
quote as per email
"""
# TODO -> textshaper

def prefix(text, quote='> '):
    return '\n'.join(['%s%s' % (quote, line.rstrip())
                      for line in text.strip().splitlines()])

if __name__ == '__main__':
    import sys
    import optparse
    usage = '%prog [options] [file] <file2> <...>'
    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())