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
8 def signup_confirm(user, token)
9 with_recipient_locale user do
10 @url = url_for(:host => SERVER_URL,
11 :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(:host => SERVER_URL,
24 :controller => "user", :action => "confirm_email",
25 :confirm_string => token.token)
27 mail :to => user.new_email,
28 :subject => I18n.t("notifier.email_confirm.subject")
32 def lost_password(user, token)
33 with_recipient_locale user do
34 @url = url_for(:host => SERVER_URL,
35 :controller => "user", :action => "reset_password",
36 :token => token.token)
38 mail :to => user.email,
39 :subject => I18n.t("notifier.lost_password.subject")
43 def gpx_success(trace, possible_points)
44 with_recipient_locale trace.user do
45 @trace_name = trace.name
46 @trace_points = trace.size
47 @trace_description = trace.description
48 @trace_tags = trace.tags
49 @possible_points = possible_points
51 mail :to => trace.user.email,
52 :subject => I18n.t("notifier.gpx_notification.success.subject")
56 def gpx_failure(trace, error)
57 with_recipient_locale trace.user do
58 @trace_name = trace.name
59 @trace_description = trace.description
60 @trace_tags = trace.tags
63 mail :to => trace.user.email,
64 :subject => I18n.t("notifier.gpx_notification.failure.subject")
68 def message_notification(message)
69 with_recipient_locale message.recipient do
70 @to_user = message.recipient.display_name
71 @from_user = message.sender.display_name
73 @title = message.title
74 @readurl = url_for(:host => SERVER_URL,
75 :controller => "message", :action => "read",
76 :message_id => message.id)
77 @replyurl = url_for(:host => SERVER_URL,
78 :controller => "message", :action => "reply",
79 :message_id => message.id)
80 @user_message_author = @from_user
82 attach_user_avatar(message.sender)
84 mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
85 :to => message.recipient.email,
86 :subject => I18n.t("notifier.message_notification.subject_header", :subject => message.title)
90 def diary_comment_notification(comment, recipient)
91 with_recipient_locale recipient do
92 @to_user = recipient.display_name
93 @from_user = comment.user.display_name
95 @title = comment.diary_entry.title
96 @readurl = url_for(:host => SERVER_URL,
97 :controller => "diary_entry",
99 :display_name => comment.diary_entry.user.display_name,
100 :id => comment.diary_entry.id,
101 :anchor => "comment#{comment.id}")
102 @commenturl = url_for(:host => SERVER_URL,
103 :controller => "diary_entry",
105 :display_name => comment.diary_entry.user.display_name,
106 :id => comment.diary_entry.id,
107 :anchor => "newcomment")
108 @replyurl = url_for(:host => SERVER_URL,
109 :controller => "message",
111 :display_name => comment.user.display_name,
112 :title => "Re: #{comment.diary_entry.title}")
113 @user_message_author = @from_user
115 attach_user_avatar(comment.user)
117 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest, recipient.id),
118 :to => recipient.email,
119 :subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
123 def friend_notification(friend)
124 with_recipient_locale friend.befriendee do
126 @viewurl = url_for(:host => SERVER_URL,
127 :controller => "user", :action => "view",
128 :display_name => @friend.befriender.display_name)
129 @friendurl = url_for(:host => SERVER_URL,
130 :controller => "user", :action => "make_friend",
131 :display_name => @friend.befriender.display_name)
132 @user_message_author = @friend.befriender.display_name
134 attach_user_avatar(@friend.befriender)
135 mail :to => friend.befriendee.email,
136 :subject => I18n.t("notifier.friend_notification.subject", :user => friend.befriender.display_name)
140 def note_comment_notification(comment, recipient)
141 with_recipient_locale recipient do
142 @noteurl = browse_note_url(comment.note, :host => SERVER_URL)
143 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
144 @comment = comment.body
145 @owner = recipient == comment.note.author
146 @event = comment.event
148 @commenter = if comment.author
149 comment.author.display_name
151 I18n.t("notifier.note_comment_notification.anonymous")
154 @user_message_author = @commenter
155 attach_user_avatar(comment.author)
158 I18n.t("notifier.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
160 I18n.t("notifier.note_comment_notification.#{@event}.subject_other", :commenter => @commenter)
163 mail :to => recipient.email, :subject => subject
167 def changeset_comment_notification(comment, recipient)
168 with_recipient_locale recipient do
169 @changeset_url = changeset_url(comment.changeset, :host => SERVER_URL)
170 @comment = comment.body
171 @owner = recipient == comment.changeset.user
172 @commenter = comment.author.display_name
173 @changeset_comment = comment.changeset.tags["comment"].presence
174 @time = comment.created_at
175 @changeset_author = comment.changeset.user.display_name
176 @user_message_author = @commenter
179 I18n.t("notifier.changeset_comment_notification.commented.subject_own", :commenter => @commenter)
181 I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter)
184 attach_user_avatar(comment.author)
186 mail :to => recipient.email, :subject => subject
192 def set_shared_template_vars
193 @root_url = root_url(:host => SERVER_URL)
197 def attach_project_logo
198 attachments.inline["logo.png"] = File.read("#{Rails.root}/app/assets/images/osm_logo_30.png")
201 def attach_user_avatar(user)
202 attachments.inline["avatar.png"] = File.read(user_avatar_file_path(user))
205 def user_avatar_file_path(user)
206 image = user && user.image
207 if image && image.file?
208 return image.path(:small)
210 return "#{Rails.root}/app/assets/images/users/images/small.png"
214 def with_recipient_locale(recipient)
215 I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do
220 def from_address(name, type, id, digest, user_id = nil)
221 if Object.const_defined?(:MESSAGES_DOMAIN) && domain = MESSAGES_DOMAIN
223 "#{name} <#{type}-#{id}-#{user_id}-#{digest[0, 6]}@#{domain}>"
225 "#{name} <#{type}-#{id}-#{digest[0, 6]}@#{domain}>"