astrotrain 0.4.4 → 0.4.5

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.4.4
1
+ 0.4.6
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.4.4"
5
+ s.version = "0.4.5"
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-10-02}
9
+ s.date = %q{2009-10-30}
10
10
  s.email = %q{technoweenie@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
data/lib/astrotrain.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module Astrotrain
2
+ class ProcessingCancelled < StandardError; end
3
+
2
4
  CALLBACK_TYPES = [:pre_mapping, :pre_processing, :post_processing]
3
5
  class << self
4
6
  attr_accessor :root, :lib_root, :callbacks
@@ -45,7 +45,11 @@ module Astrotrain
45
45
  if mapping
46
46
  logged.recipient = recipient
47
47
  logged.mapping = mapping
48
- mapping.process(message, recipient)
48
+ begin
49
+ mapping.process(message, recipient)
50
+ rescue Astrotrain::ProcessingCancelled
51
+ logged.error_message = "Cancelled."
52
+ end
49
53
  logged.delivered_at = Time.now.utc
50
54
  end
51
55
  LoggedMail.log_processed # save successfully processed messages?
@@ -61,6 +65,7 @@ module Astrotrain
61
65
  def process(message, recipient)
62
66
  Astrotrain.callback(:pre_processing, message, self)
63
67
  Transport.process(message, self, recipient)
68
+
64
69
  end
65
70
 
66
71
  # returns true if the email matches this mapping. Wildcards in the name are allowed.
@@ -54,6 +54,7 @@ module Astrotrain
54
54
  Astrotrain.callback(:pre_mapping, message)
55
55
  Mapping.process(message, file)
56
56
  message
57
+ rescue Astrotrain::ProcessingCancelled
57
58
  end
58
59
 
59
60
  # Processes the given file. It parses it by reading the contents, and optionally
@@ -282,8 +283,13 @@ module Astrotrain
282
283
  @body = @body.join("\n")
283
284
  @html = @html.join("\n")
284
285
  else
285
- @body = @mail.body
286
- @html = ''
286
+ if @mail.content_type == 'text/html'
287
+ @html = @mail.body
288
+ @body = ''
289
+ else
290
+ @body = @mail.body
291
+ @html = ''
292
+ end
287
293
  end
288
294
  if !@mail.charset
289
295
  @body = convert_to_utf8(@body)
@@ -4,13 +4,7 @@ To: xyz@astrotrain.com
4
4
  Message-ID: <11644553.1741252281981737.JavaMail.root@astrotrain>
5
5
  Subject: ABC DEF
6
6
  MIME-Version: 1.0
7
- Content-Type: multipart/mixed;
8
- boundary="----=_Part_1695_189596019.1252281981305"
9
- X-Mailer: Railo Mail
10
-
11
- ------=_Part_1695_189596019.1252281981305
12
7
  Content-Type: text/html; charset=UTF-8
13
8
  Content-Transfer-Encoding: quoted-printable
14
9
 
15
- <p>ABC</p>
16
- ------=_Part_1695_189596019.1252281981305--
10
+ <p>ABC</p>
data/test/message_test.rb CHANGED
@@ -42,6 +42,16 @@ class Astrotrain::MessageTest < Astrotrain::TestCase
42
42
  assert_equal callback_msg, @msg
43
43
  end
44
44
 
45
+ it "it allows pre_mapping callback to cancel processing" do
46
+ Astrotrain::LoggedMail.log_processed = true
47
+ Astrotrain.callback(:pre_mapping) do |message|
48
+ raise Astrotrain::ProcessingCancelled
49
+ end
50
+
51
+ @msg = Astrotrain::Message.receive(mail(:mapped))
52
+ assert_equal 0, Astrotrain::LoggedMail.count
53
+ end
54
+
45
55
  it "calls pre_processing callback" do
46
56
  Astrotrain::LoggedMail.log_processed = true
47
57
  callback_msg, callback_map = nil
@@ -56,6 +66,17 @@ class Astrotrain::MessageTest < Astrotrain::TestCase
56
66
  assert_equal callback_map, @log.mapping
57
67
  end
58
68
 
69
+ it "it allows pre_processing callback to cancel processing" do
70
+ Astrotrain::LoggedMail.log_processed = true
71
+ Astrotrain.callback(:pre_processing) do |message, mapping|
72
+ raise Astrotrain::ProcessingCancelled
73
+ end
74
+
75
+ @msg = Astrotrain::Message.receive(mail(:mapped))
76
+ @log = Astrotrain::LoggedMail.first
77
+ assert_equal "Cancelled.", @log.error_message
78
+ end
79
+
59
80
  it "calls post_processing callback" do
60
81
  Astrotrain::LoggedMail.log_processed = true
61
82
  callback_msg, callback_map, callback_log = nil
@@ -145,11 +166,8 @@ class Astrotrain::MessageTest < Astrotrain::TestCase
145
166
  @message = Astrotrain::Message.parse(@raw)
146
167
  end
147
168
 
148
- it "parses message-id" do
169
+ it "parses message-id and headers" do
149
170
  assert_equal 'a16be7390810161014n52b603e9k1aa6bb803c6735aa@mail.gmail.com', @message.message_id
150
- end
151
-
152
- it "parses TMail::Mail headers" do
153
171
  expected = {'mime-version' => '1.0', 'content-type' => 'text/plain; charset=ISO-8859-1', 'to' => 'Processor <processor@astrotrain.com>',
154
172
  'x-custom' => 'reply', 'content-transfer-encoding' => '7bit', 'content-disposition' => 'inline', 'message-id' => '<a16be7390810161014n52b603e9k1aa6bb803c6735aa@mail.gmail.com>'}
155
173
  assert_equal expected, @message.headers
@@ -369,6 +387,21 @@ class Astrotrain::MessageTest < Astrotrain::TestCase
369
387
  end
370
388
  end
371
389
 
390
+ describe "with only HTML body in a multipart message" do
391
+ before :all do
392
+ @raw = mail(:html_multipart)
393
+ @message = Astrotrain::Message.parse(@raw)
394
+ end
395
+
396
+ it "parses emtpy body" do
397
+ assert_equal '', @message.body
398
+ end
399
+
400
+ it "parses HTML body" do
401
+ assert_equal "<p>ABC</p>\n------", @message.html
402
+ end
403
+ end
404
+
372
405
  describe "with only HTML body" do
373
406
  before :all do
374
407
  @raw = mail(:html)
@@ -380,7 +413,7 @@ class Astrotrain::MessageTest < Astrotrain::TestCase
380
413
  end
381
414
 
382
415
  it "parses HTML body" do
383
- assert_equal "<p>ABC</p>\n------", @message.html
416
+ assert_equal "<p>ABC</p>", @message.html
384
417
  end
385
418
  end
386
419
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astrotrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
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-10-02 00:00:00 -07:00
12
+ date: 2009-10-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency