-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhermesmail-rules
224 lines (189 loc) · 5.82 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
require 'gdbm'
require 'icalendar'
#self.spoolfile =
self.spooldir = "/srv/mail/ats"
self.maildir = "Mail"
self.default_format = Maildir
def mbox name
Maildir.new "/srv/mail/ats/.#{name}"
end
def filter_duplicates list
dbfile = "#{ENV['HOME']}/.dupcache"
GDBM.open(dbfile, 0600, GDBM::WRCREAT|GDBM::SYNC) do |dbm|
key = "#{list}:#{headers.message_id}"
if dbm[key]
deposit mbox :dups
else
dbm[key] = Time.now.to_i.to_s
end
end
rescue
end
def list name, subject: nil, dupcheck: false
#$stderr.puts "List #{name}"
filter_duplicates(name) if dupcheck
begin # Cleanup subject
original = headers.subject
modified = original.dup
if subject
subject = Regexp.escape subject unless subject.is_a? Regexp
modified.sub!(subject, '')
end
reply = true if modified.sub!( /(-reply\s*)+$/i, '' )
reply = true if modified.sub!( /^(\s*Re(\[\d+\])?:)+/i, '' )
modified.strip!
modified = "Re: #{modified}" if reply
headers.replace :Subject, modified unless modified == original
rescue
end
deposit mbox "L.#{name}"
end
def mutt_alias name
re = /^\s*alias\s+#{Regexp.escape name}\s+(.*)/
File.open("#{ENV['HOME']}/.mutt/aliases") do |f|
f.each_line do |l|
case l
when re
return $1.split(',')
end
end
end
raise "Alias #{name} not found"
end
def add_event calFile, req
req = Icalendar::Calendar.parse(req).first
newEvent = req.events.first
File.open(calFile, 'r+') do |f|
f.flock(File::LOCK_EX)
updt = Icalendar::Calendar.new
updt.append_custom_property 'X-WR-CALNAME', 'Flights'
orig = Icalendar::Calendar.parse(f).first
orig.events.each do |ev|
next if ev.uid == newEvent.uid
updt.add_event ev
end
if req.ip_method != 'CANCEL'
updt.add_event newEvent
end
f.rewind
f.puts updt.to_ical
f.truncate(f.pos)
end
end
def process
begin
save Time.now.strftime('/srv/mail/qqx.org/backup_ats/%Y/%m/%d')
rescue
end
begin
headers.replace 'Lines', body.lines.size
rescue
end
envelope_to =
if ENV['EXTENSION']
ENV['EXTENSION'].sub(/=([^=]*)/, '@\\1')
elsif ENV['RECIPIENT']
ENV['RECIPIENT']
end
headers.replace 'X-QQX-Envelope-To', envelope_to if envelope_to
begin # Update flight calendar
case headers.subject
when \
'Wings of Carolina Flying Club Schedule Confirmation',
'Wings of Carolina Flying Club Scheduling Notification',
'Wings of Carolina Flying Club Reservation Change Notification',
'Wings of Carolina Flying Club Reservation Canceled'
body.each do |part|
if part.content_type.name == 'flight.ics'
cal = part.body_decoded
cal.gsub!(/(for )?Schrab, Aaron( with)?/, '')
add_event("#{ENV['HOME']}/www/flight.ics", cal)
end
end
end
rescue
end
deposit mbox :spam if headers.x_spam_flag =~ /YES/i
deposit mbox :junk if from.has?(/postmaster@(pug\.)?qqx\.org/i)
deposit mbox :junk if addresses_of(:to).has?(/mailman-bounces.*@trilug\.org/i)
case headers.list_id
when /debian-([a-z0-9_-]+)\.lists\.debian\.org/
list "debian.#$1".downcase
when /mutt-(users|dev).mutt.org/
list 'mail.mutt-dev'
when /raleigh-rb-members/
list 'ruby.raleigh', subject: /\[triangle\.rb\]\s*/i
when /raleigh-(talk|pm)\.pm\.org/i
list 'ug.raleigh-pm', subject: /\[Raleigh-pm\]\s*/i
when /steering\.trilug\.org/i
list 'ug.trilug.steering', subject: '[Steering]'
when /volunteers\.trilug\.org/i
list 'ug.trilug.volunteers', subject: '[TriLUG Volunteers]'
when /linux-ham\.trilug\.org/i
list 'ug.trilug.ham', subject: '[Linux-ham]'
when /trilug\.trilug\.org/i
unless headers.x_list_administrivia =~ /yes/i
list 'ug.trilug', subject: /\[TriLUG\]\s*/i
end
when /trilug-ontopic\.trilug\.org/i
list 'ug.trilug', subject: /\[TriLUG-ontopic\]\s*/i
when /dbix-class\.lists\.scsys\.co\.uk/i
list 'perl.dbix', subject: /\[Dbix-class\]/i
when /zsh-(workers|users)\.zsh\.org/i
list 'dev.zsh', dupcheck: true
when /git\.vger\.kernel\.org/i
list 'dev.git', dupcheck: true
when /tmux-users\.lists\.sourceforge\.net/i
list 'dev.tmux'
when /meld-list\.gnome\.org/i
list 'dev.meld'
when /i3-discuss\.(freelists\.org|i3\.zekjur\.net)/
list 'dev.i3', subject: /\[i3(-discuss)?\]/i
when /sqlfairy-developers\.lists\.sourceforge\.net/i
list 'dev.sql-translator', subject: /\[sqlfairy-developers\]/i
when /mailscanner.lists.mailscanner.info/i
list 'mail.scanner'
when /bugtraq.list-id.securityfocus.com/
list 'bugtraq'
when /mailman-users\.mailman3\.org/i
list 'mail.mailman3'
when /sympa-users\.listes\.renater\.fr/i
list 'mail.sympa'
end
case headers.list_unsubscribe
when %r{<http://discourse.triangleruby.com/}
list 'ug.trianglerb', subject: '[Triangle.rb Forum]'
end
# Practice on git list is to CC everyone involved, attempt to send
# direct-to-me messages to the list folder
#list 'dev.git', dupcheck: true if receivers.include? '[email protected]'
list 'debian.pts' if headers.x_pts_package =~ /\w/
list 'subs.skeptic' if from.has?(/[email protected]/i)
case headers.x_gitlab_project
when 'mutt'
list 'mail.mutt-dev', subject: 'mutt |'
end
if from.has?(/noreturn@([a-z0-9_-]+\.)*myfbo\.com/i)
begin
if body.match(/^Message sent by (.*?) (\S+@\S+)$/)
headers.replace 'From', %Q{"#$1" <#$2>}
end
rescue
$stderr.puts $!
end
deposit mbox 'INBOX.wcfc'
end
if from.has?(/@(cooperpress\.com|peterc\.org)$/i)
begin
sendmail mutt_alias :newsblur
rescue
end
deposit mbox 'INBOX.read'
end
if from.has?(/mailman.*[@.]trilug\.org/) and headers.x_list_administrivia =~ /yes/i
filter_duplicates :inbox
end
#$stderr.puts "Saving to default mailbox"
deposit Maildir.new "/srv/mail/ats"
end
# vim: ft=ruby