gurgitate-mail 1.7.2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/gurgitate-mail CHANGED
@@ -12,20 +12,26 @@ GLOBAL_RULES="/etc/gurgitate-rules"
12
12
  GLOBAL_RULES_POST="/etc/gurgitate-rules-default"
13
13
 
14
14
  commandline_files = []
15
+ mail_sender = nil
15
16
 
16
17
  opts = OptionParser.new do |o|
17
- o.on("-f FILE", "--file FILE", "Use FILE as a rules file") do |file|
18
+ o.on "-f FILE", "--file FILE", "Use FILE as a rules file" do |file|
18
19
  commandline_files << file
19
20
  end
20
- o.on_tail("-h", "--help", "Show this message") do
21
+
22
+ o.on "-s SENDER", "--sender SENDER", "Use SENDER as sender" do |sender|
23
+ mail_sender = sender
24
+ end
25
+
26
+ o.on_tail "-h", "--help", "Show this message" do
21
27
  puts opts
22
28
  exit
23
29
  end
24
30
  end
25
31
 
26
- opts.parse!(ARGV)
32
+ mail_recipients = opts.parse(ARGV)
27
33
 
28
- gurgitate = Gurgitate::Gurgitate.new(STDIN)
34
+ gurgitate = Gurgitate::Gurgitate.new(STDIN, mail_recipients, mail_sender)
29
35
 
30
36
  if commandline_files.length > 0
31
37
  commandline_files.each do |file|
@@ -103,9 +103,17 @@ module Gurgitate
103
103
  # input::
104
104
  # Either the text of the email message in RFC-822 format,
105
105
  # or a filehandle where the email message can be read from
106
+ # recipient::
107
+ # The contents of the envelope recipient parameter
108
+ # sender::
109
+ # The envelope sender parameter
106
110
  # spooldir::
107
111
  # The location of the mail spools directory.
108
- def initialize(input=nil,spooldir="/var/spool/mail",&block)
112
+ def initialize(input=nil,
113
+ recipient=nil,
114
+ sender=nil,
115
+ spooldir="/var/spool/mail",
116
+ &block)
109
117
  @passwd = Etc.getpwuid
110
118
  @homedir = @passwd.dir;
111
119
  @maildir = File.join(@passwd.dir,"Mail")
@@ -118,7 +126,7 @@ module Gurgitate
118
126
 
119
127
  input_text = ""
120
128
  input.each do |l| input_text << l end
121
- super(input_text)
129
+ super(input_text, recipient, sender)
122
130
  instance_eval(&block) if block_given?
123
131
  end
124
132
 
@@ -1,14 +1,9 @@
1
1
  #!/opt/bin/ruby -w
2
2
 
3
- #------------------------------------------------------------------------
4
- #
5
- #------------------------------------------------------------------------
6
-
7
3
  module Gurgitate
8
4
  class IllegalHeader < RuntimeError ; end
9
5
 
10
6
  # A little class for a single header
11
-
12
7
  class Header
13
8
  # The name of the header
14
9
  attr_accessor :name
@@ -89,6 +84,25 @@ module Gurgitate
89
84
  y or ( ( x =~ regex ) != nil )
90
85
  end
91
86
  end
87
+
88
+ def sub!(regex, replacement)
89
+ each do |header|
90
+ header.contents = header.contents.sub regex, replacement
91
+ end
92
+ p self
93
+ end
94
+
95
+ def sub(regex, replacement)
96
+ ::Gurgitate::HeaderBag.new(
97
+ self.map do |header|
98
+ ::Gurgitate::Header.new(
99
+ "#{header.name}: " + header.contents.sub(regex,
100
+ replacement)
101
+ )
102
+ end
103
+ )
104
+ end
105
+
92
106
  end
93
107
 
94
108
  # A slightly bigger class for all of a message's headers
@@ -132,6 +146,11 @@ module Gurgitate
132
146
 
133
147
  @headers_changed=false
134
148
 
149
+ # Get the envelope From information. This comes with a
150
+ # whole category of rants: this information is absurdly hard
151
+ # to get your hands on. The best you can manage is a sort
152
+ # of educated guess.
153
+ #
135
154
  # Okay, now worry about the "From foo@bar" line. If it's
136
155
  # not there, then make one up from the Return-Path:
137
156
  # header. If there isn't a "Return-Path:" header (then I
@@ -201,6 +220,13 @@ module Gurgitate
201
220
  @headers[name]=HeaderBag.new([Header.new(name,value)])
202
221
  end
203
222
 
223
+ # Who the message is to (the envelope to)
224
+ #
225
+ # Yet another bucket of rants. Unix mail sucks.
226
+ def to
227
+ return @headers["X-Original-To"] || nil
228
+ end
229
+
204
230
  # Who the message is from (the envelope from)
205
231
  def from
206
232
  return @from || ""
@@ -15,12 +15,14 @@ module Gurgitate
15
15
  # The body of the message
16
16
  attr_accessor :body
17
17
 
18
- def initialize(text)
18
+ def initialize(text, recipient=nil, sender=nil)
19
19
  (@headertext,@body)=text.split(/^$/,2)
20
20
  fromregex=/([^ ]+@[^ ]+) \(.*\)|[^<][<](.*@.*)[>]|([^ ]+@[^ ]+)/;
21
21
  @headers=Headers.new(@headertext);
22
22
  fromregex.match(@headers["From"][0].contents);
23
23
  @from=$+
24
+ @recipient = recipient
25
+ @sender = sender
24
26
  end
25
27
 
26
28
  # Returns the header +name+
@@ -31,10 +33,11 @@ module Gurgitate
31
33
  # custom accessors
32
34
 
33
35
  # Returns the UNIX "from" line
34
- def from; @headers.from; end
36
+ def from; @sender || @headers.from; end
35
37
 
36
38
  # Returns all the candidates for a "to" line
37
- def to; @headers["To","Cc"]; end
39
+ def to; @recipient || @headers["To", "Cc"]; end
40
+ # def to; @headers["To","Cc"]; end
38
41
 
39
42
  # Returns the formatted mail message
40
43
  def to_s; @headers.to_s + @body; end
data/test.rb CHANGED
@@ -8,520 +8,20 @@ require 'test/unit'
8
8
  require 'test/unit/ui/console/testrunner'
9
9
  require 'stringio'
10
10
 
11
- class TC_Header < Test::Unit::TestCase
12
-
13
- def setup
14
- require './gurgitate-mail'
15
- end
16
-
17
- # def teardown
18
- # end
19
-
20
- def test_simple_header
21
- h=Gurgitate::Header.new("From: fromheader@example.com")
22
- assert_equal(h.name,"From", "Simple header name is From")
23
- assert_equal(h.contents,"fromheader@example.com",
24
- "Contents is fromheader@example.com")
25
- assert_equal(h.value,"fromheader@example.com",
26
- "Contents is fromheader@example.com")
27
- end
28
-
29
- # This is an illegal header that turns up in spam sometimes.
30
- # Crashing when you get spam is bad.
31
- def test_malcapitalized_header
32
- h=Gurgitate::Header.new("FROM: fromheader@example.com")
33
- assert_equal(h.name,"From", "Badly-capitalized header is From")
34
- assert_equal(h.contents,"fromheader@example.com",
35
- "Badly-capitalized header")
36
- assert_equal(h.value,"fromheader@example.com",
37
- "Badly-capitalized header")
38
- end
39
-
40
- # I got a message with "X-Qmail-Scanner-1.19" once. I hate whoever did
41
- # that.
42
- def test_dot_in_header
43
- h=Gurgitate::Header.new("From.Header: fromheader@example.com")
44
- assert_equal(h.name, "From.header",
45
- "header with dot in it is From.header")
46
- assert_equal(h.contents, "fromheader@example.com",
47
- "header with dot in it")
48
- assert_equal(h.value, "fromheader@example.com",
49
- "header with dot in it")
50
- end
51
-
52
- # Dammit! My new "anything goes" header parser was parsing too much
53
- def test_delivered_to
54
- h=Gurgitate::Header.new("Delivered-To: dagbrown@example.com")
55
- assert_equal("Delivered-To", h.name)
56
- assert_equal "dagbrown@example.com", h.contents
57
- assert_equal "dagbrown@example.com", h.value
58
- end
59
-
60
- # This is another particularly horrible spamware-generated not-a-header.
61
- def test_header_that_starts_with_hyphen
62
- h=Gurgitate::Header.new("-From: -fromheader@example.com")
63
- assert_equal(h.name, "-From",
64
- "header with leading hyphen is -From")
65
- assert_equal(h.contents, "-fromheader@example.com",
66
- "header with leading hyphen")
67
- assert_equal(h.value, "-fromheader@example.com",
68
- "header with leading hyphen")
69
- end
70
-
71
- # This is another illegal header that turns up in spam sometimes.
72
- # Crashing when you get spam is bad.
73
- def test_nonalphabetic_initial_char_header
74
- h=Gurgitate::Header.new("2From: fromheader@example.com")
75
- assert_equal(h.name,"2from",
76
- "Header that starts with illegal char is 2From")
77
- assert_equal(h.contents, "fromheader@example.com",
78
- "Header that starts with illegal char")
79
- assert_equal(h.value, "fromheader@example.com",
80
- "Header that starts with illegal char")
81
- end
82
-
83
- def test_bad_headers
84
- assert_raises(Gurgitate::IllegalHeader,"Empty name") {
85
- h=Gurgitate::Header.new(": Hi")
86
- }
87
- # assert_raises(Gurgitate::IllegalHeader,"Empty header contents") {
88
- # h=Gurgitate::Header.new("From: ")
89
- # }
90
- assert_raises(Gurgitate::IllegalHeader,"Bad header syntax") {
91
- h=Gurgitate::Header.new("This is completely wrong")
92
- }
93
- end
94
- def test_extending_header
95
- h=Gurgitate::Header.new("From: fromheader@example.com")
96
- h << " (Dave Brown)"
97
- assert_equal(h.name,"From","Extended header is From")
98
- assert_equal(h.contents,"fromheader@example.com\n (Dave Brown)",
99
- "Extended header contains all data")
100
- assert_equal(h.contents,h.value,"Contents same as value")
101
- end
102
-
103
- def test_empty_header_with_extension
104
- h=Gurgitate::Header.new("From:")
105
- h << " fromheader@example.com"
106
- assert_equal("From",h.name,"Empty extended header is From")
107
- assert_equal("\n fromheader@example.com", h.contents,
108
- "Empty extended header contains all data")
109
- assert_equal(h.contents, h.value, "Contents same as value")
110
- end
111
-
112
- def test_changing_header
113
- h=Gurgitate::Header.new("From: fromheader@example.com")
114
- h.contents="anotherfromheader@example.com"
115
- assert_equal(h.contents,"anotherfromheader@example.com",
116
- "header contents contains new data")
117
- end
118
-
119
- def test_tabseparated_header
120
- h=Gurgitate::Header.new("From:\tfromheader@example.com")
121
- assert_equal(h.name,"From","Tabseparated header is From (bug#154)")
122
- assert_equal(h.contents,"fromheader@example.com",
123
- "Tabseparated header's contents are correct (bug#154)")
124
- assert_equal(h.contents,h.value,"Contents same as value (bug#154)")
125
- end
126
-
127
- def test_conversion_to_String
128
- h=Gurgitate::Header.new("From: fromheader@example.com")
129
- assert_equal(h.to_s,"From: fromheader@example.com", "Conversion to string returns input")
130
- end
131
-
132
- def test_regex_match
133
- h=Gurgitate::Header.new("From: fromheader@example.com")
134
- assert_equal(0,h.matches(/fromheader/),"Matches regex that would match input")
135
- assert_equal(nil,h.matches(/notininput/),"Does not match regex that would not match input")
136
- end
137
- end
138
-
139
- class TC_Headers < Test::Unit::TestCase
140
- def setup
141
- require './gurgitate-mail'
142
- end
143
-
144
- def test_single_header
145
- h=Gurgitate::Headers.new(<<'EOF'
146
- From fromline@example.com Sat Sep 27 12:20:25 PDT 2003
147
- From: fromheader@example.com
148
- EOF
149
- )
150
- assert_equal("fromline@example.com",h.from)
151
- assert_equal(1,h["From"].length)
152
- assert_equal("From",h["From"][0].name)
153
- assert_equal("fromheader@example.com",h["From"][0].contents)
154
- end
155
-
156
- def test_fromline_simple_username
157
- h=Gurgitate::Headers.new(<<'EOF'
158
- From fromline Sat Sep 27 12:20:25 PDT 2003
159
- From: fromheader@example.com
160
- EOF
161
- )
162
- assert_equal("fromline",h.from)
163
- assert_equal(1,h["From"].length)
164
- assert_equal("From",h["From"][0].name)
165
- assert_equal("fromheader@example.com",h["From"][0].contents)
11
+ def runtests(testcases)
12
+ testcases.each do |testcase|
13
+ Test::Unit::UI::Console::TestRunner.run testcase
166
14
  end
167
-
168
- def test_fromline_no_username
169
- h=Gurgitate::Headers.new(<<'EOF'
170
- From Sat Sep 27 12:20:25 PDT 2003
171
- From: fromheader@example.com
172
- EOF
173
- )
174
- assert_equal("",h.from)
175
- assert_equal(1,h["From"].length)
176
- assert_equal("From",h["From"][0].name)
177
- assert_equal("fromheader@example.com",h["From"][0].contents)
178
- end
179
-
180
- def test_missing_toline
181
- h=Gurgitate::Headers.new(<<'EOF'
182
- From: fromheader@example.com
183
- EOF
184
- )
185
- assert_equal('fromheader@example.com',h.from)
186
- assert_equal(1,h["From"].length)
187
- assert_equal("From",h["From"][0].name)
188
- assert_equal("fromheader@example.com",h["From"][0].contents)
189
- end
190
-
191
- def test_multiple_headers
192
- h=Gurgitate::Headers.new(<<'EOF'
193
- From fromline@example.com Sat Sep 27 12:20:25 PDT 2003
194
- From: fromheader@example.com
195
- To: toheader@example.com
196
- Subject: Subject line
197
- EOF
198
- )
199
- assert_equal(h.from,"fromline@example.com")
200
- assert_equal(1,h["From"].length)
201
- assert_equal("From",h["From"][0].name)
202
- assert_equal("fromheader@example.com",h["From"][0].contents)
203
- assert_equal(1,h["To"].length)
204
- assert_equal("To",h["To"][0].name)
205
- assert_equal("toheader@example.com",h["To"][0].contents)
206
- assert_equal(1,h["Subject"].length)
207
- assert_equal("Subject",h["Subject"][0].name)
208
- assert_equal("Subject line",h["Subject"][0].contents)
209
- end
210
-
211
- def test_missing_fromline
212
- h=Gurgitate::Headers.new(<<'EOF'
213
- From: fromheader@example.com
214
- To: toheader@example.com
215
- Subject: Subject line
216
- EOF
217
- )
218
- assert_equal('fromheader@example.com',h.from)
219
- assert_equal(1,h["From"].length)
220
- assert_equal("From",h["From"][0].name)
221
- assert_equal("fromheader@example.com",h["From"][0].contents)
222
- assert_equal(1,h["To"].length)
223
- assert_equal("To",h["To"][0].name)
224
- assert_equal("toheader@example.com",h["To"][0].contents)
225
- assert_equal(1,h["Subject"].length)
226
- assert_equal("Subject",h["Subject"][0].name)
227
- assert_equal("Subject line",h["Subject"][0].contents)
228
- end
229
-
230
- def test_multiline_headers
231
- h=Gurgitate::Headers.new(<<'EOF'
232
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
233
- From: fromheader@example.com
234
- To: toheader@example.com,
235
- nexttoheader@example.com
236
- Subject: Subject line
237
- EOF
238
- )
239
- assert_equal(h.from,"fromline@example.com")
240
- assert_equal(1,h["From"].length)
241
- assert_equal("From",h["From"][0].name)
242
- assert_equal("fromheader@example.com",h["From"][0].contents)
243
- assert_equal(1,h["To"].length)
244
- assert_equal("To",h["To"][0].name)
245
- assert_equal("toheader@example.com,\n nexttoheader@example.com",h["To"][0].contents)
246
- assert_equal(1,h["Subject"].length)
247
- assert_equal("Subject",h["Subject"][0].name)
248
- assert_equal("Subject line",h["Subject"][0].contents)
249
- end
250
-
251
- def test_multiline_headers_with_extra_colons
252
- h=Gurgitate::Headers.new(<<'EOF'
253
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
254
- From: fromheader@example.com
255
- To: toheader@example.com,
256
- nexttoheader@example.com (The test: header)
257
- Subject: Subject line
258
- EOF
259
- )
260
- assert_equal(h.from,"fromline@example.com")
261
- assert_equal(1,h["From"].length)
262
- assert_equal("From",h["From"][0].name)
263
- assert_equal("fromheader@example.com",h["From"][0].contents)
264
- assert_equal(1,h["To"].length)
265
- assert_equal("To",h["To"][0].name)
266
- assert_equal("toheader@example.com,\n nexttoheader@example.com (The test: header)",h["To"][0].contents)
267
- assert_equal(1,h["Subject"].length)
268
- assert_equal("Subject",h["Subject"][0].name)
269
- assert_equal("Subject line",h["Subject"][0].contents)
270
- end
271
-
272
- def test_multiline_headers_with_various_levels_of_indentation
273
- h=Gurgitate::Headers.new(<<'EOF'
274
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
275
- From: fromheader@example.com
276
- To: toheader@example.com,
277
- nexttoheader@example.com,
278
- thirdtoheader@example.com,
279
- fourthtoheader@example.com
280
- Subject: Subject line
281
- EOF
282
- )
283
- assert_equal(h.from,"fromline@example.com")
284
- assert_equal(1,h["From"].length)
285
- assert_equal("From",h["From"][0].name)
286
- assert_equal("fromheader@example.com",h["From"][0].contents)
287
- assert_equal(1,h["To"].length)
288
- assert_equal("To",h["To"][0].name)
289
- assert_equal("toheader@example.com,\n nexttoheader@example.com,\n thirdtoheader@example.com,\n fourthtoheader@example.com",h["To"][0].contents)
290
- assert_equal(1,h["Subject"].length)
291
- assert_equal("Subject",h["Subject"][0].name)
292
- assert_equal("Subject line",h["Subject"][0].contents)
293
- end
294
-
295
- def test_a_header_that_actually_crashed_gurgitate
296
- h=Gurgitate::Headers.new(<<'EOF'
297
- Return-path: <nifty-bounces@neurotica.com>
298
- Received: from pd8mr3no.prod.shaw.ca
299
- (pd8mr3no-qfe2.prod.shaw.ca [10.0.144.160]) by l-daemon
300
- (iPlanet Messaging Server 5.2 HotFix 1.16 (built May 14 2003))
301
- with ESMTP id <0HO6002FDGPREL@l-daemon> for dagbrown@shaw.ca; Tue,
302
- 11 Nov 2003 00:56:15 -0700 (MST)
303
- Received: from pd7mi4no.prod.shaw.ca ([10.0.149.117])
304
- by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003))
305
- with ESMTP id <0HO60055LGPR40@l-daemon> for dagbrown@shaw.ca
306
- (ORCPT dagbrown@shaw.ca); Tue, 11 Nov 2003 00:56:15 -0700 (MST)
307
- Received: from venom.easydns.com (smtp.easyDNS.com [216.220.40.247])
308
- by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003))
309
- with ESMTP id <0HO60079HGPR79@l-daemon> for dagbrown@shaw.ca; Tue,
310
- 11 Nov 2003 00:56:15 -0700 (MST)
311
- Received: from ohno.mrbill.net (ohno.mrbill.net [207.200.6.75])
312
- by venom.easydns.com (Postfix) with ESMTP id D6493722BB for
313
- <dagbrown@lart.ca>; Tue, 11 Nov 2003 02:53:50 -0500 (EST)
314
- Received: by ohno.mrbill.net (Postfix) id ED0AD53380; Tue,
315
- 11 Nov 2003 01:56:13 -0600 (CST)
316
- Received: from mail.neurotica.com (neurotica.com [207.100.203.161])
317
- by ohno.mrbill.net (Postfix) with ESMTP id 5CD465337F for
318
- <dagbrown@dagbrown.com>; Tue, 11 Nov 2003 01:56:13 -0600 (CST)
319
- Received: from mail.neurotica.com (localhost [127.0.0.1])
320
- by mail.neurotica.com (Postfix) with ESMTP id CDAA2364C; Tue,
321
- 11 Nov 2003 02:56:03 -0500 (EST)
322
- Received: from smtpzilla5.xs4all.nl (smtpzilla5.xs4all.nl [194.109.127.141])
323
- by mail.neurotica.com (Postfix) with ESMTP id B6A22361E for
324
- <nifty@neurotica.com>; Tue, 11 Nov 2003 02:56:00 -0500 (EST)
325
- Received: from xs1.xs4all.nl (xs1.xs4all.nl [194.109.21.2])
326
- by smtpzilla5.xs4all.nl (8.12.9/8.12.9) with ESMTP id hAB7u5ZZ042116 for
327
- <nifty@neurotica.com>; Tue, 11 Nov 2003 08:56:05 +0100 (CET)
328
- Received: from xs1.xs4all.nl (wstan@localhost.xs4all.nl [127.0.0.1])
329
- by xs1.xs4all.nl (8.12.10/8.12.9) with ESMTP id hAB7u5xE048677 for
330
- <nifty@neurotica.com>; Tue,
331
- 11 Nov 2003 08:56:05 +0100 (CET envelope-from wstan@xs4all.nl)
332
- Received: (from wstan@localhost) by xs1.xs4all.nl (8.12.10/8.12.9/Submit)
333
- id hAB7u4sZ048676 for nifty@neurotica.com; Tue,
334
- 11 Nov 2003 08:56:04 +0100 (CET envelope-from wstan)
335
- Date: Tue, 11 Nov 2003 08:56:04 +0100
336
- From: William Staniewicz <wstan@xs4all.nl>
337
- Subject: Re: [nifty] Ping...
338
- In-reply-to: <9636B78C-140B-11D8-9EE6-003065D0C184@nimitzbrood.com>
339
- Sender: nifty-bounces@neurotica.com
340
- To: Nifty <nifty@neurotica.com>
341
- Cc:
342
- Errors-to: nifty-bounces@neurotica.com
343
- Reply-to: Nifty <nifty@neurotica.com>
344
- Message-id: <20031111075604.GE79497@xs4all.nl>
345
- MIME-version: 1.0
346
- Content-type: text/plain; charset=us-ascii
347
- Content-disposition: inline
348
- Precedence: list
349
- X-BeenThere: nifty@mail.neurotica.com
350
- Delivered-to: dagbrown@mrbill.net
351
- Delivered-to: nifty@neurotica.com
352
- User-Agent: Mutt/1.4.1i
353
- X-Original-To: nifty@neurotica.com
354
- References: <9636B78C-140B-11D8-9EE6-003065D0C184@nimitzbrood.com>
355
- X-Mailman-Version: 2.1.2
356
- List-Post: <mailto:nifty@mail.neurotica.com>
357
- List-Subscribe: <http://mail.neurotica.com:8080/mailman/listinfo/nifty>,
358
- <mailto:nifty-request@mail.neurotica.com?subject=subscribe>
359
- List-Unsubscribe: <http://mail.neurotica.com:8080/mailman/listinfo/nifty>,
360
- <mailto:nifty-request@mail.neurotica.com?subject=unsubscribe>
361
- List-Help: <mailto:nifty-request@mail.neurotica.com?subject=help>
362
- List-Id: Nifty <nifty.mail.neurotica.com>
363
- Original-recipient: rfc822;dagbrown@shaw.ca
364
- EOF
365
- )
366
- assert_equal(h.from,"nifty-bounces@neurotica.com")
367
- assert_equal(1,h["From"].length)
368
- assert_equal("From",h["From"][0].name)
369
- assert_equal("William Staniewicz <wstan@xs4all.nl>",h["From"][0].contents)
370
- assert_equal(1,h["To"].length)
371
- assert_equal("To",h["To"][0].name)
372
- assert_equal('Nifty <nifty@neurotica.com>',h["To"][0].contents)
373
-
374
- assert_equal(1,h["Subject"].length)
375
- assert_equal("Subject",h["Subject"][0].name)
376
- assert_equal("Re: [nifty] Ping...",h["Subject"][0].contents)
377
- end
378
-
379
- def another_crashy_test
380
- h=Gurgitate::Headers.new(<<'EOF'
381
- From HEYITBLEWUP Fri Nov 21 14:41:08 PST 2003
382
- Received: from unknown (harley.radius [192.168.0.123]) by yoda.radius with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
383
- id LYN7YZKG; Wed, 9 Jul 2003 14:36:40 -0700
384
- Subject: IAP password
385
- EOF
386
- )
387
- assert_equal(h.from,"HEYITBLEWUP")
388
- assert_equal(1,h["From"].length)
389
- assert_equal("From",h["From"][0].name)
390
- assert_equal("IAP password",h["Subject"][0].name)
391
- end
392
-
393
- def test_fromline_no_hostname # illegal from line
394
- m=<<'EOF'
395
- From HEYITBLEWUP Sat Mar 27 16:02:12 PST 2004
396
- Received: from ohno.mrbill.net (ohno.mrbill.net [207.200.6.75])
397
- by lart.ca (Postfix) with ESMTP id A485F104CA9
398
- for <dagbrown@lart.ca>; Sat, 27 Mar 2004 15:58:06 -0800 (PST)
399
- Received: by ohno.mrbill.net (Postfix)
400
- id 0D3423A289; Sat, 27 Mar 2004 17:58:42 -0600 (CST)
401
- Delivered-To: dagbrown@mrbill.net
402
- Received: from 66-168-59-126.jvl.wi.charter.com (66-168-59-126.jvl.wi.charter.com [66.168.59.126])
403
- by ohno.mrbill.net (Postfix) with SMTP id 948BD3A288
404
- for <dagbrown@dagbrown.com>; Sat, 27 Mar 2004 17:58:41 -0600 (CST)
405
- X-Message-Info: HOCBSQX
406
- Message-Id: <20040327235841.948BD3A288@ohno.mrbill.net>
407
- Date: Sat, 27 Mar 2004 17:58:41 -0600 (CST)
408
- From: ""@
409
- To: undisclosed-recipients: ;
410
- EOF
411
- h=Gurgitate::Headers.new(m)
412
- assert_equal(%{""@},h["From"][0].contents)
413
- assert_equal(1,h["From"].length)
414
- end
415
-
416
- def test_editing_header
417
- m = <<'EOF'
418
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
419
- From: fromline@example.com
420
- To: toline@example.com
421
- Subject: Subject line
422
- EOF
423
- h=Gurgitate::Headers.new(m)
424
- h["From"]="anotherfromline@example.com"
425
- assert_equal("anotherfromline@example.com",h["From"][0].contents,
426
- "From line correctly changed")
427
- assert_match(/^From: anotherfromline@example.com$/,h.to_s,
428
- "From line correctly turns up in finished product")
429
- end
430
-
431
- def test_editing_from
432
- m = <<'EOF'
433
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
434
- From: fromline@example.com
435
- To: toline@example.com
436
- Subject: Subject line
437
- EOF
438
- h=Gurgitate::Headers.new(m)
439
- t=Time.new.to_s
440
- h.from="anotherfromline@example.com"
441
- assert_equal("anotherfromline@example.com",h.from,
442
- "Envelope from correctly changed")
443
- assert_match(/^From anotherfromline@example.com #{t}/,
444
- h.to_mbox, "Envelope from changed in finished product")
445
- end
446
-
447
- def test_match_multiple_headers
448
- m = <<'EOF'
449
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
450
- From: fromline@example.com
451
- To: toline@example.com
452
- Subject: Subject line
453
- EOF
454
- h=Gurgitate::Headers.new(m)
455
- assert_equal(true,h["From","To"] =~ /fromline@example.com/,
456
- "headers contains fromline")
457
- assert_equal(true,h["From","To"] =~ /toline@example.com/,
458
- "headers contains toline")
459
- assert_equal(false,h["From","To"] =~ /nonexistent@example.com/,
460
- "headers do not contain nonexistent value")
461
- assert_equal(false,h["Rabbit"] =~ /nonexistent/,
462
- "Asking for a nonexistent header")
463
- end
464
-
465
- def test_broken_spam
466
- m=<<'EOF'
467
- Return-Path: kirstenparsonsry@yahoo.com
468
- Delivery-Date: Fri May 21 19:42:02 PDT
469
- Return-Path: kirstenparsonsry@yahoo.com
470
- Delivery-Date: Fri May 21 17:39:51 2004
471
- Return-Path: <kirstenparsonsry@yahoo.com>
472
- X-Original-To: dagbrown@lart.ca
473
- Delivered-To: dagbrown@lart.ca
474
- Received: from anest.co.jp (c-24-1-221-189.client.comcast.net [24.1.221.189])
475
- by lart.ca (Postfix) with ESMTP id 05B7F5704
476
- for <dagbrown@lart.ca>; Fri, 21 May 2004 17:39:51 -0700 (PDT)
477
- Message-ID: <NKELFLPJDPLDHJCMGFHDFEKLLNAA.kirstenparsonsry@yahoo.com>
478
- From: "Kirsten Parsons" <kirstenparsonsry@yahoo.com>
479
- To: dagbrown@lart.ca
480
- Subject: Congrats!
481
- Date: Fri, 21 May 2004 20:56:27 +0000
482
- MIME-Version: 1.0
483
- Content-Type: text/plain
484
- Content-Transfer-Encoding: base64
485
- EOF
486
- h=Gurgitate::Headers.new(m)
487
-
488
- assert_equal(Gurgitate::Header.new("To","dagbrown@lart.ca").contents,
489
- h["To"][0].contents,"To header is as expected")
490
-
491
- assert_equal(false,h["To","Cc"] =~ /\blunar@lunar-linux.org\b/i,
492
- "There should be no Lunar Linux mailing list here")
493
-
494
- assert_equal(false,h["To"] =~ /\blunar@lunar-linux.org\b/i,
495
- "There should be no Lunar Linux mailing list in To line")
496
- assert_equal(false,h["Cc"] =~ /\blunar@lunar-linux.org\b/i,
497
- "There should be no Lunar Linux mailing list in Cc line")
498
- end
499
- end
500
-
501
- class TC_Process < Test::Unit::TestCase
502
- def setup
503
- m = StringIO.new("From: me\nTo: you\nSubject: test\n\nHi.")
504
- @gurgitate = Gurgitate::Gurgitate.new(m)
505
- end
506
-
507
- def test_1
508
- assert_nothing_raised do
509
- @gurgitate.process { break }
510
- @gurgitate.process { pipe('cat > /dev/null') }
511
- @gurgitate.process { return }
512
- end
513
- end
514
15
  end
515
16
 
516
- def runtests
517
- Test::Unit::UI::Console::TestRunner.run(TC_Header)
518
- Test::Unit::UI::Console::TestRunner.run(TC_Headers)
519
- Test::Unit::UI::Console::TestRunner.run(TC_Process)
17
+ testcases = Dir[File.join("tests","test_*")].map do |file|
18
+ load file
19
+ eval("TC_" + File.basename(file,".rb").sub(/^test_/,'').capitalize)
520
20
  end
521
21
 
522
22
  if __FILE__ == $0 then
523
23
  if(ARGV[0] == '-c')
524
24
  require 'coverage'
525
25
  end
526
- runtests
26
+ runtests testcases
527
27
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: gurgitate-mail
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.7.2
7
- date: 2006-08-22 00:00:00 +09:00
6
+ version: 1.8.0
7
+ date: 2006-12-01 00:00:00 +09:00
8
8
  summary: gurgitate-mail is a mail filter (and a mail-delivery agent)
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Dave Brown
30
31
  files: