Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 120
- Log:
Hub integration. RForum Users are lazy-created when Hub users, logged in,
visit RForum for the first time. RForum navigation links to log in and
out or change settings all point at Hub. Webmaster and adminstrator roles
in Hub map to administrator permissions in RForum; in addition to the
RForum permission management system, though, added Hub permissions hashes
to various controllers to include Hub authorisation too. Two layers can't
hurt and it means sensible return-to'd redirections to Hub for some
action types.Corrected grammar on deletion confirmation messages and tidied up a few
templates here and there, too.
- Author:
- adh
- Date:
- Sat Oct 28 23:53:03 +0100 2006
- Size:
- 3678 Bytes
1 | require 'url_generator' |
2 | require 'digest/md5' |
3 | require 'received_mail' |
4 | |
5 | class Mailer < ActionMailer::Base |
6 | |
7 | include RForum::Localization |
8 | |
9 | def registration_mail(user, password, login_url) |
10 | setup_email(user) |
11 | @subject += l(:welcome_to, RForum::CONFIG[:site_name]) |
12 | @body = { 'user' => user, 'password' => password, 'login_url' => login_url } |
13 | end |
14 | |
15 | def new_post_notification(user, post) |
16 | setup_email(user) |
17 | # TODO: how to get topic URL from here? |
18 | # TODO: take care of non-ASCII chars in subject |
19 | @subject += l(:new_post_in_thread, post.topic.subject) |
20 | @body['post_url'] = UrlGenerator.url_for(:controller => 'topic', :action => 'show', :id => post.topic_id, :anchor => post.id) |
21 | @body['disable_notification_url'] = UrlGenerator.url_for(:controller => 'topic', :action => 'unsubscribe', :id => post.topic_id) |
22 | @body['post'] = post |
23 | @body['user'] = user |
24 | end |
25 | |
26 | def reset_password(user, reset_password_url) |
27 | setup_email(user) |
28 | @subject += l(:reset_password_subject) |
29 | @body['user'] = user |
30 | @body['reset_password_url'] = reset_password_url |
31 | end |
32 | |
33 | def user_message(from, to, text) |
34 | setup_email(to) |
35 | @from = from.email |
36 | @subject += l(:user_message_from, from.firstname) |
37 | @body['text'] = Wraptools.wrap_ff(text, 72) |
38 | @body['from'] = from |
39 | @body['to'] = to |
40 | end |
41 | |
42 | def delete_post_notification(post) |
43 | setup_email(post.author) |
44 | @body['post'] = post |
45 | end |
46 | |
47 | def ml_post(post) |
48 | unless post.topic.forum.list_address |
49 | raise RuntimeError |
50 | end |
51 | |
52 | footer = "\n\n-- \nPosted via http://www.ruby-forum.com/." |
53 | @body = post.text + footer |
54 | |
55 | |
56 | if post.author.guest? |
57 | name = (post.author.guest_name || 'Guest').dup |
58 | email = post.author.guest_email |
59 | else |
60 | name = "#{post.author.firstname}" # Adding #{post.author.surname} not required in Hub; firstname already contains a full unique name |
61 | email = post.author.email |
62 | end |
63 | |
64 | if post.topic.forum.ml_from_address |
65 | email = post.topic.forum.ml_from_address |
66 | end |
67 | |
68 | @from = "#{name} <#{email}>" |
69 | |
70 | @subject = post.subject |
71 | @recipients = post.topic.forum.list_address |
72 | @sent_on = post.created_at |
73 | |
74 | @headers['Content-Type'] = "text/plain; charset=#{RForum::CONFIG[:mail_charset]}; format=flowed" |
75 | @headers['reply-to'] = post.topic.forum.list_address |
76 | #@headers["bcc"] = (users.collect { |u| u.email }).join "," |
77 | @headers['sender'] = @headers['errors-to'] = RForum::CONFIG[:bounce_address] |
78 | @headers['message-id'] = '<' + post.messageid + '>' |
79 | |
80 | if post.parent |
81 | @headers['in-reply-to'] = '<' + post.parent.messageid + '>' |
82 | @headers['references'] = post.get_references |
83 | end |
84 | |
85 | if headers = post.topic.forum.add_mail_headers |
86 | headers.each_line do |line| |
87 | key, value = line.split(/\s*:\s*/, 2) |
88 | @headers[key] = value |
89 | end |
90 | end |
91 | end |
92 | |
93 | def receive(email) |
94 | email.extend(ReceivedMail) |
95 | |
96 | end |
97 | |
98 | def self.process_email(raw) |
99 | email = self.receive(raw) |
100 | unless RForum::CONFIG[:accept_mail_from_guests] |
101 | if email.from_guest? |
102 | # TODO: bounce |
103 | raise 'email from guest' |
104 | end |
105 | |
106 | if email.from_unauthorized_user? |
107 | # TODO: bounce |
108 | raise 'email from unauthorized user' |
109 | end |
110 | end |
111 | |
112 | email.create_post |
113 | end |
114 | |
115 | protected |
116 | |
117 | def setup_email(user) |
118 | @recipients = user.email |
119 | @subject = "[#{RForum::CONFIG[:site_name]}] " |
120 | @from = RForum::CONFIG[:site_email] |
121 | @headers['Content-Type'] = "text/plain; charset=#{RForum::CONFIG[:mail_charset]}; format=flowed" |
122 | end |
123 | |
124 | def template_path |
125 | template_root + "/" + Inflector.underscore(self.class.name) + "/" + RForum::CONFIG[:default_language] |
126 | end |
127 | |
128 | end |