diff --git a/pagure-milters/comment_email_milter.py b/pagure-milters/comment_email_milter.py index 8f27fcb..a60abf4 100644 --- a/pagure-milters/comment_email_milter.py +++ b/pagure-milters/comment_email_milter.py @@ -36,14 +36,25 @@ import pagure def get_email_body(emailobj): ''' Return the body of the email, preferably in text. ''' - body = None - if emailobj.is_multipart(): - for payload in emailobj.get_payload(): - body = payload.get_payload() - if payload.get_content_type() == 'text/plain': - break - else: - body = emailobj.get_payload() + def _get_body(emailobj): + """ Return the first text/plain body found if the email is multipart + or just the regular payload otherwise. + """ + if emailobj.is_multipart(): + for payload in emailobj.get_payload(): + # If the message comes with a signature it can be that this + # payload itself has multiple parts, so just return the + # first one + if payload.is_multipart(): + return _get_body(payload) + + body = payload.get_payload() + if payload.get_content_type() == 'text/plain': + return body + else: + return emailobj.get_payload() + + body = _get_body(emailobj) enc = emailobj['Content-Transfer-Encoding'] if enc == 'base64':