ezmlm-browse (0.10-3) direct (non packaging) changes

Summary

 globalfns.py |   10 +++++-----
 main.py      |   16 +++++++++++++---
 2 files changed, 18 insertions(+), 8 deletions(-)

    
download this patch

Patch contents

--- ezmlm-browse-0.10.orig/globalfns.py
+++ ezmlm-browse-0.10/globalfns.py
@@ -145,7 +145,7 @@
 
 def sub_showpart(ctxt, part):
 	ctxt[BODY] = part.get_payload(decode=1)
-	type = ctxt[TYPE] = part.get_type('text/plain')
+	type = ctxt[TYPE] = part.get_content_type()
 	ctxt[FILENAME] = part.get_filename()
 	template = html('msg-' + type.replace('/', '-'))
 	if not template:
@@ -154,7 +154,7 @@
 
 def rec_noshowpart(ctxt, part, partnum):
 	ctxt[PART] = partnum
-	ctxt[TYPE] = part.get_type('text/plain')
+	ctxt[TYPE] = part.get_content_type()
 	# FIXME: show something here
 	if part.is_multipart():
 		for p in part.get_payload():
@@ -165,13 +165,13 @@
 
 def rec_showpart(ctxt, part, partnum):
 	ctxt[PART] = partnum
-	ctxt[TYPE] = part.get_type('text/plain')
+	ctxt[TYPE] = part.get_content_type()
 	if part.is_multipart():
 		# handle alternative parts differently
-		if part.get_subtype() == 'alternative':
+		if part.get_content_subtype() == 'alternative':
 			m = { }
 			for p in part.get_payload():
-				m[p.get_type('text/plain')] = p
+				m[p.get_content_type()] = p
 			try:
 				altpart = m[ctxt[ALTPART]]
 			except KeyError:
--- ezmlm-browse-0.10.orig/main.py
+++ ezmlm-browse-0.10/main.py
@@ -2,6 +2,7 @@
 cgitb.enable()
 import cgi
 import email
+import imp
 import os
 import re
 import sys
@@ -292,7 +293,7 @@
 		while parts:
 			part = part.get_payload()[parts[0]]
 			parts = parts[1:]
-		write('Content-Type: %s\r\n\r\n' % part.get_type('text/plain'))
+		write('Content-Type: %s\r\n\r\n' % part.get_content_type())
 		write(part.get_payload(decode=1))
 	else:
 		try:
@@ -302,7 +303,7 @@
 				if partnum <= 0:
 					break
 				partnum -= 1
-			write('Content-Type: %s\r\n\r\n' % part.get_type('text/plain'))
+			write('Content-Type: %s\r\n\r\n' % part.get_content_type())
 			write(part.get_payload(decode=1))
 		except:
 			write('Content-Type: message/rfc822\r\n\r\n')
@@ -312,6 +313,15 @@
 				buf = msg.read(8192)
 	sys.exit(0)
 
+def import_command(command):
+	name = 'commands.' + command
+	for base in sys.path[:2]:
+		filename = base + '/commands/' + command + '.py'
+		if os.path.exists(filename):
+			return imp.load_module(name, open(filename, 'r'), filename,
+								   ('', '', imp.PY_SOURCE))
+	raise ImportError, "Could not locate command: " + command
+
 def main_form():
 	global ctxt
 	setup_list()
@@ -321,7 +331,7 @@
 	if not ctxt[LIST]:
 		ctxt[COMMAND] = 'lists'
 	try:
-		module = __import__('commands/' + ctxt[COMMAND])
+		module = import_command(ctxt[COMMAND])
 	except ImportError:
 		die(ctxt, "Invalid command")
 	module.do(ctxt)