Script to drop HTML part of multipart/mixed e-mails
I think the code is quite fine as it is. Some small notes:

if composition == (TEXTPLAIN + TEXTHTML) or composition == TEXTPLAIN:


Just to make sure: this code tests that TEXTPLAIN is set and that MISCPARTS is not set. I would make that explicit, otherwise this code is hard to understand (in particular, it’s easy to miss that MISCPARTS mustn’t be set):

if (composition &amp; TEXTPLAIN) != 0 and (composition &amp; MISCPARTS) == 0:


If you’re not happy with bit operations, you can a set instead.

composition = set()

# …

if TEXTPLAIN in composition and MISCPARTS not in composition:


… and define TEXTPLAIN etc. as simple consecutive constants rather than bitmasks.

This is more pythonic certainly, but I actually find the use of bit masks entirely appropriate here.