1 class Notifier < ActionMailer::Base
2 default :from => EMAIL_FROM,
3 :return_path => EMAIL_RETURN_PATH,
4 :auto_submitted => "auto-generated"
6 before_action :set_shared_template_vars
7 before_action :attach_project_logo
9 def signup_confirm(user, token)
10 with_recipient_locale user do
11 @url = url_for(:controller => "user", :action => "confirm",
12 :display_name => user.display_name,
13 :confirm_string => token.token)
15 mail :to => user.email,
16 :subject => I18n.t("notifier.signup_confirm.subject")
20 def email_confirm(user, token)
21 with_recipient_locale user do
22 @address = user.new_email
23 @url = url_for(:controller => "user", :action => "confirm_email",
24 :confirm_string => token.token)
26 mail :to => user.new_email,
27 :subject => I18n.t("notifier.email_confirm.subject")
31 def lost_password(user, token)
32 with_recipient_locale user do
33 @url = url_for(:controller => "user", :action => "reset_password",
34 :token => token.token)
36 mail :to => user.email,
37 :subject => I18n.t("notifier.lost_password.subject")
41 def gpx_success(trace, possible_points)
42 with_recipient_locale trace.user do
43 @trace_name = trace.name
44 @trace_points = trace.size
45 @trace_description = trace.description
46 @trace_tags = trace.tags
47 @possible_points = possible_points
49 mail :to => trace.user.email,
50 :subject => I18n.t("notifier.gpx_notification.success.subject")
54 def gpx_failure(trace, error)
55 with_recipient_locale trace.user do
56 @trace_name = trace.name
57 @trace_description = trace.description
58 @trace_tags = trace.tags
61 mail :to => trace.user.email,
62 :subject => I18n.t("notifier.gpx_notification.failure.subject")
66 def message_notification(message)
67 with_recipient_locale message.recipient do
68 @to_user = message.recipient.display_name
69 @from_user = message.sender.display_name
71 @title = message.title
72 @readurl = url_for(:controller => "message", :action => "read",
73 :message_id => message.id)
74 @replyurl = url_for(:controller => "message", :action => "reply",
75 :message_id => message.id)
78 attach_user_avatar(message.sender)
80 mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
81 :to => message.recipient.email,
82 :subject => I18n.t("notifier.message_notification.subject_header", :subject => message.title)
86 def diary_comment_notification(comment, recipient)
87 with_recipient_locale recipient do
88 @to_user = recipient.display_name
89 @from_user = comment.user.display_name
91 @title = comment.diary_entry.title
92 @readurl = url_for(:controller => "diary_entry",
94 :display_name => comment.diary_entry.user.display_name,
95 :id => comment.diary_entry.id,
96 :anchor => "comment#{comment.id}")
97 @commenturl = url_for(:controller => "diary_entry",
99 :display_name => comment.diary_entry.user.display_name,
100 :id => comment.diary_entry.id,
101 :anchor => "newcomment")
102 @replyurl = url_for(:controller => "message",
104 :display_name => comment.user.display_name,
105 :title => "Re: #{comment.diary_entry.title}")
109 attach_user_avatar(comment.user)
111 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest, recipient.id),
112 :to => recipient.email,
113 :subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
117 def friend_notification(friend)
118 with_recipient_locale friend.befriendee do
120 @viewurl = url_for(:controller => "user", :action => "view",
121 :display_name => @friend.befriender.display_name)
122 @friendurl = url_for(:controller => "user", :action => "make_friend",
123 :display_name => @friend.befriender.display_name)
124 @author = @friend.befriender.display_name
126 attach_user_avatar(@friend.befriender)
127 mail :to => friend.befriendee.email,
128 :subject => I18n.t("notifier.friend_notification.subject", :user => friend.befriender.display_name)
132 def note_comment_notification(comment, recipient)
133 with_recipient_locale recipient do
134 @noteurl = browse_note_url(comment.note)
135 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
136 @comment = comment.body
137 @owner = recipient == comment.note.author
138 @event = comment.event
140 @commenter = if comment.author
141 comment.author.display_name
143 I18n.t("notifier.note_comment_notification.anonymous")
147 attach_user_avatar(comment.author)
150 I18n.t("notifier.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
152 I18n.t("notifier.note_comment_notification.#{@event}.subject_other", :commenter => @commenter)
155 mail :to => recipient.email, :subject => subject
159 def changeset_comment_notification(comment, recipient)
160 with_recipient_locale recipient do
161 @to_user = recipient.display_name
162 @changeset_url = changeset_url(comment.changeset)
163 @comment = comment.body
164 @owner = recipient == comment.changeset.user
165 @commenter = comment.author.display_name
166 @changeset_comment = comment.changeset.tags["comment"].presence
167 @time = comment.created_at
168 @changeset_author = comment.changeset.user.display_name
172 I18n.t("notifier.changeset_comment_notification.commented.subject_own", :commenter => @commenter)
174 I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter)
177 attach_user_avatar(comment.author)
179 mail :to => recipient.email, :subject => subject
185 def set_shared_template_vars
189 def attach_project_logo
190 attachments.inline["logo.png"] = File.read(Rails.root.join("app", "assets", "images", "osm_logo_30.png"))
193 def attach_user_avatar(user)
194 attachments.inline["avatar.png"] = File.read(user_avatar_file_path(user))
197 def user_avatar_file_path(user)
198 image = user && user.image
199 if image && image.file?
200 return image.path(:small)
202 return Rails.root.join("app", "assets", "images", "users", "images", "small.png")
206 def with_recipient_locale(recipient)
207 I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do
212 def from_address(name, type, id, digest, user_id = nil)
213 if Object.const_defined?(:MESSAGES_DOMAIN) && domain = MESSAGES_DOMAIN
215 "#{name} <#{type}-#{id}-#{user_id}-#{digest[0, 6]}@#{domain}>"
217 "#{name} <#{type}-#{id}-#{digest[0, 6]}@#{domain}>"