sugoi-mail 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +35 -0
- data/Rakefile +10 -0
- data/app/apis/mailservice_api.rb +178 -0
- data/app/controllers/.sugoi_admin_controller.rb.swp +0 -0
- data/app/controllers/account_controller.rb +39 -0
- data/app/controllers/address_controller.rb +49 -0
- data/app/controllers/application.rb +4 -0
- data/app/controllers/commandline_controller.rb +15 -0
- data/app/controllers/domain_controller.rb +37 -0
- data/app/controllers/mailinglist_controller.rb +51 -0
- data/app/controllers/mailservice_controller.rb +497 -0
- data/app/controllers/sugoi_admin_controller.rb +93 -0
- data/app/helpers/account_helper.rb +2 -0
- data/app/helpers/address_helper.rb +2 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/domain_helper.rb +2 -0
- data/app/helpers/mailservice_helper.rb +2 -0
- data/app/helpers/sugoi_admin_helper.rb +2 -0
- data/app/models/address.rb +110 -0
- data/app/models/admin_message.rb +45 -0
- data/app/models/confirmationcode.rb +59 -0
- data/app/models/domain.rb +76 -0
- data/app/models/mailinglist.rb +336 -0
- data/app/models/mailinglist_class.rb +39 -0
- data/app/models/message.rb +293 -0
- data/app/models/proxy_link.rb +25 -0
- data/app/models/user.rb +150 -0
- data/app/views/account/login.rhtml +22 -0
- data/app/views/account/logout.rhtml +10 -0
- data/app/views/account/signup.rhtml +17 -0
- data/app/views/account/welcome.rhtml +13 -0
- data/app/views/address/_form.rhtml +7 -0
- data/app/views/address/edit.rhtml +10 -0
- data/app/views/address/list.rhtml +27 -0
- data/app/views/address/new.rhtml +8 -0
- data/app/views/address/show.rhtml +8 -0
- data/app/views/domain/login.rhtml +22 -0
- data/app/views/domain/logout.rhtml +10 -0
- data/app/views/domain/signup.rhtml +17 -0
- data/app/views/domain/welcome.rhtml +13 -0
- data/app/views/layouts/address.rhtml +13 -0
- data/app/views/layouts/scaffold.rhtml +13 -0
- data/app/views/mailinglist/_form.rhtml +28 -0
- data/app/views/mailinglist/edit.rhtml +10 -0
- data/app/views/mailinglist/list.rhtml +27 -0
- data/app/views/mailinglist/new.rhtml +8 -0
- data/app/views/mailinglist/show.rhtml +16 -0
- data/app/views/sugoi_admin/create_domain.rhtml +1 -0
- data/app/views/sugoi_admin/list_addresses.rhtml +1 -0
- data/app/views/sugoi_admin/list_domains.rhtml +2 -0
- data/app/views/sugoi_admin/list_mailinglists.rhtml +1 -0
- data/bin/mailc +32 -0
- data/bin/maild +133 -0
- data/bin/sugoi-admin +21 -0
- data/bin/sugoi-mail +20 -0
- data/config/boot.rb +44 -0
- data/config/environment.rb +54 -0
- data/config/environments/bench.rb +21 -0
- data/config/environments/coverage.rb +21 -0
- data/config/environments/development.rb +21 -0
- data/config/environments/production.rb +18 -0
- data/config/environments/test.rb +19 -0
- data/config/lighttpd.conf +46 -0
- data/config/routes.rb +29 -0
- data/db/migrate/001_mailproxy.rb +7 -0
- data/db/migrate/002_create_users.rb +13 -0
- data/db/migrate/003_create_mailinglists.rb +13 -0
- data/db/migrate/004_create_addresses.rb +12 -0
- data/db/migrate/005_create_addresses_mailinglists.rb +13 -0
- data/db/migrate/006_alter_mailinglists.rb +9 -0
- data/db/migrate/007_create_messages.rb +25 -0
- data/db/migrate/008_add_mailinglistid_to_users.rb +14 -0
- data/db/migrate/009_add_domainadmin_to_users.rb +9 -0
- data/db/migrate/010_add_domain_to_users.rb +16 -0
- data/db/migrate/011_add_active_to_addresses.rb +14 -0
- data/db/migrate/012_create_confirmationcodes.rb +14 -0
- data/db/migrate/013_add_description_to_mailinglists.rb +9 -0
- data/db/migrate/014_create_admin_messages.rb +69 -0
- data/db/migrate/015_add_messages_to_mailinglists.rb +26 -0
- data/db/migrate/016_add_mailinglist_admin_to_users.rb +9 -0
- data/db/migrate/017_add_mailinglist_types.rb +94 -0
- data/db/migrate/018_add_bounciness_to_addresses.rb +20 -0
- data/db/migrate/019_add_archived_to_mailinglist_classes.rb +25 -0
- data/db/migrate/020_add_envelope_data_to_messages.rb +11 -0
- data/db/migrate/021_add_addresses_users.rb +14 -0
- data/db/migrate/022_add_virtual_to_users.rb +14 -0
- data/db/migrate/023_drop_openposting_from_mailinglists.rb +9 -0
- data/db/migrate/024_add_proxy_links.rb +21 -0
- data/db/migrate/025_add_proxify_to_mailinglist_classes.rb +25 -0
- data/db/schema.mysql.sql +104 -0
- data/db/schema.postgresql.sql +104 -0
- data/db/schema.rb +85 -0
- data/db/schema.sqlite.sql +104 -0
- data/db/schema.sqlserver.sql +113 -0
- data/db/schema_version +1 -0
- data/doc/README_FOR_APP +179 -0
- data/doc/mailinglist_classes description.txt +28 -0
- data/installer/rails_installer_defaults.yml +5 -0
- data/lib/daemonize.rb +56 -0
- data/lib/domain_system.rb +87 -0
- data/lib/gurgitate-rules.rb +69 -0
- data/lib/limitedfork.rb +66 -0
- data/lib/login_system.rb +87 -0
- data/public/.htaccess +40 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/dispatch.cgi +10 -0
- data/public/dispatch.fcgi +24 -0
- data/public/dispatch.rb +10 -0
- data/public/favicon.ico +0 -0
- data/public/images/rails.png +0 -0
- data/public/javascripts/application.js +2 -0
- data/public/javascripts/controls.js +815 -0
- data/public/javascripts/dragdrop.js +913 -0
- data/public/javascripts/effects.js +958 -0
- data/public/javascripts/prototype.js +2006 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/scaffold.css +74 -0
- data/public/stylesheets/trestle.css +74 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/fakedeliver +19 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/sugoi-mail.gemspec +36 -0
- data/test/fixtures/addresses.yml +70 -0
- data/test/fixtures/addresses_mailinglists.yml +20 -0
- data/test/fixtures/admin_messages.yml +65 -0
- data/test/fixtures/confirmationcodes.yml +13 -0
- data/test/fixtures/domains.yml +9 -0
- data/test/fixtures/mailinglist_classes.yml +45 -0
- data/test/fixtures/mailinglists.yml +80 -0
- data/test/fixtures/messages.yml +154 -0
- data/test/fixtures/proxy_links.yml +5 -0
- data/test/fixtures/users.yml +50 -0
- data/test/functional/domain_controller_test.rb +74 -0
- data/test/functional/mailservice_controller_test.rb +546 -0
- data/test/integration/test_soap.rb +413 -0
- data/test/integration/test_xmlrpc.rb +198 -0
- data/test/mocks/test/net-smtp-stub.rb +24 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/address_test.rb +44 -0
- data/test/unit/admin_message_test.rb +41 -0
- data/test/unit/confirmationcode_test.rb +64 -0
- data/test/unit/domain_test.rb +128 -0
- data/test/unit/mailinglist_class_test.rb +82 -0
- data/test/unit/mailinglist_test.rb +145 -0
- data/test/unit/message_test.rb +151 -0
- data/test/unit/user_test.rb +126 -0
- data/test/units.rb +4 -0
- data/vendor/plugins/active_command/init.rb +1 -0
- data/vendor/plugins/active_command/lib/active_command/request.rb +137 -0
- data/vendor/plugins/active_command/lib/active_command/response.rb +132 -0
- data/vendor/plugins/active_command/lib/active_command.rb +2 -0
- data/vendor/plugins/ar_fixtures/CHANGELOG +10 -0
- data/vendor/plugins/ar_fixtures/MIT-LICENSE +20 -0
- data/vendor/plugins/ar_fixtures/README +19 -0
- data/vendor/plugins/ar_fixtures/Rakefile +54 -0
- data/vendor/plugins/ar_fixtures/about.yml +7 -0
- data/vendor/plugins/ar_fixtures/init.rb +1 -0
- data/vendor/plugins/ar_fixtures/lib/ar_fixtures.rb +102 -0
- data/vendor/plugins/ar_fixtures/tasks/ar_fixtures.rake +39 -0
- data/vendor/plugins/ar_fixtures/test/ar_fixtures_test.rb +53 -0
- data/vendor/plugins/ar_fixtures/test/database.yml +18 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/beer.rb +5 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/beers.yml +9 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/beers_drunkards.yml +8 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/drunkard.rb +6 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/drunkards.yml +8 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/glass.rb +2 -0
- data/vendor/plugins/ar_fixtures/test/fixtures/glasses.yml +9 -0
- data/vendor/plugins/ar_fixtures/test/schema.rb +21 -0
- data/vendor/plugins/ar_fixtures/test/test_helper.rb +37 -0
- metadata +320 -0
@@ -0,0 +1,497 @@
|
|
1
|
+
# = Using sugoi-mail in your own web applications
|
2
|
+
#
|
3
|
+
# Sugoi-Mail provides a SOAP (and XMLRPC) API to let you embed it into
|
4
|
+
# your own web appplication without using its own interface. (This is
|
5
|
+
# handy if, for example, you want to make a Xoops or Drupal module for
|
6
|
+
# it.)
|
7
|
+
#
|
8
|
+
# To use the web service, first you need to have a Domain account on
|
9
|
+
# the server. Let's say that your domain is "example.com" and the
|
10
|
+
# password for example.com is "example".
|
11
|
+
#
|
12
|
+
# You'd start a session with Sugoi-Mail by logging into the domain. I'm
|
13
|
+
# going to use SOAP as my example API, with the assumption that you've
|
14
|
+
# already had wsdl2ruby build a client library for you with.
|
15
|
+
# *MAKE SURE THAT COOKIES ARE ENABLED IN YOUR SOAP CLIENT!*
|
16
|
+
#
|
17
|
+
# wsdl2ruby --wsdl http://sugoi-mail-server/wsdl --type client
|
18
|
+
#
|
19
|
+
# This being done, you'd connect like this:
|
20
|
+
#
|
21
|
+
# client = MailserviceMailservicePort.new
|
22
|
+
# client.domainLogin "example.com", "example"
|
23
|
+
#
|
24
|
+
# This is how the web application logs in. Once the application is
|
25
|
+
# logged in, then the user (let's keep the "example" theme going with a
|
26
|
+
# username of "example" and a password of "password") can log in:
|
27
|
+
#
|
28
|
+
# client.userLogin "example", "password"
|
29
|
+
#
|
30
|
+
# Once the user's logged in, then your application can call the user_*
|
31
|
+
# functions--for example, to retrieve the user's email address, use
|
32
|
+
# the UserEmailAddress call:
|
33
|
+
#
|
34
|
+
# emailaddress = client.userEmailAddress # returns "example@example.com"
|
35
|
+
#
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# If you log in as an "admin" user, then all of the admin_* messages are
|
39
|
+
# also available to you.
|
40
|
+
class MailserviceController < ApplicationController
|
41
|
+
wsdl_service_name "Mailservice"
|
42
|
+
web_service_api MailserviceApi
|
43
|
+
web_service_scaffold :invoke
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def domain_logged_in?
|
48
|
+
raise "Not logged into domain" unless @session[:domain]
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_logged_in?
|
53
|
+
domain_logged_in?
|
54
|
+
raise "Not logged in as user" unless @session[:user]
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def user_admin?
|
60
|
+
user_logged_in?
|
61
|
+
raise "No privileges to perform that operation" unless @session[:user].domainadmin?
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Verifies whether a mailing list belongs to the currently-logged-in
|
66
|
+
# user or not.
|
67
|
+
def my_mailing_list (mailinglist_id)
|
68
|
+
user_logged_in?
|
69
|
+
mailinglist = Mailinglist.find_by_id(mailinglist_id)
|
70
|
+
raise "Mailing list not found" unless mailinglist
|
71
|
+
unless @session[:user].id == mailinglist.user_id
|
72
|
+
begin
|
73
|
+
user_admin?
|
74
|
+
rescue
|
75
|
+
raise "Permission denied"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
mailinglist
|
79
|
+
end
|
80
|
+
|
81
|
+
public
|
82
|
+
|
83
|
+
#========================================================================
|
84
|
+
# Server methods
|
85
|
+
#========================================================================
|
86
|
+
|
87
|
+
# Use this to ensure that the SOAP connection is still alive and
|
88
|
+
# responding. This and domain_logged_in are the only API methods
|
89
|
+
# that don't require any kind of authentication.
|
90
|
+
def ping
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
#========================================================================
|
95
|
+
# domain methods
|
96
|
+
#========================================================================
|
97
|
+
|
98
|
+
# Log into the domain.
|
99
|
+
def domain_login domainname, password
|
100
|
+
@session[:domain]=Domain.authenticate domainname, password
|
101
|
+
domain_logged_in
|
102
|
+
end
|
103
|
+
|
104
|
+
# Log out of the domain.
|
105
|
+
def domain_logout
|
106
|
+
if @session[:domain] then
|
107
|
+
@session[:domain] = nil
|
108
|
+
true
|
109
|
+
else
|
110
|
+
false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Verify whether the domain is logged in or not.
|
115
|
+
def domain_logged_in
|
116
|
+
not @session[:domain].nil?
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns the domain name.
|
120
|
+
def domain_name
|
121
|
+
@session[:domain].name
|
122
|
+
end
|
123
|
+
|
124
|
+
# == Administrator methods
|
125
|
+
|
126
|
+
# Returns true if the user is an administrator and false otherwise
|
127
|
+
def is_admin
|
128
|
+
user_admin? rescue false
|
129
|
+
end
|
130
|
+
|
131
|
+
# Creates a new user. NOTE: This method requires that you're
|
132
|
+
# already signed in as an administrator.
|
133
|
+
def admin_user_signup login, password, password_confirmation
|
134
|
+
user_admin?
|
135
|
+
|
136
|
+
user=User.new
|
137
|
+
|
138
|
+
if user then
|
139
|
+
user.login=login
|
140
|
+
user.domain=@session[:domain]
|
141
|
+
user.password=password
|
142
|
+
user.password_confirmation=password_confirmation
|
143
|
+
if user.save then
|
144
|
+
true
|
145
|
+
else
|
146
|
+
raise user.errors.sort.map { |e| "#{e[0]}: #{e[1]}" }.join("\n")
|
147
|
+
end
|
148
|
+
else
|
149
|
+
return false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns all users in this domain.
|
154
|
+
def admin_user_list
|
155
|
+
user_admin?
|
156
|
+
|
157
|
+
all_users=User.find_all_by_domain_id @session[:domain].id
|
158
|
+
return all_users.map { |u| [ u.login, u.description ] }
|
159
|
+
end
|
160
|
+
|
161
|
+
# Resets a user's password.
|
162
|
+
def admin_user_reset_password login, password, password_confirmation
|
163
|
+
user_admin?
|
164
|
+
|
165
|
+
user=User.find_by_login login
|
166
|
+
if user then
|
167
|
+
user.password=password
|
168
|
+
user.password_confirmation=password_confirmation
|
169
|
+
if user.save then
|
170
|
+
true
|
171
|
+
else
|
172
|
+
raise user.errors.sort.map { |e| "#{e[0]}: #{e[1]}" }.join("\n")
|
173
|
+
end
|
174
|
+
else
|
175
|
+
raise "user: user not found"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# Deletes a user.
|
180
|
+
def admin_user_delete login, login_confirmation
|
181
|
+
user_admin?
|
182
|
+
|
183
|
+
if login_confirmation != login then
|
184
|
+
raise "Login and login confirmation not the same"
|
185
|
+
end
|
186
|
+
|
187
|
+
u=User.find_by_login login
|
188
|
+
if u then
|
189
|
+
u.destroy
|
190
|
+
return true
|
191
|
+
else
|
192
|
+
return false
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns the confirmation code for a particular combination of
|
197
|
+
# mailing list and address.
|
198
|
+
#
|
199
|
+
# This one should probably resend the confirmation message.
|
200
|
+
def admin_get_confirmation_code mailinglist_name, address
|
201
|
+
user_admin?
|
202
|
+
|
203
|
+
m=Mailinglist.find_by_name(mailinglist_name)
|
204
|
+
a=Address.find_by_address(address)
|
205
|
+
c=Confirmationcode.find(:first,:conditions => [
|
206
|
+
'mailinglist_id = ? and address_id = ?', m.id, a.id
|
207
|
+
])
|
208
|
+
return c.code
|
209
|
+
end
|
210
|
+
|
211
|
+
# Returns all mailing lists in this domain.
|
212
|
+
def admin_mailinglists_all
|
213
|
+
user_admin?
|
214
|
+
|
215
|
+
Mailinglist.find_by_domain(@session[:domain]).map { |ml| ml.id }
|
216
|
+
end
|
217
|
+
|
218
|
+
#========================================================================
|
219
|
+
# user methods
|
220
|
+
#========================================================================
|
221
|
+
|
222
|
+
# Logs the user in. If the user logs in successfully, returns true,
|
223
|
+
# otherwise false.
|
224
|
+
def user_login username, password
|
225
|
+
domain_logged_in?
|
226
|
+
@session[:user]=User.authenticate username, password
|
227
|
+
user_logged_in
|
228
|
+
end
|
229
|
+
|
230
|
+
# Logs the user out.
|
231
|
+
def user_logout; @session[:user] = nil; end
|
232
|
+
|
233
|
+
# Returns whether the user is logged in or not.
|
234
|
+
def user_logged_in; not @session[:user].nil?; end
|
235
|
+
|
236
|
+
# Returns the user's username.
|
237
|
+
def user_name; @session[:user].login; end
|
238
|
+
|
239
|
+
# Returns all the mailing lists that belong to this user.
|
240
|
+
def user_mailinglists
|
241
|
+
user_logged_in?
|
242
|
+
Mailinglist.find_all_by_user_id(@session[:user].id).map { |m| m.id } -
|
243
|
+
[ @session[:user].mailinglist_id ]
|
244
|
+
end
|
245
|
+
|
246
|
+
# Returns the user's email address.
|
247
|
+
def user_email_address
|
248
|
+
user_logged_in?
|
249
|
+
@session[:user].address
|
250
|
+
end
|
251
|
+
|
252
|
+
# Returns all addresses belonging to this user.
|
253
|
+
def user_email_addresses
|
254
|
+
user_logged_in?
|
255
|
+
@session[:user].addresses.map { |a| a.address }
|
256
|
+
end
|
257
|
+
|
258
|
+
# Returns all _confirmed_ email addresses belonging to this user
|
259
|
+
def user_email_addresses_confirmed
|
260
|
+
user_logged_in?
|
261
|
+
@session[:user].mailinglist.confirmed_addresses.map { |a| a.address }
|
262
|
+
end
|
263
|
+
|
264
|
+
# Returns all yet-to-be-confirmed email addresses belong to this
|
265
|
+
# user.
|
266
|
+
def user_email_addresses_unconfirmed
|
267
|
+
user_logged_in?
|
268
|
+
@session[:user].mailinglist.pending_addresses.map { |a| a.address }
|
269
|
+
end
|
270
|
+
|
271
|
+
# Allows the user to confirm his email address on the web instead of
|
272
|
+
# by email.
|
273
|
+
def user_email_address_confirm(address,code)
|
274
|
+
user_logged_in?
|
275
|
+
address_obj=Address.find_by_address(address)
|
276
|
+
ml=@session[:user].mailinglist
|
277
|
+
if ml.confirm(address_obj,code) then
|
278
|
+
ml.save
|
279
|
+
else
|
280
|
+
false
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
# Lets the user change his password.
|
285
|
+
def user_change_password(old_password, password, password_confirmation)
|
286
|
+
user_logged_in?
|
287
|
+
user=@session[:user]
|
288
|
+
if User.authenticate(user.login, old_password) then
|
289
|
+
user.password=password
|
290
|
+
user.password_confirmation=password_confirmation
|
291
|
+
if(user.save)
|
292
|
+
return true
|
293
|
+
else
|
294
|
+
errstr = user.errors.sort.map do |fac,err|
|
295
|
+
"#{fac}: #{err}"
|
296
|
+
end.join("\n")
|
297
|
+
|
298
|
+
raise RuntimeError, errstr
|
299
|
+
end
|
300
|
+
else
|
301
|
+
raise "auth: original password incorrect"
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
# Returns the user's real name.
|
306
|
+
def user_real_name
|
307
|
+
user_logged_in?
|
308
|
+
|
309
|
+
@session[:user].description
|
310
|
+
end
|
311
|
+
|
312
|
+
# Allows the user to change his real name.
|
313
|
+
def user_change_real_name password, new_name
|
314
|
+
user_logged_in?
|
315
|
+
user=@session[:user]
|
316
|
+
|
317
|
+
if User.authenticate(user.login, password) then
|
318
|
+
user.description=new_name
|
319
|
+
if user.save
|
320
|
+
return new_name
|
321
|
+
else
|
322
|
+
errstr = user.errors.sort.map do |fac, err|
|
323
|
+
"#{fac}: #{err}"
|
324
|
+
end.join("\n")
|
325
|
+
|
326
|
+
raise RuntimeError, errstr
|
327
|
+
end
|
328
|
+
else
|
329
|
+
raise "auth: password incorrect"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
# Adds a new email address to this user.
|
334
|
+
def user_email_addresses_add(address)
|
335
|
+
user_logged_in?
|
336
|
+
if @session[:user].mailinglist.subscribe address then
|
337
|
+
@session[:user].mailinglist.save
|
338
|
+
end
|
339
|
+
@session[:user].mailinglist.addresses
|
340
|
+
end
|
341
|
+
|
342
|
+
# Removes an email address from the user's email address list.
|
343
|
+
def user_email_addresses_remove(address)
|
344
|
+
user_logged_in?
|
345
|
+
@session[:user].mailinglist.unsubscribe address
|
346
|
+
end
|
347
|
+
|
348
|
+
# Creates a mailing list of type +mailinglist_class+. Retrieve the
|
349
|
+
# list of valid mailing list classes with mailinglist_classes.
|
350
|
+
def mailinglist_create mailinglist_name, mailinglist_class
|
351
|
+
user_logged_in?
|
352
|
+
|
353
|
+
mailinglist_class_id = MailinglistClass.find_by_name mailinglist_class
|
354
|
+
unless mailinglist_class_id
|
355
|
+
raise "Class does not exist (check MailinglistClasses for list)"
|
356
|
+
end
|
357
|
+
|
358
|
+
m=Mailinglist.new(:name => mailinglist_name,
|
359
|
+
:mailinglist_class_id => mailinglist_class_id,
|
360
|
+
:user => @session[:user])
|
361
|
+
if m then
|
362
|
+
if m.save then
|
363
|
+
return m.address
|
364
|
+
else
|
365
|
+
nil
|
366
|
+
end
|
367
|
+
else
|
368
|
+
nil
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
# Returns a list of the names of all the mailing list classes.
|
373
|
+
def mailinglist_classes
|
374
|
+
# the first mailing list class is special (it's reserved for
|
375
|
+
# forwarding addresses).
|
376
|
+
MailinglistClass.find_all("id > 1").map { |mlc| mlc.name }
|
377
|
+
end
|
378
|
+
|
379
|
+
# Returns the attributes of the mailing list class +mlclass+. Use
|
380
|
+
# mailinglist_classes to retrieve a list of mailing list class
|
381
|
+
# names.
|
382
|
+
def mailinglist_class_get_attributes(mlclass)
|
383
|
+
MailinglistClass.find_by_name mlclass
|
384
|
+
end
|
385
|
+
|
386
|
+
# Returns the name of the mailing list with id +id+
|
387
|
+
def mailinglist_name id
|
388
|
+
my_mailing_list(id).name
|
389
|
+
end
|
390
|
+
|
391
|
+
# Returns the email address of the mailing list with id +id+
|
392
|
+
def mailinglist_address id
|
393
|
+
my_mailing_list(id).address
|
394
|
+
end
|
395
|
+
|
396
|
+
# Returns the id of the mailing list with name +name+. The converse
|
397
|
+
# of mailinglist_name
|
398
|
+
def mailinglist_find_by_name name
|
399
|
+
user_logged_in?
|
400
|
+
|
401
|
+
m=Mailinglist.find_by_address("#{name}@#{@session[:domain].name}")
|
402
|
+
if m then m[0].id end
|
403
|
+
end
|
404
|
+
|
405
|
+
# Deletes a mailing list if you're allowed to do that.
|
406
|
+
def mailinglist_delete mailinglist_id
|
407
|
+
m=my_mailing_list(mailinglist_id)
|
408
|
+
|
409
|
+
if m.destroy
|
410
|
+
true
|
411
|
+
else
|
412
|
+
false
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
# Returns a list of addresses on a mailing list.
|
417
|
+
def mailinglist_subscribers mailinglist_id
|
418
|
+
mailinglist=my_mailing_list(mailinglist_id)
|
419
|
+
mailinglist.confirmed_addresses.each do |addr|
|
420
|
+
addr.address
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
# Returns a list of non-confirmed addresses on a mailing list.
|
425
|
+
def mailinglist_pending mailinglist_id
|
426
|
+
mailinglist=my_mailing_list(mailinglist_id)
|
427
|
+
mailinglist.pending_addresses.map do |addr|
|
428
|
+
addr.address
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
# Adds an address to a mailing list. If the mailing list requires
|
433
|
+
# confirmation, then the confirmation code will be emailed to
|
434
|
+
# +address+.
|
435
|
+
def mailinglist_subscribe mailinglist_id, address
|
436
|
+
if my_mailing_list(mailinglist_id).subscribe(address)
|
437
|
+
true
|
438
|
+
else
|
439
|
+
false
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
# Confirms a subscription to a mailing list. Returns false if the
|
444
|
+
# confirmation code was incorrect.
|
445
|
+
def mailinglist_confirm mailinglist_name, address, code
|
446
|
+
addr = Address.find_by_address address
|
447
|
+
mailinglist = Mailinglist.find_by_name mailinglist_name
|
448
|
+
|
449
|
+
return false if addr == nil or mailinglist == nil
|
450
|
+
|
451
|
+
# This redundant-looking if is to ensure that it returns only
|
452
|
+
# "true" or "false", and not a not-true-but-still-evaluated-as-
|
453
|
+
# truth value like a mailing list, or a not-false such as nil.
|
454
|
+
if mailinglist.confirm(addr, code)
|
455
|
+
true
|
456
|
+
else
|
457
|
+
false
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
# Removes an address from a mailing list.
|
462
|
+
def mailinglist_unsubscribe mailinglist_id, address
|
463
|
+
if my_mailing_list(mailinglist_id).unsubscribe(address)
|
464
|
+
true
|
465
|
+
else
|
466
|
+
false
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
# Returns the IDs of all the messages messages sent to this mailing
|
471
|
+
# list.
|
472
|
+
#
|
473
|
+
# This should probably do something more useful like return all
|
474
|
+
# new messages since some datestamp or something.
|
475
|
+
def mailinglist_messages mailinglist_id
|
476
|
+
my_mailing_list(mailinglist_id).messages
|
477
|
+
end
|
478
|
+
|
479
|
+
#========================================================================
|
480
|
+
# Message methods
|
481
|
+
#========================================================================
|
482
|
+
|
483
|
+
# Returns the message with the id +id+.
|
484
|
+
def message message_id
|
485
|
+
readable_message(id)
|
486
|
+
end
|
487
|
+
|
488
|
+
# Return the message that this one's a response to.
|
489
|
+
def message_parent message_id
|
490
|
+
readable_message(id).parent
|
491
|
+
end
|
492
|
+
|
493
|
+
# Returns all responses to this message.
|
494
|
+
def message_responses message_id
|
495
|
+
readable_message(id).children.map { |m| m.id }
|
496
|
+
end
|
497
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class SugoiAdminController < CommandlineController
|
2
|
+
model :mailinglist
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def get_password
|
7
|
+
password = ask "Password: " do |q| q.echo = false end
|
8
|
+
confirmation = ask "Confirm: " do |q| q.echo = false end
|
9
|
+
|
10
|
+
return [ password, confirmation ]
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_errors errors
|
14
|
+
errors.map do |facility, text|
|
15
|
+
@messages << "#{facility}: #{text}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
def list_domains
|
22
|
+
@domains = Domain.find_all
|
23
|
+
end
|
24
|
+
|
25
|
+
def list_mailinglists(domain_name)
|
26
|
+
@domain = Domain.find_by_name domain_name
|
27
|
+
@mailinglists = Mailinglist.find :all
|
28
|
+
end
|
29
|
+
|
30
|
+
def list_addresses(mailinglist_address)
|
31
|
+
@mailinglist = Mailinglist.find_by_address(mailinglist_address)
|
32
|
+
if @mailinglist then
|
33
|
+
@mailinglist=@mailinglist[0]
|
34
|
+
@addresses = @mailinglist.addresses
|
35
|
+
else
|
36
|
+
@addresses = []
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_domain(domain_name)
|
41
|
+
@message = []
|
42
|
+
|
43
|
+
domain = Domain.find_by_name domain_name
|
44
|
+
if domain == nil then
|
45
|
+
password, confirmation = get_password
|
46
|
+
domain = Domain.new
|
47
|
+
domain.name = domain_name
|
48
|
+
domain.password = password
|
49
|
+
domain.password_confirmation = confirmation
|
50
|
+
if domain.save then
|
51
|
+
@message = [ "Domain \"#{domain_name}\" created successfully" ]
|
52
|
+
else
|
53
|
+
format_errors domain.errors
|
54
|
+
end
|
55
|
+
else
|
56
|
+
@message = [ "Domain \"#{domain_name}\" already exists." ]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_user domain_name, username, email_address = nil, description = nil
|
61
|
+
domain = Domain.find_by_name domain_name
|
62
|
+
if domain then
|
63
|
+
password, confirmation = get_password
|
64
|
+
|
65
|
+
if email_address == nil then
|
66
|
+
email_address = ask "Address to forward #{username}'s email to: "
|
67
|
+
if email_address == "" then email_address = nil end
|
68
|
+
end
|
69
|
+
|
70
|
+
if description == nil then
|
71
|
+
description = ask "Description for #{username}: "
|
72
|
+
if description == "" then description = nil end
|
73
|
+
end
|
74
|
+
|
75
|
+
user = User.new
|
76
|
+
user.domain = domain
|
77
|
+
user.login = username
|
78
|
+
user.password = password
|
79
|
+
user.password_confirmation = password_confirmation
|
80
|
+
user.description = description
|
81
|
+
if user.save then
|
82
|
+
@message = [ "User \"#{username}@#{domain_name}\" created successfully" ]
|
83
|
+
if email_address then
|
84
|
+
user.addresses << email_address
|
85
|
+
end
|
86
|
+
else
|
87
|
+
format_errors
|
88
|
+
end
|
89
|
+
else
|
90
|
+
@message = [ "domain: Domain \"#{domain.name}\" doesn't exist." ]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|