1 class Notifier < ActionMailer::Base
2 default :from => EMAIL_FROM,
3 :return_path => EMAIL_RETURN_PATH,
4 :auto_submitted => "auto-generated"
7 def signup_confirm(user, token)
8 with_recipient_locale user do
9 @url = url_for(:host => SERVER_URL,
10 :controller => "user", :action => "confirm",
11 :display_name => user.display_name,
12 :confirm_string => token.token)
14 mail :to => user.email,
15 :subject => I18n.t("notifier.signup_confirm.subject")
19 def email_confirm(user, token)
20 with_recipient_locale user do
21 @address = user.new_email
22 @url = url_for(:host => SERVER_URL,
23 :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(:host => SERVER_URL,
34 :controller => "user", :action => "reset_password",
35 :token => token.token)
37 mail :to => user.email,
38 :subject => I18n.t("notifier.lost_password.subject")
42 def gpx_success(trace, possible_points)
43 with_recipient_locale trace.user do
44 @trace_name = trace.name
45 @trace_points = trace.size
46 @trace_description = trace.description
47 @trace_tags = trace.tags
48 @possible_points = possible_points
50 mail :to => trace.user.email,
51 :subject => I18n.t("notifier.gpx_notification.success.subject")
55 def gpx_failure(trace, error)
56 with_recipient_locale trace.user do
57 @trace_name = trace.name
58 @trace_description = trace.description
59 @trace_tags = trace.tags
62 mail :to => trace.user.email,
63 :subject => I18n.t("notifier.gpx_notification.failure.subject")
67 def message_notification(message)
68 with_recipient_locale message.recipient do
69 @to_user = message.recipient.display_name
70 @from_user = message.sender.display_name
72 @title = message.title
73 @readurl = url_for(:host => SERVER_URL,
74 :controller => "message", :action => "read",
75 :message_id => message.id)
76 @replyurl = url_for(:host => SERVER_URL,
77 :controller => "message", :action => "reply",
78 :message_id => message.id)
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)
87 with_recipient_locale comment.diary_entry.user do
88 @to_user = comment.diary_entry.user.display_name
89 @from_user = comment.user.display_name
91 @title = comment.diary_entry.title
92 @readurl = url_for(:host => SERVER_URL,
93 :controller => "diary_entry",
95 :display_name => comment.diary_entry.user.display_name,
96 :id => comment.diary_entry.id,
97 :anchor => "comment#{comment.id}")
98 @commenturl = url_for(:host => SERVER_URL,
99 :controller => "diary_entry",
101 :display_name => comment.diary_entry.user.display_name,
102 :id => comment.diary_entry.id,
103 :anchor => "newcomment")
104 @replyurl = url_for(:host => SERVER_URL,
105 :controller => "message",
107 :display_name => comment.user.display_name,
108 :title => "Re: #{comment.diary_entry.title}")
110 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
111 :to => comment.diary_entry.user.email,
112 :subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
116 def friend_notification(friend)
117 with_recipient_locale friend.befriendee do
120 mail :to => friend.befriendee.email,
121 :subject => I18n.t("notifier.friend_notification.subject", :user => friend.befriender.display_name)
125 def note_comment_notification(comment, recipient)
126 with_recipient_locale recipient do
127 @noteurl = browse_note_url(comment.note, :host => SERVER_URL)
128 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
129 @comment = comment.body
130 @owner = recipient == comment.note.author
131 @event = comment.event
134 @commenter = comment.author.display_name
136 @commenter = I18n.t("notifier.note_comment_notification.anonymous")
140 subject = I18n.t("notifier.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
142 subject = I18n.t("notifier.note_comment_notification.#{@event}.subject_other", :commenter => @commenter)
145 mail :to => recipient.email, :subject => subject
149 def changeset_comment_notification(comment, recipient)
150 with_recipient_locale recipient do
151 @changeset_url = changeset_url(comment.changeset, :host => SERVER_URL)
152 @comment = comment.body
153 @owner = recipient == comment.changeset.user
154 @commenter = comment.author.display_name
155 @changeset_comment = comment.changeset.tags["comment"].presence
156 @time = comment.created_at
157 @changeset_author = comment.changeset.user.display_name
160 subject = I18n.t("notifier.changeset_comment_notification.commented.subject_own", :commenter => @commenter)
162 subject = I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter)
165 mail :to => recipient.email, :subject => subject
171 def with_recipient_locale(recipient)
172 old_locale = I18n.locale
175 I18n.locale = recipient.preferred_language_from(I18n.available_locales)
179 I18n.locale = old_locale
183 def from_address(name, type, id, digest)
184 if Object.const_defined?(:MESSAGES_DOMAIN) && domain = MESSAGES_DOMAIN
185 "#{name} <#{type}-#{id}-#{digest[0, 6]}@#{domain}>"