1 class UserMailer < ApplicationMailer
2 include ActionView::Helpers::AssetUrlHelper
4 self.delivery_job = ActionMailer::MailDeliveryJob
6 default :from => Settings.email_from,
7 :return_path => Settings.email_return_path,
8 :auto_submitted => "auto-generated"
10 before_action :set_shared_template_vars
11 before_action :attach_project_logo
13 def signup_confirm(user, token, referer = nil)
14 with_recipient_locale user do
15 @url = url_for(:controller => "confirmations", :action => "confirm",
16 :display_name => user.display_name,
17 :confirm_string => token,
20 mail :to => user.email,
21 :subject => t(".subject")
25 def email_confirm(user, token)
26 with_recipient_locale user do
27 @address = user.new_email
28 @url = url_for(:controller => "confirmations", :action => "confirm_email",
29 :confirm_string => token)
31 mail :to => user.new_email,
32 :subject => t(".subject")
36 def lost_password(user, token)
37 with_recipient_locale user do
38 @url = user_reset_password_url(:token => token)
40 mail :to => user.email,
41 :subject => t(".subject")
45 def gpx_success(trace, possible_points)
46 with_recipient_locale trace.user do
47 @to_user = trace.user.display_name
48 @trace_url = show_trace_url(trace.user, trace)
49 @trace_name = trace.name
50 @trace_points = trace.size
51 @trace_description = trace.description
52 @trace_tags = trace.tags
53 @possible_points = possible_points
54 @my_traces_url = url_for(:controller => "traces", :action => "mine")
56 mail :to => trace.user.email,
57 :subject => t(".subject")
61 def gpx_failure(trace, error)
62 with_recipient_locale trace.user do
63 @to_user = trace.user.display_name
64 @trace_name = trace.name
65 @trace_description = trace.description
66 @trace_tags = trace.tags
69 mail :to => trace.user.email,
70 :subject => t(".subject")
74 def message_notification(message)
75 with_recipient_locale message.recipient do
76 @to_user = message.recipient.display_name
77 @from_user = message.sender.display_name
79 @title = message.title
80 @readurl = message_url(message)
81 @replyurl = message_reply_url(message)
84 attach_user_avatar(message.sender)
86 mail :from => from_address(message.sender.display_name, "m", message.id, message.notification_token),
87 :to => message.recipient.email,
88 :subject => t(".subject", :message_title => message.title)
92 def diary_comment_notification(comment, recipient)
93 with_recipient_locale recipient do
94 @to_user = recipient.display_name
95 @from_user = comment.user.display_name
97 @title = comment.diary_entry.title
98 @readurl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "comment#{comment.id}")
99 @commenturl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "newcomment")
100 @replyurl = new_message_url(comment.user, :message => { :title => "Re: #{comment.diary_entry.title}" })
101 @unsubscribeurl = diary_entry_unsubscribe_url(comment.diary_entry.user, comment.diary_entry)
104 attach_user_avatar(comment.user)
106 set_references("diary", comment.diary_entry)
108 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.notification_token(recipient.id), recipient.id),
109 :to => recipient.email,
110 :subject => t(".subject", :user => comment.user.display_name)
114 def friendship_notification(friendship)
115 with_recipient_locale friendship.befriendee do
116 @friendship = friendship
117 @viewurl = user_url(@friendship.befriender)
118 @friendurl = make_friend_url(@friendship.befriender)
119 @author = @friendship.befriender.display_name
121 attach_user_avatar(@friendship.befriender)
122 mail :to => friendship.befriendee.email,
123 :subject => t(".subject", :user => friendship.befriender.display_name)
127 def note_comment_notification(comment, recipient)
128 with_recipient_locale recipient do
129 @noteurl = note_url(comment.note)
130 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
131 @comment = comment.body
132 @owner = recipient == comment.note.author
133 @event = comment.event
135 @commenter = if comment.author
136 comment.author.display_name
142 attach_user_avatar(comment.author)
144 set_references("note", comment.note)
147 t(".#{@event}.subject_own", :commenter => @commenter)
149 t(".#{@event}.subject_other", :commenter => @commenter)
152 mail :to => recipient.email, :subject => subject
156 def changeset_comment_notification(comment, recipient)
157 with_recipient_locale recipient do
158 @to_user = recipient.display_name
159 @changeset_url = changeset_url(comment.changeset)
160 @comment = comment.body
161 @owner = recipient == comment.changeset.user
162 @commenter = comment.author.display_name
163 @changeset_comment = comment.changeset.tags["comment"].presence
164 @time = comment.created_at
165 @changeset_author = comment.changeset.user.display_name
169 t(".commented.subject_own", :commenter => @commenter)
171 t(".commented.subject_other", :commenter => @commenter)
174 attach_user_avatar(comment.author)
176 set_references("changeset", comment.changeset)
178 mail :to => recipient.email, :subject => subject
184 def set_shared_template_vars
188 def attach_project_logo
189 attachments.inline["logo.png"] = Rails.root.join("app/assets/images/osm_logo_30.png").read
192 def attach_user_avatar(user)
193 @avatar = user_avatar_filename(user)
194 attachments.inline[@avatar] = user_avatar_file(user)
197 def user_avatar_filename(user)
198 avatar = user&.avatar
200 case avatar.content_type
201 when "image/png" then "avatar.png"
202 when "image/jpeg" then "avatar.jpg"
203 when "image/gif" then "avatar.gif"
204 when "image/bmp" then "avatar.bmp"
205 when "image/tiff" then "avatar.tif"
206 when "image/svg+xml" then "avatar.svg"
214 def user_avatar_file(user)
215 avatar = user&.avatar
218 avatar.variant(:resize_to_limit => [50, 50]).download
223 Rails.root.join("app/assets/images/avatar_small.png").read
227 def with_recipient_locale(recipient, &block)
228 I18n.with_locale(Locale.available.preferred(recipient.preferred_languages), &block)
231 def from_address(name, type, id, token, user_id = nil)
232 if Settings.key?(:messages_domain) && domain = Settings.messages_domain
234 "#{name} <#{type}-#{id}-#{user_id}-#{token}@#{domain}>"
236 "#{name} <#{type}-#{id}-#{token}@#{domain}>"
243 def set_references(scope, reference_object)
244 ref = "osm-#{scope}-#{reference_object.id}@#{Settings.server_url}"
246 headers["X-Entity-Ref-ID"] = ref
247 headers["In-Reply-To"] = ref
248 headers["References"] = ref