carterdte_smtp_filter 0.0.6.3 → 0.0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/carterdte_smtp_filter/message.rb +9 -2
- data/lib/carterdte_smtp_filter/smtp_server.rb +1 -1
- data/lib/carterdte_smtp_filter/spool_manager.rb +1 -1
- data/lib/carterdte_smtp_filter/version.rb +1 -1
- data/test/fixtures/config.yml +2 -1
- data/test/fixtures/to_in_brackets.eml +10 -0
- data/test/test_message.rb +6 -0
- data/test/test_smtp_server.rb +17 -17
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b40da9da5d7f10d95586a05ea8280c318f899b6f
|
4
|
+
data.tar.gz: 3d11b216c1b5b980e856d19d67b2df7b81b070ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc872cc0fd2e2ac93f8bde7e5eae9e826436ecd8e9c2c74887ed02b6be492686b3ed9b8880c2a69370236ec4b9aa7aadb159257f8a68484eb72d3c91deb91d88
|
7
|
+
data.tar.gz: 32d237a518241ee42329bcc9d69d23c821d28caf32b6baae0531ce180f09b8d0eb1b6db6119b7e239639fd25911b4fa38e8753fab640d9ddb9f220b96e702e75
|
@@ -6,16 +6,23 @@ module CarterdteSmtpFilter
|
|
6
6
|
|
7
7
|
attr_accessor :raw_data, :return_qid, :email, :response, :dte, :qid
|
8
8
|
|
9
|
-
def initialize(raw_data, qid = nil)
|
9
|
+
def initialize(raw_data, envelope = nil, qid = nil)
|
10
10
|
set_mail_defaults
|
11
11
|
@raw_data = raw_data
|
12
|
-
@email =
|
12
|
+
@email = parse_email(envelope)
|
13
13
|
@logger = CarterdteSmtpFilter.logger
|
14
14
|
@dte = extract_dte
|
15
15
|
@qid = qid || generate_qid
|
16
16
|
@return_qid = nil
|
17
17
|
end
|
18
18
|
|
19
|
+
def parse_email(envelope)
|
20
|
+
email = Mail.read_from_string raw_data
|
21
|
+
email.from = envelope[:from] unless envelope.nil?
|
22
|
+
email.from = envelope[:to] unless envelope.nil?
|
23
|
+
email
|
24
|
+
end
|
25
|
+
|
19
26
|
def queue_file
|
20
27
|
queue_sub_dir = qid.split(//).first
|
21
28
|
"#{Config::spool_directory}/#{queue_sub_dir}/#{qid}"
|
@@ -15,7 +15,7 @@ module CarterdteSmtpFilter
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def on_message_data_event(ctx)
|
18
|
-
message = CarterdteSmtpFilter::Message.new(ctx[:message][:data])
|
18
|
+
message = CarterdteSmtpFilter::Message.new(ctx[:envelope], ctx[:message][:data])
|
19
19
|
carterdte_logger.info("Processing message: #{message.qid}")
|
20
20
|
# Save a copy when testing
|
21
21
|
# /tmp/carterdte_smtp_filter/<message-id>
|
@@ -17,7 +17,7 @@ module CarterdteSmtpFilter
|
|
17
17
|
def resend_message(file_path)
|
18
18
|
qid = queue_id file_path
|
19
19
|
logger.info("Resending #{qid} - #{file_path}")
|
20
|
-
message = CarterdteSmtpFilter::Message.new(File.read(file_path), qid)
|
20
|
+
message = CarterdteSmtpFilter::Message.new(File.read(file_path), nil, qid)
|
21
21
|
FileUtils.rm file_path
|
22
22
|
CarterdteSmtpFilter::ApiClient.new.async.perform message
|
23
23
|
message
|
data/test/fixtures/config.yml
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
Date: Wed, 3 Jun 2015 18:00:44 -0300
|
2
|
+
To: <philips@facturanet.cl>
|
3
|
+
From: "Comercial Copelec ño" <dte@copelec.cl>
|
4
|
+
Reply-To: "ó es una cosa"<dte@copelec.cl>
|
5
|
+
Subject: Documento Tributario Electr�nico
|
6
|
+
Content-Type: multipart/mixed; boundary="===SEE34177390===MIX==="
|
7
|
+
Message-Id: <20150603205852.6D8FC126007F@mail.copelec.cl>
|
8
|
+
|
9
|
+
ñ ññ ñ ñ ññ ñ ñ ñ
|
10
|
+
ááááaá´
|
data/test/test_message.rb
CHANGED
@@ -92,5 +92,11 @@ class TestMessage < Minitest::Test
|
|
92
92
|
assert(File.file?("#{message.queue_file}"), "Failure message.")
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_should_work_with_corrupted_to_fields
|
96
|
+
message = CarterdteSmtpFilter::Message.new File.open("./test/fixtures/to_in_brackets.eml", "rb").read
|
97
|
+
message.return_email
|
98
|
+
assert_equal(message.response.string.split(/\s+/).last, message.return_qid)
|
99
|
+
end
|
100
|
+
|
95
101
|
|
96
102
|
end
|
data/test/test_smtp_server.rb
CHANGED
@@ -21,22 +21,22 @@ class TestSmtpServer < Minitest::Test
|
|
21
21
|
@return_stmp.stop
|
22
22
|
end
|
23
23
|
|
24
|
-
def test_carterdte_smtp_filter_should_accept_mail
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_return_email_to_postfix
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_accept_email_with_attachments
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
24
|
+
# def test_carterdte_smtp_filter_should_accept_mail
|
25
|
+
# mail = Enviacorreo.new(port: CarterdteSmtpFilter::Config::bind_port)
|
26
|
+
# assert(mail.send, "Failure message.")
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def test_should_return_email_to_postfix
|
30
|
+
# mail = Enviacorreo.new(port: CarterdteSmtpFilter::Config::bind_port)
|
31
|
+
# mail.send
|
32
|
+
# return_email = Mail.read "./test/tmp/returnmail"
|
33
|
+
# assert_equal("DTE", return_email.subject)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# def test_should_accept_email_with_attachments
|
37
|
+
# xml_file = "./test/fixtures/envio_dte_33.xml"
|
38
|
+
# mail = Enviacorreo.new(port: CarterdteSmtpFilter::Config::bind_port, subject: "DTE Attachment", attachment_path: xml_file)
|
39
|
+
# assert(mail.send, "Failure message.")
|
40
|
+
# end
|
41
41
|
|
42
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carterdte_smtp_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.
|
4
|
+
version: 0.0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Bruna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- test/fixtures/mail_with_multiple_attachments.eml
|
247
247
|
- test/fixtures/recepcion_dte_33.xml
|
248
248
|
- test/fixtures/resultado_revision_sii.xml
|
249
|
+
- test/fixtures/to_in_brackets.eml
|
249
250
|
- test/test_api_client.rb
|
250
251
|
- test/test_config.rb
|
251
252
|
- test/test_dte.rb
|
@@ -293,6 +294,7 @@ test_files:
|
|
293
294
|
- test/fixtures/mail_with_multiple_attachments.eml
|
294
295
|
- test/fixtures/recepcion_dte_33.xml
|
295
296
|
- test/fixtures/resultado_revision_sii.xml
|
297
|
+
- test/fixtures/to_in_brackets.eml
|
296
298
|
- test/test_api_client.rb
|
297
299
|
- test/test_config.rb
|
298
300
|
- test/test_dte.rb
|