Anthony Baxter's cleanup patch.  Python project SF patch # 583190,
quoting:

  in non-strict mode, messages don't require a blank line at the end
  with a missing end-terminator. A single newline is sufficient now.

  Handle trailing whitespace at the end of a boundary. Had to switch
  from using string.split() to re.split()

  Handle whitespace on the end of a parameter list for Content-type.

  Handle whitespace on the end of a plain content-type header.

Specifically,

get_type(): Strip the content type string.

_get_params_preserve(): Strip the parameter names and values on both
sides.

_parsebody(): Lots of changes as described above, with some stylistic
changes by Barry (who hopefully didn't screw things up ;).
diff --git a/Lib/email/Message.py b/Lib/email/Message.py
index 5e8d32f..fb121a9 100644
--- a/Lib/email/Message.py
+++ b/Lib/email/Message.py
@@ -373,7 +373,7 @@
         value = self.get('content-type', missing)
         if value is missing:
             return failobj
-        return paramre.split(value)[0].lower()
+        return paramre.split(value)[0].lower().strip()
 
     def get_main_type(self, failobj=None):
         """Return the message's main content type if present."""
@@ -428,11 +428,11 @@
         for p in paramre.split(value):
             try:
                 name, val = p.split('=', 1)
-                name = name.rstrip()
-                val = val.lstrip()
+                name = name.strip()
+                val = val.strip()
             except ValueError:
                 # Must have been a bare attribute
-                name = p
+                name = p.strip()
                 val = ''
             params.append((name, val))
         params = Utils.decode_params(params)