Better Mime Decoder than mimetools?

Lars Wirzenius liw at iki.fi
Mon May 17 11:46:05 EDT 1999


"Brad Clements" <bkc at Murkworks.com>:
> I'm wondering if anyone has combined the various mime and multi-part
> utilities together to produce a unified package for decoding all forms of
> mime enhanced mail.

While writing my mailer, I have made a Python package of the
back-end routines that manipulate mails and folders (i.e.,
essentially everything not related to the user interface).
It is availabe in the source tarball of my mailer at
<http://www.iki.fi/liw/Slime/>. (Slime comes from "Stupid
little mailer". It is, of course, being written in Python,
although it isn't really even alpha quality yet.)

As an example, here is a test program from the tarball that goes through
all mails in the folders named on the command line and lists the type
of each mail and all its parts (and their parts, recursively).

import time
import slimelib

def types(msg, level):
	main, sub = msg.get_type()
	print "  %*s%s/%s" % (level*2, "", main, sub)
	for part in msg.get_parts():
		types(part, level+1)

def list(folder):
	folder.open()
	messages = folder.messages()
	print "Folder %s (%d msgs)" % (folder.get_name(), len(messages))
	msglist = slimelib.list.Unsorted(messages)
	for indent, msg in msglist.get():
		maintype, subtype = msg.get_type()
		addrs = msg.get_addresses("From")
		if not addrs:
			addrs = [("Unknown", "")]
		name, addr = addrs[0]
		if not name:
			name = addr
		datestr = time.strftime("%y-%m-%d", msg.get_time("Date"))
		subject = msg.get_header("Subject")
		print ("  %s %-15.15s  %s" % \
			(datestr, name, subject))[:78]
		types(msg, 0)
	print ""
	folder.close()

def main():
	import sys
	for foldername in sys.argv[1:]:
		list(slimelib.Folder(foldername))

if __name__ == "__main__":
	main()




More information about the Python-list mailing list