]> git.openstreetmap.org Git - rails.git/blob - app/models/notifier.rb
Use a script to pull in host blocks and add some robot blocks from
[rails.git] / app / models / notifier.rb
1 class Notifier < ActionMailer::Base
2   def signup_confirm(user, token)
3     common_headers user
4     subject I18n.t('notifier.signup_confirm.subject')
5     body :url => url_for(:host => SERVER_URL,
6                          :controller => "user", :action => "confirm",
7                          :confirm_string => token.token)
8   end
9
10   def email_confirm(user, token)
11     common_headers user
12     recipients user.new_email
13     subject I18n.t('notifier.email_confirm.subject')
14     body :address => user.new_email,
15          :url => url_for(:host => SERVER_URL,
16                          :controller => "user", :action => "confirm_email",
17                          :confirm_string => token.token)
18   end
19
20   def lost_password(user, token)
21     common_headers user
22     subject I18n.t('notifier.lost_password.subject')
23     body :url => url_for(:host => SERVER_URL,
24                          :controller => "user", :action => "reset_password",
25                          :token => token.token)
26   end
27
28   def gpx_success(trace, possible_points)
29     common_headers trace.user
30     subject I18n.t('notifier.gpx_notification.success.subject')
31     body :trace_name => trace.name,
32          :trace_points => trace.size,
33          :trace_description => trace.description,
34          :trace_tags => trace.tags,
35          :possible_points => possible_points
36   end
37
38   def gpx_failure(trace, error)
39     common_headers trace.user
40     from "webmaster@openstreetmap.org"
41     subject I18n.t('notifier.gpx_notification.failure.subject')
42     body :trace_name => trace.name,
43          :trace_description => trace.description,
44          :trace_tags => trace.tags,
45          :error => error
46   end
47   
48   def message_notification(message)
49     common_headers message.recipient
50     from_header message.sender.display_name, "m", message.id, message.digest
51     subject I18n.t('notifier.message_notification.subject', :user => message.sender.display_name, :locale => locale)
52     body :to_user => message.recipient.display_name,
53          :from_user => message.sender.display_name,
54          :body => message.body,
55          :title => message.title,
56          :readurl => url_for(:host => SERVER_URL,
57                              :controller => "message", :action => "read",
58                              :message_id => message.id),
59          :replyurl => url_for(:host => SERVER_URL,
60                               :controller => "message", :action => "reply",
61                               :message_id => message.id)
62   end
63
64   def diary_comment_notification(comment)
65     common_headers comment.diary_entry.user
66     from_header comment.user.display_name, "c", comment.id, comment.digest
67     subject I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name, :locale => locale)
68     body :to_user => comment.diary_entry.user.display_name,
69          :from_user => comment.user.display_name,
70          :body => comment.body,
71          :title => comment.diary_entry.title,
72          :readurl => url_for(:host => SERVER_URL,
73                              :controller => "diary_entry",
74                              :action => "view",
75                              :display_name => comment.diary_entry.user.display_name,
76                              :id => comment.diary_entry.id,
77                              :anchor => "comment#{comment.id}"),
78          :commenturl => url_for(:host => SERVER_URL,
79                                 :controller => "diary_entry",
80                                 :action => "view",
81                                 :display_name => comment.diary_entry.user.display_name,
82                                 :id => comment.diary_entry.id,
83                                 :anchor => "newcomment"),
84          :replyurl => url_for(:host => SERVER_URL,
85                               :controller => "message",
86                               :action => "new",
87                               :user_id => comment.user.id,
88                               :title => "Re: #{comment.diary_entry.title}")
89   end
90
91   def friend_notification(friend)
92     befriender = User.find_by_id(friend.user_id)
93     befriendee = User.find_by_id(friend.friend_user_id)
94
95     common_headers befriendee
96     subject I18n.t('notifier.friend_notification.subject', :user => befriender.display_name, :locale => locale)
97     body :user => befriender.display_name,
98          :userurl => url_for(:host => SERVER_URL,
99                              :controller => "user", :action => "view",
100                              :display_name => befriender.display_name)
101   end
102
103 private
104
105   def common_headers(recipient)
106     recipients recipient.email
107     locale recipient.preferred_language_from(I18n.available_locales)
108     from "OpenStreetMap <webmaster@openstreetmap.org>"
109     headers "return-path" => "bounces@openstreetmap.org",
110             "Auto-Submitted" => "auto-generated"
111   end
112
113   def from_header(name, type, id, digest)
114     if domain = APP_CONFIG['messages_domain']
115       from quote_address_if_necessary("#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>", "utf-8")
116     end
117   end
118 end