carterdte_smtp_filter 0.0.3.1 → 0.0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54379beeed5e97c980ef5d630f73e4daa2715910
4
- data.tar.gz: 022f9d1dc8f2f48373570921f12dc64731449716
3
+ metadata.gz: 27253f9b1af9bd45d2f49cb4f7d01ae9826c2c57
4
+ data.tar.gz: 7a27bfc531615cb815b48bfc71456d3ab7b334f4
5
5
  SHA512:
6
- metadata.gz: 623f3caa51e8699498edb247227d273a6f298fb14266745d4df85f630c432c7b93daf806f15538921ba0c5a06d8ccbd799a04faa4cd9f5b3b0c81111d20ccb33
7
- data.tar.gz: 26f73da02580c836eb72f6b88fcea0bfaa24722a97888022b64ac4765b7cfcdefe5d0be3b414f8592a0681e51a984f168b43192f02d6f2ca78869597f252dd48
6
+ metadata.gz: 9172d84c5fef7923b38cd9a65da5b980b996fe95219c53c816c40787bc3fab240e3db7c59f8b82ba7ad154d2f7e547aee5c71c7fc9d6e168611b6af387695ee9
7
+ data.tar.gz: 616d66d591bef54e5e97373cdc98dd2bfea3351fa28da0d2d959f463e16eb126fd0eea943c5b613e85328da0cd07d64d5f60bad9fd47ece2e21d3d643421918f
@@ -30,7 +30,7 @@ if options[:config]
30
30
  CarterdteSmtpFilter::Config.parse(options[:config])
31
31
 
32
32
  logger = CarterdteSmtpFilter.logger
33
- logger.info("#{Time.now}: Starting CarterDte SMTP Filter")
33
+ logger.info("#{Time.now}: Starting CarterDte SMTP Filter v: #{CarterdteSmtpFilter::VERSION}")
34
34
 
35
35
  # Create a new server instance
36
36
  server = CarterdteSmtpFilter::SmtpServer.new()
@@ -2,30 +2,27 @@ module CarterdteSmtpFilter
2
2
 
3
3
  class Message
4
4
 
5
+ TMP_MESSAGE_DIR = "/tmp/carterdte_smtp_filter"
6
+
5
7
  attr_accessor :raw_data, :qid, :email, :response, :dte
6
8
 
7
9
  def initialize(raw_data)
8
10
  set_mail_defaults
9
11
  @raw_data = raw_data
10
12
  @email = Mail.read_from_string raw_data
11
- @dte = extract_dte
12
13
  @logger = CarterdteSmtpFilter.logger
14
+ @dte = extract_dte
13
15
  @qid = nil
14
16
  end
15
17
 
16
18
  def extract_dte
17
19
  return false unless @email.attachments.any?
18
- file = @email.attachments.select {|m| m.sub_type == "xml"}.first
20
+ xml_attachments = @email.attachments.select {|m| m.sub_type == "xml"}
21
+ file = xml_attachments.any? ? xml_attachments.first : false
19
22
  return false unless file
20
23
  CarterdteSmtpFilter::Dte.new file.body.decoded
21
24
  end
22
25
 
23
- def process
24
- return_email
25
- return unless has_dte?
26
- extract_qid_from_response
27
- end
28
-
29
26
  def has_dte?
30
27
  @dte ? true : false
31
28
  end
@@ -34,6 +31,7 @@ module CarterdteSmtpFilter
34
31
  JSON.generate({
35
32
  to: @email.to,
36
33
  from: @email.from,
34
+ message_id: @email.message_id,
37
35
  cc: @email.cc,
38
36
  date: @email.date.to_s,
39
37
  qid: qid,
@@ -55,9 +53,15 @@ module CarterdteSmtpFilter
55
53
  @qid = response.string.split(/\s+/).last
56
54
  end
57
55
 
56
+ def save_tmp
57
+ Dir.mkdir TMP_MESSAGE_DIR unless File.directory? TMP_MESSAGE_DIR
58
+ File.open("#{TMP_MESSAGE_DIR}/#{@email.message_id}.eml", 'w') { |file| file.write(@raw_data) }
59
+ end
60
+
58
61
  def return_email
59
62
  @logger.info("Returning email <#{email.message_id}> to #{CarterdteSmtpFilter::Config::return_host}:#{CarterdteSmtpFilter::Config::return_port}")
60
63
  @response = email.deliver!
64
+ extract_qid_from_response
61
65
  end
62
66
 
63
67
  end
@@ -14,8 +14,14 @@ module CarterdteSmtpFilter
14
14
  message = CarterdteSmtpFilter::Message.new(ctx[:message][:data])
15
15
  # return the email back, and extract queue_id unless we are not
16
16
  # working with Postfix
17
- message.process unless CarterdteSmtpFilter::Config::stand_alone
17
+ message.return_email unless CarterdteSmtpFilter::Config::stand_alone
18
+
19
+ # We send it to CarterDte App
18
20
  CarterdteSmtpFilter::ApiClient.push message.to_json if message.has_dte?
21
+
22
+ # Save a copy when testing
23
+ # /tmp/carterdte_smtp_filter/<message-id>
24
+ message.save_tmp if CarterdteSmtpFilter::Config::testing
19
25
  end
20
26
 
21
27
  # get event before Connection
@@ -1,3 +1,3 @@
1
1
  module CarterdteSmtpFilter
2
- VERSION = "0.0.3.1"
2
+ VERSION = "0.0.3.2"
3
3
  end
data/test/test_message.rb CHANGED
@@ -28,7 +28,7 @@ class TestMessage < Minitest::Test
28
28
  def test_message_should_save_server_queueid_response_if_any
29
29
  raw_mail = File.open("./test/fixtures/mail_with_dte.eml", "rb").read
30
30
  message = CarterdteSmtpFilter::Message.new raw_mail
31
- message.process
31
+ message.return_email
32
32
  assert_equal(message.response.string.split(/\s+/).last, message.qid)
33
33
  end
34
34
 
@@ -63,5 +63,11 @@ class TestMessage < Minitest::Test
63
63
  assert_equal(CarterdteSmtpFilter::Dte, message.dte.class)
64
64
  end
65
65
 
66
+ def test_save_tmp_should_make_tmp_dir_if_it_no_exist
67
+ message = CarterdteSmtpFilter::Message.new File.open("./test/fixtures/mail_with_dte.eml", "rb").read
68
+ message.save_tmp
69
+ assert(File.file?("/tmp/carterdte_smtp_filter/#{message.email.message_id}.eml"), "Failure message.")
70
+ end
71
+
66
72
 
67
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carterdte_smtp_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
4
+ version: 0.0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Bruna