From 473d7cd179b2be697c8f1d9104fd3c556d14483e Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 9 Aug 2023 11:41:55 +0100 Subject: [PATCH] Use correct extension and type for avatar images attached to mails Fixes #4147 --- app/mailers/user_mailer.rb | 20 +++++++++++++++++++- app/views/user_mailer/_message_body.html.erb | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) 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, -- 2.39.5