#!/usr/bin/env python # nohtml.py - Filter To Remove HTML Attachments From Email # Copyright (c) 2003 TundraWare Inc. All Rights Reserved. # For Updates See: http://www.tundraware.com/Software/nohtml #------------------- Nothing Below Here Should Need Changing ------------------# # Program Information PROGNAME = "nohtml" RCSID = "$Id: nohtml.py,v 1.10 2003/05/05 21:56:35 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information CPRT = chr(169) DATE = 2003 OWNER = "TundraWare Inc." RIGHTS = "All Rights Reserved" COPYRIGHT = "Copyright %s %s %s %s. " % (CPRT, DATE, OWNER, RIGHTS) #----------------------------------------------------------# # Imports # #----------------------------------------------------------# import getopt import os import sys #----------------------------------------------------------# # Constants & Literals # #----------------------------------------------------------# ##### # Literals ##### STARTHTML1 = "Content-Type:".lower() STARTHTML2 = "text/html".lower() ENDHTML = "</HTML>".lower() #----------------------------------------------------------# # Prompts, & Application Strings # #----------------------------------------------------------# ##### # Usage Prompts ##### uTable = [PROGNAME + " " + VERSION + " - %s\n" % COPYRIGHT, "usage: " + PROGNAME + " [-hv] where,\n", " -h print this help information", " -v print detailed version information", ] #--------------------------- Code Begins Here ---------------------------------# #----------------------------------------------------------# # Supporting Function Definitions # #----------------------------------------------------------# ##### # Print Usage Information ##### def Usage(): for line in uTable: print line #----------------------------------------------------------# # Program Entry Point # #----------------------------------------------------------# # Command line processing - Process any options set in the # environment first, and then those given on the command line OPTIONS = sys.argv[1:] envopt = os.getenv(PROGNAME.upper()) if envopt: OPTIONS = envopt.split() + OPTIONS try: opts, args = getopt.getopt(OPTIONS, '-hv') except getopt.GetoptError: Usage() sys.exit(1) for opt, val in opts: if opt == "-h": Usage() sys.exit(0) if opt == "-v": print RCSID sys.exit(0) PASS = True for line in sys.stdin.readlines(): lline = line.lower() if lline.count(STARTHTML1) and lline.count(STARTHTML2): PASS = False if PASS: sys.stdout.write(line) if lline.count(ENDHTML): DONE = True