xmlconv 1.0.4 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4976e15c3eb44fd7e1e31c9503a49d929a83b79
4
- data.tar.gz: 251ef9c9450150f7a548c2525adc3f7ce214846b
3
+ metadata.gz: bb9f329fdd7667ecc35ea69858f86af27effca80
4
+ data.tar.gz: 59698a9a9b806498a40eec8023fbef3d140c2ce8
5
5
  SHA512:
6
- metadata.gz: 0d7658887226d0ab9454fa2c58cf30188c40d5e75fdadbce8c34bef8bfa1053c9600550f595c5e0283dcb0a1ce7efdd0b0afa87566eadbc804c3a84ce5b04ffa
7
- data.tar.gz: 14df94d39537bae76704a80ea4b11c8d5315815186d3736a16a28c82e6e2288e9fbfa4386e674eda1a7a7c641d4b70fffa6f551888ba6078d37ee09c86a89a31
6
+ metadata.gz: 4f3c78a411e366c376f4eefff010c1fa591a5fabacd1f30370db15bad1c7024d2fc5a00a93de141eee7a6d41c77a28a600f74841559fd5806782b40c8b9ba93c
7
+ data.tar.gz: 7a382f02bc10df72414b3b622eedace2eef0b92f93c8b1c9a27463c70714c987f0cb2a1b5260bd7ff3cf1d0a048c521c431e10618a93014ff9fee1e2cba3820f
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.0.5 / 21.06.2016
2
+
3
+ * Corrected polling pop3 message. Fixed corresponding test case
4
+
1
5
  === 1.0.4 / 20.06.2016
2
6
 
3
7
  * setup correct smtp delivery if config.smtp_server is given. Works with smtp.gmail.com
@@ -8,7 +8,7 @@ require 'xmlconv/util/destination'
8
8
  require 'xmlconv/util/mail'
9
9
  require 'xmlconv/util/transaction'
10
10
  require 'net/pop'
11
- require 'rmail'
11
+ require 'mail'
12
12
 
13
13
  module XmlConv
14
14
  module Util
@@ -66,35 +66,37 @@ module XmlConv
66
66
  class PopMission < Mission
67
67
  attr_accessor :host, :port, :user, :pass, :content_type
68
68
  def poll(&block)
69
- Net::POP3.start(@host, @port || 110, @user, @pass) { |pop|
70
- pop.each_mail { |mail|
71
- source = mail.pop
69
+ puts "PopMission starts polling host #{@host}:#{@port} u: #{@user} pw: #{@pass}"
70
+ options = {
71
+ :address => @host,
72
+ :port => @port,
73
+ :user_name => @user,
74
+ :password => @pass,
75
+ :enable_ssl => true
76
+ }
77
+ ::Mail.defaults do retriever_method :pop3, options end
78
+ all_mails = ::Mail.delivery_method.is_a?(::Mail::TestMailer) ? ::Mail::TestMailer.deliveries : ::Mail.all
79
+ all_mails.each do |mail|
72
80
  begin
73
- ## work around a bug in RMail::Parser that cannot deal with
74
- ## RFC-2822-compliant CRLF..
75
- source.gsub!(/\r\n/, "\n")
76
- poll_message(RMail::Parser.read(source), &block)
81
+ poll_message(mail, &block)
77
82
  ensure
78
83
  time = Time.now
79
- name = sprintf("%s.%s.%s", @user,
80
- time.strftime("%Y%m%d%H%M%S"), time.usec)
84
+ name = sprintf("%s.%s.%s", @user, time.strftime("%Y%m%d%H%M%S"), time.usec)
81
85
  FileUtils.mkdir_p(@backup_dir)
82
86
  path = File.join(@backup_dir, name)
83
- File.open(path, 'w') { |fh| fh.puts(source) }
84
- mail.delete
87
+ File.open(path, 'w') { |fh| fh.puts(mail) }
88
+ mail.mark_for_delete = true
89
+ # mail.delete # Not necessary with gem mail, as delete_after_find is set to true by default
85
90
  end
86
- }
87
- }
91
+ end
88
92
  end
89
93
  def poll_message(message, &block)
90
94
  if(message.multipart?)
91
- message.each_part { |part|
95
+ message.parts.each do |part|
92
96
  poll_message(part, &block)
93
- }
94
- elsif(@content_type.match(message.header.content_type('text/plain')))
95
- src = message.decode
96
- filtered_transaction(src, sprintf('pop3:%s@%s:%s', @user, @host, @port),
97
- &block)
97
+ end
98
+ elsif(/text\/xml/.match(message.content_type))
99
+ filtered_transaction(message.decoded, sprintf('pop3:%s@%s:%s', @user, @host, @port), &block)
98
100
  end
99
101
  end
100
102
  end
@@ -1,3 +1,3 @@
1
1
  module XmlConv
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
@@ -0,0 +1,74 @@
1
+ Return-Path: <info@xundart.ch>
2
+ Delivered-To:
3
+ Received: (qmail 3820 invoked from network); 23 May 2011 22:08:01 -0000
4
+ Received: from [82.195.225.113] (HELO WEB-WIN-225-113.genotec.ch) (82.195.225.113)
5
+ by mail.ywesee.com (qpsmtpd/0.82) with ESMTP; Tue, 24 May 2011 00:08:01 +0200
6
+ Received: from WEB-WIN-225-113.genotec.ch ([127.0.0.1]) by WEB-WIN-225-113.genotec.ch with Microsoft SMTPSVC(6.0.3790.4675);
7
+ Tue, 24 May 2011 00:07:58 +0200
8
+ From: "=?ISO-8859-1?B?eHVuZGFydCDEcnp0ZW5ldHp3?=
9
+ =?ISO-8859-1?B?ZXJr?=" <info@xundart.ch>
10
+ To: sandoz.xundart@bbmb.ch
11
+ Subject: Bestellung Shop Internet
12
+ Date: Tue, 24 May 2011 00:07:58 +0200
13
+ Message-ID: <20110524-00075891-8728@WEB-WIN-225-113.genotec.ch>
14
+ MIME-Version: 1.0
15
+ Content-Type: multipart/mixed;
16
+ boundary="--=D8581FE41FAB40EE9DE9_16FE_32EC_7C28"
17
+ Return-Path: info@xundart.ch
18
+ X-OriginalArrivalTime: 23 May 2011 22:07:58.0914 (UTC) FILETIME=[E032AA20:01CC1995]
19
+
20
+ ----=D8581FE41FAB40EE9DE9_16FE_32EC_7C28
21
+ Content-Type: text/html;charset="iso-8859-1"
22
+ Content-Transfer-Encoding: 7bit
23
+
24
+ <html><style type=text/css><!-- td {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 11px;} --></style><body><font face=verdana size=2><br><table cellpadding=0 cellspacing=0 border=0><tr><td><br>Dr. med. Andreas Diethelm<br>Wattstrasse 14<br>9240 Uzwil</td></tr></table>
25
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>23.05.2011</td><td width=280>Valsartan Sandoz Filmtabl</td><td width=180>160 mg 98 Stk</td><td width=80>4782465</td><td width=100>7680620390052</td><td width=40 align=right>2</td><td width=50 align=right>80.20</td><td width=70 align=right>160.40</td></tr></table>
26
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>23.05.2011</td><td width=280>Valsartan Sandoz Filmtabl</td><td width=180>80 mg 98 Stk</td><td width=80>4782459</td><td width=100>7680620390038</td><td width=40 align=right>2</td><td width=50 align=right>60.98</td><td width=70 align=right>121.96</td></tr></table>
27
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>23.05.2011</td><td width=280>Amlodipin Sandoz eco Tabl</td><td width=180>5 mg 100 Stk</td><td width=80>3458461</td><td width=100>7680573110042</td><td width=40 align=right>5</td><td width=50 align=right>33.45</td><td width=70 align=right>167.25</td></tr></table>
28
+ <table cellpadding=0 cellspacing=0 border=0><tr><td><br>Dr. med. Patrick Hutter<br>Herrenhofstrasse 36<br>9244 Niederuzwil</td></tr></table>
29
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>20.05.2011</td><td width=280>Co-Valsartan Sandoz Filmtabl</td><td width=180>160/25 mg 28 Stk</td><td width=80>4804304</td><td width=100>7680618740074</td><td width=40 align=right>5</td><td width=50 align=right>24.71</td><td width=70 align=right>123.55</td></tr></table>
30
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>20.05.2011</td><td width=280>Ecofenac CR Retardtabl</td><td width=180>150 mg 30 Stk</td><td width=80>2366107</td><td width=100>7680555130082</td><td width=40 align=right>15</td><td width=50 align=right>17.75</td><td width=70 align=right>266.25</td></tr></table>
31
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>20.05.2011</td><td width=280>Bilol Sandoz Filmtabl</td><td width=180>5 mg 100 Stk</td><td width=80>2324014</td><td width=100>7680540300292</td><td width=40 align=right>5</td><td width=50 align=right>21.76</td><td width=70 align=right>108.80</td></tr></table>
32
+ <table cellpadding=0 cellspacing=0 border=0><tr><td><br>Dr. med. Peter Schudel<br>Marktstrasse 3<br>9244 Niederuzwil</td></tr></table>
33
+ <table cellpadding=0 cellspacing=0 border=0><tr><td width=80>23.05.2011</td><td width=280>Ecofenac</td><td width=180>Lipogel 1% 100 g Tube</td><td width=80>2128827</td><td width=100>7680542960296</td><td width=40 align=right>2</td><td width=50 align=right>6.33</td><td width=70 align=right>12.66</td></tr></table>
34
+ <table width=500 cellpadding=0 cellspacing=0 border=0><tr><td><br>xundart AG<br><a href=mailto:info@xundart.ch>info@xundart.ch</a></td></tr></table>
35
+ </font></body></html>
36
+
37
+ ----=D8581FE41FAB40EE9DE9_16FE_32EC_7C28
38
+ Content-Type: text/xml;name="order_69_20110524.xml"
39
+ Content-Transfer-Encoding: base64
40
+ Content-Disposition: attachment;filename="order_69_20110524.xml"
41
+
42
+ PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPGNvbW1hbmRlIHht
43
+ bG5zPSJodHRwOi8vd3d3Lnh1bmRhcnQuY2giIGRhdGU9IjUvMjQvMjAxMSAxMjowNzo1MCBBTSIg
44
+ aWQ9IjY5MjAxMTA1MjQiPg0KPGNvbS1waGFybWEgZWFuPSI3NjAxMDAwMTI4NzA2Ij4NCjxsaXZy
45
+ YWlzb24+PGxhc3QtbmFtZT5Eci4gbWVkLiBBbmRyZWFzIERpZXRoZWxtPC9sYXN0LW5hbWU+PGFk
46
+ ZHJlc3M+PHN0cmVldD5XYXR0c3RyYXNzZSAxNDwvc3RyZWV0Pjx6aXA+OTI0MDwvemlwPjxjaXR5
47
+ PlV6d2lsPC9jaXR5PjwvYWRkcmVzcz48L2xpdnJhaXNvbj4NCjxhcnRpY2xlIGVhbj0iNzY4MDYy
48
+ MDM5MDA1MiIgcGhhcm1hY29kZT0iNDc4MjQ2NSIgcXRlX2ZhY3R1cmU9IjIiPjxkZXNjPlZhbHNh
49
+ cnRhbiBTYW5kb3ogRmlsbXRhYmwgMTYwIG1nIDk4IFN0azwvZGVzYz48L2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M+PC9hcnRpY2xlPg0KPGFydGljbGUg
63
+ ZWFuPSI3NjgwNTQwMzAwMjkyIiBwaGFybWFjb2RlPSIyMzI0MDE0IiBxdGVfZmFjdHVyZT0iNSI+
64
+ PGRlc2M+Qmlsb2wgU2FuZG96IEZpbG10YWJsIDUgbWcgMTAwIFN0azwvZGVzYz48L2FydGljbGU+
65
+ PC9jb20tcGhhcm1hPg0KDQo8Y29tLXBoYXJtYSBlYW49Ijc2MDEwMDAyNjk0NTQiPg0KPGxpdnJh
66
+ aXNvbj48bGFzdC1uYW1lPkRyLiBtZWQuIFBldGVyIFNjaHVkZWw8L2xhc3QtbmFtZT48YWRkcmVz
67
+ cz48c3RyZWV0Pk1hcmt0c3RyYXNzZSAzPC9zdHJlZXQ+PHppcD45MjQ0PC96aXA+PGNpdHk+Tmll
68
+ ZGVydXp3aWw8L2NpdHk+PC9hZGRyZXNzPjwvbGl2cmFpc29uPg0KPGFydGljbGUgZWFuPSI3Njgw
69
+ NTQyOTYwMjk2IiBwaGFybWFjb2RlPSIyMTI4ODI3IiBxdGVfZmFjdHVyZT0iMiI+PGRlc2M+RWNv
70
+ ZmVuYWMgTGlwb2dlbCAxJSAxMDAgZyBUdWJlPC9kZXNjPjwvYXJ0aWNsZT48L2NvbS1waGFybWE+
71
+ DQo8L2NvbW1hbmRlPg0K
72
+
73
+ ----=D8581FE41FAB40EE9DE9_16FE_32EC_7C28--
74
+
@@ -0,0 +1,23 @@
1
+ Date: Wed, 22 Jun 2016 08:51:53 +0200
2
+ From: you@you.com
3
+ To: testuser:@localhost
4
+ Message-ID: <576a3589c4e08_5cd02ac6164170ec22950@ng-tr.mail>
5
+ Mime-Version: 1.0
6
+ Content-Type: multipart/mixed;
7
+ boundary="--==_mimepart_576a3589c331b_5cd02ac6164170ec228e3";
8
+ charset=UTF-8
9
+ Content-Transfer-Encoding: 7bit
10
+
11
+
12
+ ----==_mimepart_576a3589c331b_5cd02ac6164170ec228e3
13
+ Content-Type: text/xml;
14
+ charset=UTF-8
15
+ Content-Transfer-Encoding: 7bit
16
+
17
+ <?xml version="1.0"?>
18
+ <foo>
19
+ <bar/>
20
+ </foo>
21
+
22
+ ----==_mimepart_576a3589c331b_5cd02ac6164170ec228e3--
23
+
@@ -1,11 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Util::TestPollingManager -- xmlconv2 -- 29.06.2004 -- hwyss@ywesee.com
3
-
4
3
  $: << File.expand_path('..', File.dirname(__FILE__))
5
4
  $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
5
 
7
6
  require 'xmlconv/util/polling_manager'
8
- require 'rexml/document'
9
7
  require 'config'
10
8
  require 'mail'
11
9
  require 'minitest/autorun'
@@ -17,6 +15,7 @@ end
17
15
 
18
16
  module XmlConv
19
17
  module Util
18
+ TestData = File.join(File.expand_path('..', File.dirname(__FILE__)), 'data')
20
19
  class TestPollingMission < ::Minitest::Test
21
20
  def setup
22
21
  @mission = PollingMission.new
@@ -124,72 +123,34 @@ module XmlConv
124
123
  FileUtils.rm_r(@datadir)
125
124
  end
126
125
  def test_poll
127
- message = RMail::Message.new
128
- part1 = RMail::Message.new
129
- part1.header.add("content-type", 'text/plain')
130
- part1.body = "some senseless data"
131
- message.add_part(part1)
132
-
133
- part2 = RMail::Message.new
134
- part2.header.add("content-type", 'text/xml', nil,
135
- 'encoding' => 'iso-8859-1')
136
- doc = REXML::Document.new("<foo><bar /></foo>")
137
- part2.body = doc.to_s
138
- message.add_part(part2)
139
-
140
- part3 = RMail::Message.new
141
- part3.header.add("content-type", 'text/plain')
142
- part3.body = "some more senseless data"
143
- message.add_part(part3)
144
-
145
- mail = message.to_s
146
-
147
- @server = Thread.new {
148
- Thread.start(@popserver.accept) do |socket|
149
- socket.puts("+OK")
150
- while line = socket.gets
151
- case line[0,4]
152
- when "USER"
153
- assert_equal("USER testuser\r\n", line)
154
- socket.print("+OK\r\n")
155
- when "PASS"
156
- assert_equal("PASS test\r\n", line)
157
- socket.print("+OK\r\n")
158
- when "STAT"
159
- socket.print("+OK 1 1\r\n")
160
- when "LIST"
161
- socket.print("+OK\r\n")
162
- socket.print("1 #{mail.size}\r\n")
163
- socket.print(".\r\n")
164
- when "RETR"
165
- socket.print("+OK #{mail.size}\r\n")
166
- socket.print(mail)
167
- socket.print("\r\n.\r\n")
168
- when "QUIT"
169
- socket.print("+OK\r\n")
170
- break
171
- else
172
- socket.print("+OK\r\n")
173
- end
174
- end
175
- socket.close
176
- end
177
- }
126
+ options = { :from => 'you@you.com', }
127
+ ::Mail.defaults do delivery_method :test, options end
128
+ mail = ::Mail.read(File.join(TestData, 'simple_email.txt'))
129
+ mail.deliver
130
+ mail = ::Mail.read(File.join(TestData, 'sandoz.xundart@bbmb.ch.20110524001038.928592'))
131
+ mail.deliver
132
+ nr_messages = 2
133
+ assert_equal(nr_messages, ::Mail::TestMailer.deliveries.length)
178
134
  counter = 0
179
- @mission.poll { |transaction|
135
+ @mission.poll do |transaction|
180
136
  counter += 1
181
- assert_instance_of(Util::Transaction, transaction)
182
- assert_equal(doc.to_s, transaction.input)
183
- assert_equal("pop3:testuser@localhost:#{@mission.port}",
184
- transaction.origin)
185
- assert_equal('Reader', transaction.reader)
186
- assert_equal('Writer', transaction.writer)
187
- dest = transaction.destination
188
- assert_instance_of(Util::DestinationHttp, dest)
189
- assert_equal('http://foo.bar.baz:2345', dest.uri.to_s)
190
- }
191
- assert_equal(1, counter,
192
- "poll-block should have been called exactly once")
137
+ assert_instance_of(Util::Transaction, transaction)
138
+ next if /testuser@localhost/.match(transaction.origin)
139
+ expected = %(<?xml version=\"1.0\"?>
140
+ <foo>
141
+ <bar/>
142
+ </foo>
143
+ )
144
+ assert_equal(expected, transaction.input)
145
+ assert_equal("pop3:testuser@localhost:#{@mission.port}",
146
+ transaction.origin)
147
+ assert_equal('Reader', transaction.reader)
148
+ assert_equal('Writer', transaction.writer)
149
+ dest = transaction.destination
150
+ assert_instance_of(Util::DestinationHttp, dest)
151
+ assert_equal('http://foo.bar.baz:2345', dest.uri.to_s)
152
+ end
153
+ assert_equal(nr_messages, counter, "poll-block should have been called exactly #{nr_messages} times")
193
154
  end
194
155
  def teardown
195
156
  @popserver.close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: odba
@@ -398,6 +398,8 @@ files:
398
398
  - readme.md
399
399
  - test/config.rb
400
400
  - test/data/polling.yaml
401
+ - test/data/sandoz.xundart@bbmb.ch.20110524001038.928592
402
+ - test/data/simple_email.txt
401
403
  - test/suite.rb
402
404
  - test/test_i2/address.rb
403
405
  - test/test_i2/date.rb
@@ -452,6 +454,8 @@ summary: xmlconverter, convert XML to flat files
452
454
  test_files:
453
455
  - test/config.rb
454
456
  - test/data/polling.yaml
457
+ - test/data/sandoz.xundart@bbmb.ch.20110524001038.928592
458
+ - test/data/simple_email.txt
455
459
  - test/suite.rb
456
460
  - test/test_i2/address.rb
457
461
  - test/test_i2/date.rb