-
Notifications
You must be signed in to change notification settings - Fork 0
/
.hermesmail-rules
105 lines (85 loc) · 2.28 KB
/
.hermesmail-rules
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
File.umask 007
require 'stringio'
require 'mail'
require '/home/lsm/ruby_lsm/lsm.rb'
self.default_format = Maildir
::Mail.defaults do
delivery_method :sendmail
end
def create_response
response = ::Mail.new
response.from = 'lsm@qqx.org'
%w/ reply_to from unix_from /.each do |h|
begin
recipients = headers.__send__ h
next unless recipients
response.to = recipients
rescue
else
break
end
end
subject = headers.subject
subject = "Re: #{subject}" unless subject =~ /^\s*Re:/
response.subject = subject
if message_id = headers.message_id
refs = headers.references.map(&:to_s) rescue []
refs << message_id
response.header['References'] = refs.map{|r| "<#{r}>" }.join(' ')
response.header['In-Reply-To'] = "<#{message_id}>"
end
yield response if block_given?
response
end
class Hermes::Message
def ctype
content_type.caption rescue 'text/plain'
end
def check_lsm response = ''
if is_multipart?
body.each { |part| part.check_lsm response }
elsif ctype.downcase == 'text/plain' and body_decoded[/^Begin4/]
check_entry body_decoded, response
end
response
end
def check_entry body, response
io = StringIO.new body
entry = LSM::Entry.new.from_file io
if output = entry.report_errors
response << "The following entry has errors, it will NOT be added.\n\n"
response << output
response << "\n\n"
else
response << "The following entry looks correct, it will be added.\n\n"
response << entry.format
response << "\n\n"
File.open( Time.now.strftime('/home/lsm/updates/lsm.%Y-%m-%d'), 'a' ) do |f|
f.flock File::LOCK_EX
f.puts entry.format
f.puts ''
end
end
rescue
end
end
def process
case headers.subject
when /^\s*add\s*$/
save "#{ENV['HOME']}/add-requests"
response_body = check_lsm
response_body = "No LSM entries were found" if response_body == ''
create_response do |response|
response.bcc = 'LSM Maintainer <aaron@schrab.com>'
response.body = response_body
response.deliver!
end
when /^\s*(template|help)\s*$/
create_response do |response|
response.body = File.read "#{ENV['HOME']}/lsm-template"
response.deliver!
end
end
done
end
# vim: ft=ruby