Does it suffice to change: self.pat = re.compile( as_bytes(r'--%s(--)?[ \t]*\r\n' % re.escape(boundary))) to self.pat = re.compile( as_bytes(r'--%s(--)?[ \t]*(\r\n)?' % re.escape(boundary))) in MIMEInput.__init__()?