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 @locale = user.preferred_language_from(I18n.available_locales)
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', :locale => @locale)
18 def email_confirm(user, token)
19 @locale = user.preferred_language_from(I18n.available_locales)
20 @address = user.new_email
21 @url = url_for(:host => SERVER_URL,
22 :controller => "user", :action => "confirm_email",
23 :confirm_string => token.token)
25 mail :to => user.new_email,
26 :subject => I18n.t('notifier.email_confirm.subject', :locale => @locale)
29 def lost_password(user, token)
30 @locale = user.preferred_language_from(I18n.available_locales)
31 @url = url_for(:host => SERVER_URL,
32 :controller => "user", :action => "reset_password",
33 :token => token.token)
35 mail :to => user.email,
36 :subject => I18n.t('notifier.lost_password.subject', :locale => @locale)
39 def gpx_success(trace, possible_points)
40 @locale = trace.user.preferred_language_from(I18n.available_locales)
41 @trace_name = trace.name
42 @trace_points = trace.size
43 @trace_description = trace.description
44 @trace_tags = trace.tags
45 @possible_points = possible_points
47 mail :to => trace.user.email,
48 :subject => I18n.t('notifier.gpx_notification.success.subject', :locale => @locale)
51 def gpx_failure(trace, error)
52 @locale = trace.user.preferred_language_from(I18n.available_locales)
53 @trace_name = trace.name
54 @trace_description = trace.description
55 @trace_tags = trace.tags
58 mail :to => trace.user.email,
59 :subject => I18n.t('notifier.gpx_notification.failure.subject', :locale => @locale)
62 def message_notification(message)
63 @locale = message.recipient.preferred_language_from(I18n.available_locales)
64 @to_user = message.recipient.display_name
65 @from_user = message.sender.display_name
67 @title = message.title
68 @readurl = url_for(:host => SERVER_URL,
69 :controller => "message", :action => "read",
70 :message_id => message.id)
71 @replyurl = url_for(:host => SERVER_URL,
72 :controller => "message", :action => "reply",
73 :message_id => message.id)
75 mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
76 :to => message.recipient.email,
77 :subject => I18n.t('notifier.message_notification.subject_header', :subject => message.title, :locale => @locale)
80 def diary_comment_notification(comment)
81 @locale = comment.diary_entry.user.preferred_language_from(I18n.available_locales)
82 @to_user = comment.diary_entry.user.display_name
83 @from_user = comment.user.display_name
85 @title = comment.diary_entry.title
86 @readurl = url_for(:host => SERVER_URL,
87 :controller => "diary_entry",
89 :display_name => comment.diary_entry.user.display_name,
90 :id => comment.diary_entry.id,
91 :anchor => "comment#{comment.id}")
92 @commenturl = 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 => "newcomment")
98 @replyurl = url_for(:host => SERVER_URL,
99 :controller => "message",
101 :display_name => comment.user.display_name,
102 :title => "Re: #{comment.diary_entry.title}")
104 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
105 :to => comment.diary_entry.user.email,
106 :subject => I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name, :locale => @locale)
109 def friend_notification(friend)
110 @locale = friend.befriendee.preferred_language_from(I18n.available_locales)
113 mail :to => friend.befriendee.email,
114 :subject => I18n.t('notifier.friend_notification.subject', :user => friend.befriender.display_name, :locale => @locale)
117 def note_comment_notification(comment, recipient)
118 @locale = recipient.preferred_language_from(I18n.available_locales)
119 @noteurl = browse_note_url(comment.note, :host => SERVER_URL)
120 @place = comment.note.nearby_place
121 @comment =comment.body
122 @owner = recipient == comment.note.author
123 @commenter = comment.author_name
125 subject = I18n.t('notifier.note_comment_notification.subject_own', :commenter => comment.author_name) if @owner
126 subject = I18n.t('notifier.note_comment_notification.subject_other', :commenter => comment.author_name) unless @owner
128 mail :to => recipient.email, :subject => subject
133 def from_address(name, type, id, digest)
134 if Object.const_defined?(:MESSAGES_DOMAIN) and domain = MESSAGES_DOMAIN
135 "#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>"