From: Andy Allan Date: Wed, 16 Aug 2023 10:35:33 +0000 (+0100) Subject: Merge pull request #4148 from tomhughes/avatar-image X-Git-Tag: live~1228 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9173dd3192e518671d419cdfac5c51fa5d4f5094?hp=59e9203a0ac7d2ce1238055879577656c57dc216 Merge pull request #4148 from tomhughes/avatar-image Use correct extension and type for avatar images attached to mails --- diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index c5c0118e6..a9c6b70f9 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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) diff --git a/app/views/user_mailer/_message_body.html.erb b/app/views/user_mailer/_message_body.html.erb index d572fb9d0..851f153a2 100644 --- a/app/views/user_mailer/_message_body.html.erb +++ b/app/views/user_mailer/_message_body.html.erb @@ -3,7 +3,7 @@ <%= link_to( image_tag( - attachments["avatar.png"].url, + attachments[@avatar].url, :alt => @author, :title => @author, :width => 50,