3 class Notifier < ActionMailer::Base
4 default :from => EMAIL_FROM,
5 :return_path => EMAIL_RETURN_PATH,
6 :auto_submitted => "auto-generated"
9 def signup_confirm(user, token)
10 with_recipient_locale user do
11 @url = url_for(:host => SERVER_URL,
12 :controller => "user", :action => "confirm",
13 :display_name => user.display_name,
14 :confirm_string => token.token)
16 mail :to => user.email,
17 :subject => I18n.t("notifier.signup_confirm.subject")
21 def email_confirm(user, token)
22 with_recipient_locale user do
23 @address = user.new_email
24 @url = url_for(:host => SERVER_URL,
25 :controller => "user", :action => "confirm_email",
26 :confirm_string => token.token)
28 mail :to => user.new_email,
29 :subject => I18n.t("notifier.email_confirm.subject")
33 def lost_password(user, token)
34 with_recipient_locale user do
35 @url = url_for(:host => SERVER_URL,
36 :controller => "user", :action => "reset_password",
37 :token => token.token)
39 mail :to => user.email,
40 :subject => I18n.t("notifier.lost_password.subject")
44 def gpx_success(trace, possible_points)
45 with_recipient_locale trace.user do
46 @trace_name = trace.name
47 @trace_points = trace.size
48 @trace_description = trace.description
49 @trace_tags = trace.tags
50 @possible_points = possible_points
52 mail :to => trace.user.email,
53 :subject => I18n.t("notifier.gpx_notification.success.subject")
57 def gpx_failure(trace, error)
58 with_recipient_locale trace.user do
59 @trace_name = trace.name
60 @trace_description = trace.description
61 @trace_tags = trace.tags
64 mail :to => trace.user.email,
65 :subject => I18n.t("notifier.gpx_notification.failure.subject")
69 def message_notification(message)
70 with_recipient_locale message.recipient do
71 @to_user = message.recipient.display_name
72 @from_user = message.sender.display_name
74 @title = message.title
75 @readurl = url_for(:host => SERVER_URL,
76 :controller => "message", :action => "read",
77 :message_id => message.id)
78 @replyurl = url_for(:host => SERVER_URL,
79 :controller => "message", :action => "reply",
80 :message_id => message.id)
82 mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
83 :to => message.recipient.email,
84 :subject => I18n.t("notifier.message_notification.subject_header", :subject => message.title)
88 def diary_comment_notification(comment, recipient)
89 with_recipient_locale recipient do
90 @to_user = recipient.display_name
91 @from_user = comment.user.display_name
93 @title = comment.diary_entry.title
94 @readurl = url_for(:host => SERVER_URL,
95 :controller => "diary_entry",
97 :display_name => comment.diary_entry.user.display_name,
98 :id => comment.diary_entry.id,
99 :anchor => "comment#{comment.id}")
100 @commenturl = url_for(:host => SERVER_URL,
101 :controller => "diary_entry",
103 :display_name => comment.diary_entry.user.display_name,
104 :id => comment.diary_entry.id,
105 :anchor => "newcomment")
106 @replyurl = url_for(:host => SERVER_URL,
107 :controller => "message",
109 :display_name => comment.user.display_name,
110 :title => "Re: #{comment.diary_entry.title}")
112 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest, recipient.id),
113 :to => recipient.email,
114 :subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
118 def friend_notification(friend)
119 with_recipient_locale friend.befriendee do
121 @viewurl = url_for(:host => SERVER_URL,
122 :controller => "user", :action => "view",
123 :display_name => @friend.befriender.display_name)
124 @friendurl = url_for(:host => SERVER_URL,
125 :controller => "user", :action => "make_friend",
126 :display_name => @friend.befriender.display_name)
128 mail :to => friend.befriendee.email,
129 :subject => I18n.t("notifier.friend_notification.subject", :user => friend.befriender.display_name)
133 def note_comment_notification(comment, recipient)
134 with_recipient_locale recipient do
135 @noteurl = browse_note_url(comment.note, :host => SERVER_URL)
136 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
137 @comment = comment.body
138 @owner = recipient == comment.note.author
139 @event = comment.event
141 @commenter = if comment.author
142 comment.author.display_name
144 I18n.t("notifier.note_comment_notification.anonymous")
148 I18n.t("notifier.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
150 I18n.t("notifier.note_comment_notification.#{@event}.subject_other", :commenter => @commenter)
153 mail :to => recipient.email, :subject => subject
157 def changeset_comment_notification(comment, recipient)
158 with_recipient_locale recipient do
159 @root_url = root_url(:host => SERVER_URL)
160 @changeset_url = changeset_url(comment.changeset, :host => SERVER_URL)
161 @comment = comment.body
162 @owner = recipient == comment.changeset.user
163 @commenter = comment.author.display_name
164 @commenter_url = user_url(comment.author.display_name, :host => SERVER_URL)
165 @commenter_thumbnail_src = comment.author.image.url(:small, :host => SERVER_URL)
166 @changeset_comment = comment.changeset.tags["comment"].presence
167 @time = comment.created_at
168 @changeset_author = comment.changeset.user.display_name
171 I18n.t("notifier.changeset_comment_notification.commented.subject_own", :commenter => @commenter)
173 I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter)
176 attachments.inline['logo.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'osm_logo_30.png'))
177 attachments.inline['avatar.png'] = File.read(user_avatar_file_path(comment.author))
179 mail :to => recipient.email, :subject => subject
185 def user_avatar_file_path(user)
188 return image.path.sub('/original/', '/small/')
190 return Rails.root.join('app', 'assets', 'images', 'users', 'images', 'small.png')
194 def with_recipient_locale(recipient)
195 I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do
200 def from_address(name, type, id, digest, user_id = nil)
201 if Object.const_defined?(:MESSAGES_DOMAIN) && domain = MESSAGES_DOMAIN
203 "#{name} <#{type}-#{id}-#{user_id}-#{digest[0, 6]}@#{domain}>"
205 "#{name} <#{type}-#{id}-#{digest[0, 6]}@#{domain}>"