-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.cropmail-rules
100 lines (86 loc) · 2.65 KB
/
.cropmail-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
File.umask 007
Message.maildir='/srv/mail/pug.qqx.org/lsm'
require 'stringio'
require 'tmail'
require '/home/lsm/ruby_lsm/lsm.rb'
class ::Cropmail::Message #{{{
# Create a response to the current message.
def create_response #{{{
response = Message.new
%w/ reply_to from unix_from /.each do |h|
begin
recipients = __send__ h
unless recipients.addresses.empty?
response.headers.add 'to', recipients
break
end
rescue Exception
end
end
if subject =~ /^\s*Re:/
response.headers.add 'subject', subject
else
response.headers.add 'subject', "Re: #{subject}"
end
response.headers.add 'references', (references.to_s rescue '') + ' ' + message_id.to_s
response.headers.add 'in-reply-to', message_id
response.headers.add 'MIME-Version', '1.0'
response.headers.add 'Content-Type', 'text/plain; charset="utf-8"'
response.headers.add 'Content-Transfer-Encoding', '8bit'
response
end #}}}
# Recurse through multipart messages, extracting LSM entries.
def check_lsm response='' #{{{
if is_multipart? then
each do |part,invisible|
next if invisible
part.check_lsm response
end
elsif content_type.fulltype == 'text/plain' and decoded[/^Begin4/]
begin
io = StringIO.new decoded
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 Exception
end
else
File.open( "/tmp/lsm.log", 'a' ) do |lsm_log|
lsm_log.puts "Content type: #{content_type.fulltype}"
end
end
response
end #}}}
end #}}}
case subject
when /^\s*add\s*$/
save "#{ENV['HOME']}/add-requests"
response_body = check_lsm
response = create_response
response.headers.add 'bcc', 'LSM Maintainer <[email protected]>'
if response_body == ''
response.body = "No LSM entries were found."
else
response.body = response_body
end
response.forward_sendmail :use_t
when /^\s*(template|help)\s*$/
response = create_response
response.body = File.read "#{ENV['HOME']}/lsm-template"
response.forward_sendmail :use_t
end
done
save "#{ENV['HOME']}/failed_mail"
# vim: ft=ruby fdm=marker