I am using the Tmail library, and for each attachment in an email, when I do attachment.content_type
, sometimes I get not just the content type
I think we can divide this question in two:
The first is well answered above. For the second, I would do the following:
(cleaned_content_types - VALID_CONTENT_TYPES) == 0
The nice thing about this solution is that you can easily create a variable to store the undesired types to list them later like this example:
VALID_CONTENT_TYPES = ['image/jpeg']
cleaned_content_types = ['image/png', 'image/jpeg', 'image/gif', 'image/jpeg']
undesired_types = cleaned_content_types - VALID_CONTENT_TYPES
if undesired_types.size > 0
error_message = "The types #{undesired_types.join(', ')} are not allowed"
else
# The happy path here
end