sugoi-mail 0.1.5 → 0.3.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/INSTALL +5 -2
- data/app/controllers/commandline_controller.rb +16 -0
- data/app/controllers/root_admin_controller.rb +1 -274
- data/app/controllers/sugoi_admin_controller.rb +1 -1
- data/app/models/mailinglist.rb +46 -4
- data/app/models/message.rb +69 -31
- data/app/models/user.rb +2 -0
- data/bin/maild +51 -23
- data/bin/sugoi-admin +11 -3
- data/db/migrate/017_add_mailinglist_types.rb +0 -7
- data/lib/gurgitate-rules.rb +5 -8
- data/lib/tasks/release.rake +2 -3
- data/script/boot/sugoi-mail.EDIT_ME +237 -0
- data/script/cover +3 -1
- data/script/dumpintofile +5 -0
- data/test/fixtures/messages.yml +14 -26
- data/test/unit/help_test.rb +4 -1
- data/test/unit/mailinglist_test.rb +11 -0
- data/test/unit/message_test.rb +3 -0
- metadata +5 -3
- data/db/schema.rb +0 -108
data/app/models/user.rb
CHANGED
data/bin/maild
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
RAILS_BASE=File.join(File.dirname(__FILE__),"..")
|
3
|
+
RAILS_BASE=File.expand_path(File.join(File.dirname(__FILE__),".."))
|
4
4
|
CONFIGDIR=File.join(RAILS_BASE,"config")
|
5
5
|
TMPDIR=File.join(RAILS_BASE,"tmp")
|
6
6
|
PIDFILE=File.join(TMPDIR, "maild.pid")
|
7
7
|
SOCKETFILE=File.join(RAILS_BASE,"tmp","sockets","maild.socket")
|
8
8
|
|
9
|
+
#-------DEBUG-----
|
10
|
+
ENV["RAILS_ENV"] = "development"
|
11
|
+
|
9
12
|
require File.join(CONFIGDIR,"boot")
|
10
13
|
require File.join(CONFIGDIR,"environment")
|
11
14
|
require "active_record"
|
@@ -58,18 +61,15 @@ class MailDaemon
|
|
58
61
|
$logger.err "PID file exists--already running?"
|
59
62
|
end
|
60
63
|
|
64
|
+
$logger.info "Ready to accept mail"
|
65
|
+
|
66
|
+
unless @debug
|
67
|
+
daemonize
|
68
|
+
end
|
61
69
|
File.open(PIDFILE,"w") do |f|
|
62
70
|
f.puts Process.pid
|
63
71
|
end
|
64
72
|
|
65
|
-
trap("INT") do
|
66
|
-
@server.close
|
67
|
-
File.unlink(@SOCK_PATH)
|
68
|
-
File.unlink(PIDFILE)
|
69
|
-
end
|
70
|
-
|
71
|
-
$logger.info "Ready to accept mail"
|
72
|
-
self
|
73
73
|
end
|
74
74
|
|
75
75
|
def read_gurgitate_rules(gurgitatefile)
|
@@ -97,6 +97,9 @@ class MailDaemon
|
|
97
97
|
|
98
98
|
def process client_info
|
99
99
|
LimitedFork.fork do
|
100
|
+
Signal.trap("SIGTERM"){
|
101
|
+
exit!
|
102
|
+
}
|
100
103
|
begin
|
101
104
|
# pp client_info
|
102
105
|
g=Gurgitate::Mailmessage.new(client_info[:message],
|
@@ -111,31 +114,52 @@ class MailDaemon
|
|
111
114
|
$logger.warning " from #{tr}"
|
112
115
|
end
|
113
116
|
end
|
114
|
-
|
117
|
+
# since we're a child process
|
118
|
+
exit!
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
118
122
|
def run
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
123
|
+
start
|
124
|
+
loop do
|
125
|
+
begin
|
126
|
+
Signal.trap("SIGTERM"){
|
127
|
+
$logger.info "caught SIGTERM"
|
128
|
+
shutdown
|
129
|
+
}
|
130
|
+
#NOTE: A SIGTERM (kill or kill -15) or SIGINT
|
131
|
+
# (ctrl+C, kill -2) will be caught and maild
|
132
|
+
# will clean up after itself (call shutdown)
|
133
|
+
|
134
|
+
begin
|
135
|
+
client = @server.accept_nonblock
|
136
|
+
rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
|
137
|
+
IO.select([@server])
|
138
|
+
retry
|
139
|
+
end
|
140
|
+
|
128
141
|
client_info = Marshal.load client
|
129
142
|
process client_info
|
143
|
+
|
144
|
+
rescue SignalException
|
145
|
+
#catches SIGINT
|
146
|
+
shutdown
|
130
147
|
end
|
131
|
-
rescue
|
132
|
-
@server.close
|
133
|
-
File.unlink(@SOCK_PATH)
|
134
|
-
raise
|
135
148
|
end
|
136
149
|
end
|
150
|
+
|
151
|
+
def shutdown
|
152
|
+
$logger.info "shutdown has been called.."
|
153
|
+
|
154
|
+
@server.close
|
155
|
+
File.unlink(@SOCK_PATH)
|
156
|
+
File.unlink(PIDFILE)
|
157
|
+
exit 0
|
158
|
+
end
|
137
159
|
end
|
138
160
|
|
161
|
+
|
162
|
+
|
139
163
|
if ARGV[0] == "-d" then
|
140
164
|
maild=MailDaemon.new :debug => true
|
141
165
|
else
|
@@ -143,3 +167,7 @@ else
|
|
143
167
|
end
|
144
168
|
|
145
169
|
maild.run
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
data/bin/sugoi-admin
CHANGED
@@ -16,6 +16,14 @@ command = ARGV.shift.gsub(/-/,"_")
|
|
16
16
|
request = ActionController::CommandlineRequest.new(command, *ARGV)
|
17
17
|
response = ActionController::CommandlineResponse.new
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
begin
|
20
|
+
admin.process(request, response)
|
21
|
+
|
22
|
+
puts response.body
|
23
|
+
rescue UnknownAction => e
|
24
|
+
puts "sugoi-admin: Command error: #{e}"
|
25
|
+
exit 1
|
26
|
+
rescue RuntimeError => e
|
27
|
+
puts "sugoi-admin: Error: #{e}"
|
28
|
+
exit 1
|
29
|
+
end
|
@@ -11,13 +11,6 @@
|
|
11
11
|
# joinable: true -> people can subscribe to the list at will <- DEFAULT
|
12
12
|
# false -> only the owner can subscribe or unsubscribe people
|
13
13
|
|
14
|
-
# NOTE FOR JOSUIKAI!
|
15
|
-
# ******************
|
16
|
-
#
|
17
|
-
# There needs to be another kind of "joinable" which says that only
|
18
|
-
# people who already have accounts on the system can join a mailing
|
19
|
-
# list.
|
20
|
-
|
21
14
|
class AddMailinglistTypes < ActiveRecord::Migration
|
22
15
|
|
23
16
|
class MailinglistClass < ActiveRecord::Base; end
|
data/lib/gurgitate-rules.rb
CHANGED
@@ -49,19 +49,16 @@ to.each do |to_address|
|
|
49
49
|
return
|
50
50
|
else
|
51
51
|
matches = to_address.match(/(.*?)#(.*?)@(.*)/)
|
52
|
-
|
52
|
+
$logger.debug "hey, found a funky rewrite thingy"
|
53
53
|
|
54
54
|
if matches then
|
55
|
-
localpart, destdomain, domain = matches[1..3]
|
56
|
-
to_address = "#{localpart}@#{destdomain}"
|
57
|
-
p "from address is: #{from}"
|
58
55
|
proxy_address=Address.proxyaddress(from)
|
59
|
-
|
56
|
+
$logger.debug "proxy address is: #{proxy_address.inspect}"
|
60
57
|
if proxy_address
|
61
|
-
# mailinglist = Mailinglist.find_by_address(proxy_address)[0]
|
62
58
|
mess=Message.from_message(self)
|
63
|
-
|
64
|
-
mess.
|
59
|
+
|
60
|
+
mess.mailinglist = Mailinglist.find_by_address(proxy_address)[0]
|
61
|
+
mess.deliver
|
65
62
|
end
|
66
63
|
end
|
67
64
|
# bounce, or report to postmaster, or something
|
data/lib/tasks/release.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rake/gempackagetask'
|
2
2
|
|
3
|
-
PKG_VERSION = "0.
|
3
|
+
PKG_VERSION = "0.3.0"
|
4
4
|
PKG_NAME = "sugoi-mail"
|
5
5
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
6
6
|
|
@@ -9,14 +9,13 @@ spec = Gem::Specification.new do |s|
|
|
9
9
|
s.version = PKG_VERSION
|
10
10
|
s.required_ruby_version = ">= 1.8.4"
|
11
11
|
s.summary = "Powerful mailing list manager."
|
12
|
-
# s.description = "FIXME"
|
13
12
|
s.has_rdoc = true
|
14
13
|
|
15
14
|
s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f|
|
16
15
|
[ /\.$/, /config\/database.yml$/, /config\/database.yml-/,
|
17
16
|
/database\.sqlite/,
|
18
17
|
/\.log$/, /^pkg/, /\.svn/, /^vendor\/rails/, /\~$/,
|
19
|
-
/\/\._/,
|
18
|
+
/\/\._/, /\/#/, /\/coverage\// ].any? {|regex| f =~ regex }
|
20
19
|
end
|
21
20
|
s.require_path = '.'
|
22
21
|
s.author = "Dave Brown"
|
@@ -0,0 +1,237 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
|
3
|
+
# Sugoi-Mail boot-up script.
|
4
|
+
# This file should be in /etc/init.d/
|
5
|
+
# DO NOT FORGET TO SET YOUR INSTALLPATH AND SUGOIUSER
|
6
|
+
# please rename this file to sugoi-mail (without the .EDIT_ME)
|
7
|
+
|
8
|
+
#Written by: aavdacev@invio.co.jp
|
9
|
+
|
10
|
+
|
11
|
+
INSTALLPATH="/--SET INSTALL PATH--" #ie: '/home/sugoi-user/sugoi-mail'
|
12
|
+
SUGOIUSER="--SET USER RUNNING SUGOIMAIL--" #ie: 'sugoi-user'
|
13
|
+
|
14
|
+
RunTests(){
|
15
|
+
maild_socket_exists=0
|
16
|
+
maild_pid=''
|
17
|
+
maild_running=0
|
18
|
+
mongrel_pid=''
|
19
|
+
mongrel_running=0
|
20
|
+
|
21
|
+
|
22
|
+
if test -e $INSTALLPATH/tmp/sockets/maild.socket
|
23
|
+
then
|
24
|
+
maild_socket_exists=1
|
25
|
+
fi
|
26
|
+
|
27
|
+
if test -e $INSTALLPATH/tmp/maild.pid
|
28
|
+
then
|
29
|
+
maild_pid=`cat $INSTALLPATH/tmp/maild.pid`
|
30
|
+
fi
|
31
|
+
|
32
|
+
if [ ! -z "$(ps -fu $SUGOIUSER | grep ruby[\ ]$INSTALLPATH/bin/maild)" ]
|
33
|
+
then
|
34
|
+
maild_running=1
|
35
|
+
fi
|
36
|
+
|
37
|
+
if test -e $INSTALLPATH/log/mongrel.pid
|
38
|
+
then
|
39
|
+
mongrel_pid=`cat $INSTALLPATH/log/mongrel.pid`
|
40
|
+
if [ ! -z "$(ps -fu $SUGOIUSER | grep [\ ]$mongrel_pid[\ ].*mongrel_rails)" ]
|
41
|
+
then
|
42
|
+
mongrel_running=1
|
43
|
+
fi
|
44
|
+
fi
|
45
|
+
}
|
46
|
+
|
47
|
+
Status(){
|
48
|
+
RunTests
|
49
|
+
status_msg=""
|
50
|
+
if [ "$maild_socket_exists" -eq 1 ]; then
|
51
|
+
status_msg="$status_msg - 'tmp/sockets/maild.socket' exists. \n"
|
52
|
+
fi
|
53
|
+
|
54
|
+
if [ ! -z "$maild_pid" ]; then
|
55
|
+
status_msg="$status_msg - 'tmp/maild.pid' exists and reads: $maild_pid \n"
|
56
|
+
fi
|
57
|
+
|
58
|
+
if [ "$maild_running" -eq 1 ]; then
|
59
|
+
status_msg="$status_msg - Maild belonging to $SUGOIUSER is running. \n"
|
60
|
+
fi
|
61
|
+
|
62
|
+
if [ ! -z "$mongrel_pid" ]; then
|
63
|
+
status_msg="$status_msg - 'log/mongrel.pid' exists and reads $mongrel_pid \n"
|
64
|
+
fi
|
65
|
+
|
66
|
+
if [ "$mongrel_running" -eq 1 ]; then
|
67
|
+
status_msg="$status_msg - Mongrel webserver is running"
|
68
|
+
fi
|
69
|
+
|
70
|
+
if [ "$1" = "output" ]
|
71
|
+
then
|
72
|
+
echo -e "$status_msg"
|
73
|
+
fi
|
74
|
+
|
75
|
+
if [ "$maild_socket_exists" -eq 1 ] &&
|
76
|
+
[ ! -z "$maild_pid" ] &&
|
77
|
+
[ "$maild_running" -eq 1 ] &&
|
78
|
+
[ ! -z "$mongrel_pid" ] &&
|
79
|
+
[ "$mongrel_running" -eq 1 ]
|
80
|
+
then
|
81
|
+
echo "Sugoi-mail: all systems are running."
|
82
|
+
|
83
|
+
elif [ ! "$maild_socket_exists" -eq 1 ] &&
|
84
|
+
[ -z "$maild_pid" ] &&
|
85
|
+
[ ! "$maild_running" -eq 1 ] &&
|
86
|
+
[ -z "$mongrel_pid" ] &&
|
87
|
+
[ ! "$mongrel_running" -eq 1 ]
|
88
|
+
then
|
89
|
+
echo "Sugoi-mail: all processes safely stopped."
|
90
|
+
|
91
|
+
else
|
92
|
+
echo "Sugoi-mail: irregular state. Failed to start or stop properly."
|
93
|
+
echo ">> Try 'cleanup' or consult 'help'."
|
94
|
+
fi
|
95
|
+
|
96
|
+
}
|
97
|
+
|
98
|
+
Menu(){
|
99
|
+
case $1 in
|
100
|
+
start)
|
101
|
+
if [ "$mongrel_running" -eq 1 ]; then
|
102
|
+
echo "ERR: Sugoi mail is already being served by mongrel. Consult 'help'"
|
103
|
+
elif [ "$maild_running" -eq 1 ]; then
|
104
|
+
echo "ERR: Maild is already running. Consult 'help'."
|
105
|
+
else
|
106
|
+
echo " - Clearing PID and socket-files.."
|
107
|
+
rm -f $INSTALLPATH/tmp/maild.pid
|
108
|
+
rm -f $INSTALLPATH/tmp/sockets/maild.socket
|
109
|
+
|
110
|
+
echo " - Starting maild Daemon.."
|
111
|
+
su - $SUGOIUSER -c "$INSTALLPATH/bin/maild;exit;"
|
112
|
+
|
113
|
+
echo " - Starting Mongrel webserver.."
|
114
|
+
su - $SUGOIUSER -c "cd $INSTALLPATH; mongrel_rails start -d;exit;"
|
115
|
+
|
116
|
+
#timeout for 3 sec for mongrel to boot, ensure correct status msg
|
117
|
+
sleep 3s
|
118
|
+
Status
|
119
|
+
fi
|
120
|
+
|
121
|
+
;;
|
122
|
+
|
123
|
+
status)
|
124
|
+
Status "output"
|
125
|
+
;;
|
126
|
+
|
127
|
+
cleanup)
|
128
|
+
echo "Sugoi-mail cleanup.. [ started ]"
|
129
|
+
echo "- stopping maild, mongrel, and cleaning up files.."
|
130
|
+
if [ "$mongrel_running" -eq 1 ]; then
|
131
|
+
su - $SUGOIUSER -c "cd $INSTALLPATH; mongrel_rails stop"
|
132
|
+
fi
|
133
|
+
|
134
|
+
if [ "$maild_running" -eq 1 ]; then
|
135
|
+
kill -9 $maild_pid
|
136
|
+
fi
|
137
|
+
|
138
|
+
if [ "$maild_socket_exists" -eq 1 ]; then
|
139
|
+
rm -f $INSTALLPATH/tmp/sockets/maild.socket
|
140
|
+
fi
|
141
|
+
|
142
|
+
if [ ! -z "$maild_pid" ]; then
|
143
|
+
rm -f $INSTALLPATH/tmp/maild.pid
|
144
|
+
fi
|
145
|
+
|
146
|
+
Status
|
147
|
+
;;
|
148
|
+
restart)
|
149
|
+
if [ ! "$maild_running" -eq 1 ]; then
|
150
|
+
echo "CAN'T RESTART: Maild belonging to $SUGOIUSER is not running. Use 'start'"
|
151
|
+
elif [ ! "$mongrel_running" ]; then
|
152
|
+
echo "CAN'T RESTART: Sugoi-Mail is not being served by Mongrel. Try 'cleanup'"
|
153
|
+
else
|
154
|
+
if [ -z "$maild_pid" ]; then
|
155
|
+
echo "ERR: no PID file exists, but maild is running. Consult 'help'"
|
156
|
+
else
|
157
|
+
echo "Restarting Sugoi-Mail..."
|
158
|
+
Menu stop
|
159
|
+
|
160
|
+
echo "..Booting up again.."
|
161
|
+
Menu start
|
162
|
+
fi
|
163
|
+
fi
|
164
|
+
;;
|
165
|
+
stop)
|
166
|
+
if [ ! "$maild_running" -eq 1 ]; then
|
167
|
+
echo "ERR: Maild belonging to $SUGOIUSER is not running. Use 'start'"
|
168
|
+
elif [ ! "$mongrel_running" ]; then
|
169
|
+
echo "ERR: Sugoi-Mail is not being served by Mongrel. Consult 'help'"
|
170
|
+
else
|
171
|
+
if [ -z "$maild_pid" ]; then
|
172
|
+
echo "ERR: no PID file exists, but maild is running. Consult 'help'"
|
173
|
+
else
|
174
|
+
echo " - Stopping Mongrel webservice.."
|
175
|
+
su - $SUGOIUSER -c "cd $INSTALLPATH; mongrel_rails stop"
|
176
|
+
echo " - Stopping maild daemon.."
|
177
|
+
su - $SUGOIUSER -c "kill -2 $maild_pid"
|
178
|
+
|
179
|
+
Status
|
180
|
+
fi
|
181
|
+
fi
|
182
|
+
;;
|
183
|
+
|
184
|
+
*)
|
185
|
+
echo "-- SUGOI-MAIL BOOT SCRIPT HELP --
|
186
|
+
|
187
|
+
INFO:
|
188
|
+
This file is a boot script for Sugoi-Mail and should be located in /etc/init.d
|
189
|
+
Please ensure the installpath and sugoi-user have been set properly:
|
190
|
+
- Sugoi-mail installpath: $INSTALLPATH
|
191
|
+
- Sugoi-mail user: $SUGOIUSER
|
192
|
+
|
193
|
+
SYNTAX:
|
194
|
+
sugoi-mail [ command ]
|
195
|
+
|
196
|
+
COMMANDS:
|
197
|
+
|
198
|
+
start
|
199
|
+
If sugoi-mail is not running, 'start' will clean up PID & socketfiles,
|
200
|
+
boot maild daemon, start Mongrel webserver, and finally print sugoi-mail
|
201
|
+
program status.
|
202
|
+
|
203
|
+
stop
|
204
|
+
If sugoi-mail is running, 'stop' will stop Mongrel webservice, terminate the
|
205
|
+
maild daemon, and print the sugoi-mail program status.
|
206
|
+
|
207
|
+
restart
|
208
|
+
If sugoi-mail is running, 'restart' will call 'stop', and then 'start'
|
209
|
+
the behaviour of 'stop' and 'start' are described above.
|
210
|
+
|
211
|
+
cleanup
|
212
|
+
At any point in time 'cleanup' will restore sugoi-mail to a 'stopped' state.
|
213
|
+
'cleanup' does not check the current program state, harshly (kill -9) stops
|
214
|
+
maild daemon, cleans up the PID and socketfiles manualy, stops Mongrel
|
215
|
+
webservice, and then prints a status message
|
216
|
+
|
217
|
+
help
|
218
|
+
Display this help message
|
219
|
+
|
220
|
+
* All other commands default to 'help'
|
221
|
+
|
222
|
+
ERROR HANDLING:
|
223
|
+
Most error states can be resoved with 'cleanup'. If maild is running, but the
|
224
|
+
PID-file does not exist, you must kill maild manually by finding its process
|
225
|
+
id in the 'ps -ef' listing
|
226
|
+
|
227
|
+
AUTHOR:
|
228
|
+
aavdacev@invio.co.jp
|
229
|
+
"
|
230
|
+
;;
|
231
|
+
|
232
|
+
esac
|
233
|
+
}
|
234
|
+
|
235
|
+
RunTests
|
236
|
+
Menu $1
|
237
|
+
exit 0
|