-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_whale.rb
52 lines (42 loc) · 1.22 KB
/
mail_whale.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require "fileutils"
require "bundler"
Bundler.require
mail_whale = Newman::Application.new do
helpers do
def load_list(name)
store = Newman::Store.new(settings.application.database)
Newman::MailingList.new(name, store)
end
end
match :list_id, ".+"
to(:tag, "{list_id}") do
list = load_list(params[:list_id])
reply_to ="#{settings.application.inbox}+#{params[:list_id]}@#{domain}"
if list.subscriber?(sender)
forward_message :bcc => list.subscribers.join(", "),
:reply_to => reply_to
else
respond :subject => "You are not subscribed",
:body => template("non-subscriber-error")
end
end
default do
respond(:subject => "FAILURE")
end
end
begin
if File.exists?("server.lock")
abort("Server is locked because of an unclean shutdown. Check "+
"the logs to see what went wrong, and delete server.lock "+
"if the problem has been resolved")
end
logger = Logger.new("mail_whale.log")
logger.level = Logger::INFO
server = Newman::Server.simple!(mail_whale, "config/environment.rb")
server.logger = logger
server.tick
# TODO: Explain this.
rescue Exception
FileUtils.touch("server.lock")
raise
end