diff --git a/config.example.ini b/config.example.ini index c3ccd5f..44fcb5f 100644 --- a/config.example.ini +++ b/config.example.ini @@ -138,7 +138,7 @@ sock-group=postfix # and each part is checked against this list. # # Uses fnmatch for wildcard expansion. -reject-mimetypes=text/html +reject-mimetypes= # # Link to include in the rejection message where senders can get help # correcting their email. diff --git a/listssrht-lmtp b/listssrht-lmtp index 626e430..30a171e 100755 --- a/listssrht-lmtp +++ b/listssrht-lmtp @@ -197,23 +197,31 @@ class MailHandler: sender = sender[0] or sender[1] permit_mimetypes = permit_mimetypes.split(",") reject_mimetypes = reject_mimetypes.split(",") + always_reject + # check the email for plaintext part for part in mail.walk(): content_type = part.get_content_type() if content_type == "text/plain": found_textpart = True + break + # check if the email is permitted or not + # rejection occur if any forbidden mimetype is present or if any + # non-permitted part is present, except for text/html which is ignored + # if there is also a text/plain part and it is not forbidden + for part in mail.walk(): + content_type = part.get_content_type() if fnmatch(content_type, "multipart/*"): continue + # check whether the type is permitted permit = False for whitelist in permit_mimetypes: if fnmatch(content_type, whitelist): permit = True break if not permit: - if content_type == "text/html": + if content_type == "text/html" and not found_textpart: return html_error.format(sender) else: - return forbidden_mimetype_error.format( - sender, content_type) + return forbidden_mimetype_error.format(sender, content_type) for blacklist in reject_mimetypes: if fnmatch(content_type, blacklist): if content_type == "text/html": diff --git a/schema.sql b/schema.sql index 4547f69..8c76cc4 100644 --- a/schema.sql +++ b/schema.sql @@ -57,7 +57,7 @@ CREATE TABLE list ( default_access integer DEFAULT 7 NOT NULL, mirror_id integer REFERENCES list(id), permit_mimetypes character varying DEFAULT 'text/*,application/pgp-signature,application/pgp-keys'::character varying NOT NULL, - reject_mimetypes character varying DEFAULT ''::character varying NOT NULL, + reject_mimetypes character varying DEFAULT 'text/html'::character varying NOT NULL, import_in_progress boolean DEFAULT false NOT NULL, visibility visibility NOT NULL, CONSTRAINT uq_list_owner_id_name UNIQUE (owner_id, name)