| | #!/usr/bin/env python |
---|
| | # mailfmt - Copyright (c) 2002, TundraWare Inc., All Rights Reserved |
---|
| | #!/usr/bin/env python2 |
---|
| | # mailfmt - Copyright (c) 2002-2022, TundraWare Inc., All Rights Reserved |
---|
| | # Reformat mail/news to cleanup quotation characters and maintain |
---|
| | # reasonable line widths. |
---|
| | |
---|
| | PROGNAME = "MAILFMT" |
---|
| | RCSID = "$Id: mailfmt,v 1.3 2002/10/09 19:34:16 tundra Exp $" |
---|
| | RCSID = "$Id: mailfmt,v 1.4 2022/04/01 19:34:16 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | ########## |
---|
| | # Imports |
---|
| |
---|
| | import win32clipboard |
---|
| | from win32ui import MessageBox |
---|
| | else: |
---|
| | WIN32 = FALSE |
---|
| | |
---|
| | |
---|
| | |
---|
| | ########## |
---|
| | # Constants & Tables |
---|
| | ########## |
---|
| |
---|
| | quotetxt = line.split(content)[0] |
---|
| | content = " ".join(content.split()) |
---|
| | return([quotetxt, content]) |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | # End of 'line_quot()' |
---|
| | |
---|
| |
---|
| | except getopt.GetoptError: |
---|
| | usage() |
---|
| | sys.exit(1) |
---|
| | |
---|
| | |
---|
| | |
---|
| | for opt, val in opts: |
---|
| | if opt == "-a": |
---|
| | RMVQUOT = FALSE |
---|
| | if opt == "-c": |
---|
| |
---|
| | WIDTH = int(val) |
---|
| | except: |
---|
| | dsply_error(eBADWIDTH) |
---|
| | sys.exit(1) |
---|
| | |
---|
| | |
---|
| | if WIDTH < 1: |
---|
| | dsply_error(eBADWIDTH) |
---|
| | sys.exit(1) |
---|
| | |
---|
| |
---|
| | if WRAP: |
---|
| | |
---|
| | # Walk through the current work buffer and concatenate |
---|
| | # adjacent lines with identical quotations |
---|
| | |
---|
| | |
---|
| | l="" |
---|
| | i = -1 |
---|
| | lastquot = NOQUOTEMATCH # Make sure no match on first record |
---|
| | |
---|
| |
---|
| | buffer=[] |
---|
| | lastquot = tmp[0][0] |
---|
| | content = tmp[0][1] |
---|
| | tmp = tmp[1:] |
---|
| | |
---|
| | |
---|
| | for entry in tmp: |
---|
| | if entry[1] == PMARK: # Blank lines output separately |
---|
| | buffer.append([lastquot, content]) # Output pending work |
---|
| | lastquot = entry[0] # Setup to output next time through |
---|
| |
---|
| | buffer.append([lastquot, content]) |
---|
| | |
---|
| | # Iterate across the results producing lines of appropriate length |
---|
| | # with correct quotation text, if any. |
---|
| | |
---|
| | |
---|
| | tmp = [] |
---|
| | for entry in buffer: |
---|
| | # Figure out allowable width with quotation, if any |
---|
| | quot = entry[0] |
---|
| |
---|
| | # Send the output as user has specified |
---|
| | |
---|
| | output(tmp) |
---|
| | |
---|
| | |
---|
| | |