Use correct extension and type for avatar images attached to mails

Fixes #4147
This commit is contained in:
Tom Hughes 2023-08-09 11:41:55 +01:00
parent c65f808244
commit 473d7cd179
2 changed files with 20 additions and 2 deletions

View file

@ -187,7 +187,25 @@ class UserMailer < ApplicationMailer
end
def attach_user_avatar(user)
attachments.inline["avatar.png"] = user_avatar_file(user)
@avatar = user_avatar_filename(user)
attachments.inline[@avatar] = user_avatar_file(user)
end
def user_avatar_filename(user)
avatar = user&.avatar
if avatar&.attached?
case avatar.content_type
when "image/png" then "avatar.png"
when "image/jpeg" then "avatar.jpg"
when "image/gif" then "avatar.gif"
when "image/bmp" then "avatar.bmp"
when "image/tiff" then "avatar.tif"
when "image/svg+xml" then "avatar.svg"
else "avatar"
end
else
"avatar.png"
end
end
def user_avatar_file(user)

View file

@ -3,7 +3,7 @@
<td style="width: 50px; min-width: 50px; vertical-align: top; padding: 15px">
<%= link_to(
image_tag(
attachments["avatar.png"].url,
attachments[@avatar].url,
:alt => @author,
:title => @author,
:width => 50,