entp-astrotrain 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/astrotrain.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{astrotrain}
5
- s.version = "0.2.0"
5
+ s.version = "0.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["technoweenie"]
9
- s.date = %q{2009-09-21}
9
+ s.date = %q{2009-09-23}
10
10
  s.email = %q{technoweenie@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -190,12 +190,29 @@ module Astrotrain
190
190
  @mail.port.to_s
191
191
  end
192
192
 
193
+ def header(key)
194
+ @headers ||= {}
195
+ if !@headers.key?(key)
196
+ @headers[key] = if self.class.skipped_headers.include?(key)
197
+ nil
198
+ else
199
+ header = @mail.header[key]
200
+ begin
201
+ header.to_s
202
+ rescue
203
+ header.raw_body
204
+ end
205
+ end
206
+ end
207
+ @headers[key]
208
+ end
209
+
193
210
  def headers
194
211
  @headers ||= begin
195
212
  h = {}
196
213
  @mail.header.each do |key, value|
197
- next if self.class.skipped_headers.include?(key)
198
- h[key] = value.to_s
214
+ header_value = header(key)
215
+ h[key] = header_value if header_value
199
216
  end
200
217
  h
201
218
  end
@@ -45,4 +45,14 @@ module Astrotrain
45
45
  end
46
46
  end
47
47
  end
48
+ end
49
+
50
+ module TMail
51
+ # small tweak to provide the raw body of headers in case they're unable to
52
+ # be parsed properly
53
+ class HeaderField
54
+ def raw_body
55
+ @body
56
+ end
57
+ end
48
58
  end
data/test/message_test.rb CHANGED
@@ -123,6 +123,22 @@ class Astrotrain::MessageTest < Astrotrain::TestCase
123
123
  @body = "---------- Forwarded message ----------\nblah blah"
124
124
  end
125
125
 
126
+ describe "basic, with bad content type header" do
127
+ before :all do
128
+ @raw = mail(:bad_content_type)
129
+ @message = Astrotrain::Message.parse(@raw)
130
+ end
131
+
132
+ it "parses body" do
133
+ expected = "--====boundary====\nContent-Type: text/plain; charset=\"us-ascii\"\n\nThis message is being generated automatically to notify you\nthat PowerMTA has crashed on mtasv.net.\n\nAs the information below is likely to be essential for debugging\nthe problem, please forward this message to <support@port25.com>.\nThank you.\n\n--====boundary====\nContent-Type: text/plain; charset=\"us-ascii\"\n\nYo\n--====boundary====--"
134
+ assert_equal expected, @message.body
135
+ end
136
+
137
+ it "attempts parsing bad header" do
138
+ assert_equal "multipart/mixed; boundary=\"====boundary=\"===\"\"", @message.header('content-type')
139
+ end
140
+ end
141
+
126
142
  describe "basic, single sender/recipient" do
127
143
  before :all do
128
144
  @raw = mail(:basic)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entp-astrotrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - technoweenie
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-21 00:00:00 -07:00
12
+ date: 2009-09-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15