bbmb 2.0.3 → 2.0.4

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: eaa30df636673ef2b0750209b94e560b321b1003
4
- data.tar.gz: 722f5f6e81069348fd13ccfe66bca2baeda41030
3
+ metadata.gz: 99f53619764278010c43b1ce96b01da6110c1102
4
+ data.tar.gz: 4ea021144c1d8eb96b5c9041e8c6dfb27c2a3b40
5
5
  SHA512:
6
- metadata.gz: 6a18a4776e43b0532aa0d7f453fad64c9a17a586fe36d4c9001c34ccf8a848017ed71152c8bdf329794406c375d06cd5d5a2fbb3e1559b7b920e96ad4afaa5bb
7
- data.tar.gz: 34b1eb5c2a44ec0c04d1f2cad8d9c5db9044cafe3ce7abcbd902e67a2b1214e2e513a4c57df5a96adb1146c3fae033dc22c141e2fa12c8bd1c4727e3804d6cf9
6
+ metadata.gz: fd9c1e936e5f436281c0ffdd4fbcdcd95a5a2576a29506f4f07169c71d9fa212e75de70f5c09810dbb60afed3041a6d2afa7ffa5abee164e6996a553827c2ef8
7
+ data.tar.gz: 8fdb5702e160bc11111bedcdacbec1e9faf9bfa61d9ffad53c12b2ae6832757073da0df6a3159a18941e69a70565d12a76a1585edf11b7552c2462bd4ad18e37
@@ -1,3 +1,8 @@
1
+ === 2.0.4 / 20.06.2016
2
+
3
+ * Use gem 'mail' to send e-mails
4
+ * Added config.mail_suppress_sending
5
+
1
6
  === 2.0.3 / 08.06.2016
2
7
 
3
8
  * Added a DEFAULT_FLAVOR sandoz to work without rockit
@@ -5,7 +5,7 @@ require 'drb'
5
5
  require 'sbsm/drb'
6
6
  require 'bbmb'
7
7
  require 'bbmb/config'
8
- require 'encoding/character/utf-8'
8
+ require 'bbmb/util/invoicer'
9
9
  require 'readline'
10
10
  include Readline
11
11
 
data/bin/bbmbd CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $KCODE = 'u'
4
-
5
3
  $: << File.expand_path('../lib', File.dirname(__FILE__))
6
4
 
7
5
  require 'drb'
@@ -9,8 +7,6 @@ require 'logger'
9
7
  require 'ydim/invoice'
10
8
  require 'bbmb/config'
11
9
  require 'bbmb/util/server'
12
- require 'bbmb/util/server'
13
- require 'pp'
14
10
 
15
11
  module BBMB
16
12
  @config.load_files.each { |local|
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
3
+
4
+ require 'drb'
5
+ require 'logger'
6
+ require 'ydim/invoice'
7
+ require 'bbmb/config'
8
+ require 'bbmb/util/server'
9
+
10
+ module BBMB
11
+ @config.load_files.each { |local|
12
+ require local
13
+ }
14
+ require File.join('bbmb', 'persistence', @config.persistence)
15
+ case @config.persistence
16
+ when 'odba'
17
+ DRb.install_id_conv ODBA::DRbIdConv.new
18
+ @persistence = BBMB::Persistence::ODBA
19
+ end
20
+
21
+ log_file = @config.log_file
22
+ if(log_file.is_a?(String))
23
+ FileUtils.mkdir_p(File.dirname(log_file))
24
+ log_file = File.open(log_file, 'a')
25
+ at_exit { log_file.close }
26
+ end
27
+ @logger = Logger.new(log_file)
28
+ @logger.level = Logger.const_get(@config.log_level)
29
+ @logger.debug('config') { @config.pretty_inspect }
30
+
31
+ VERSION = `git rev-parse HEAD`
32
+
33
+ @auth = DRb::DRbObject.new(nil, @config.auth_url)
34
+
35
+ begin
36
+ @server = BBMB::Util::Server.new(@persistence)
37
+ @server.extend(DRbUndumped)
38
+ puts "#{Time.now}: Calling update"
39
+ @server.update
40
+ puts "#{Time.now}: Finished update"
41
+ rescue Exception => error
42
+ @logger.error('fatal') { error }
43
+ raise
44
+ end
45
+ end
@@ -61,6 +61,7 @@ module BBMB
61
61
  'load_files' => ['bbmb/util/csv_importer'],
62
62
  'log_file' => STDERR,
63
63
  'log_level' => 'INFO',
64
+ 'mail_suppress_sending' => false,
64
65
  'mail_confirm_body' => nil,
65
66
  'mail_confirm_cc' => [],
66
67
  'mail_confirm_from' => 'confirm.test@bbmb.ch',
@@ -84,6 +85,7 @@ module BBMB
84
85
  'server_url' => 'druby://localhost:12000',
85
86
  'session_timeout' => 3600,
86
87
  'smtp_authtype' => nil,
88
+ 'smtp_domain' => 'localdomain',
87
89
  'smtp_helo' => 'localhost.localdomain',
88
90
  'smtp_pass' => nil,
89
91
  'smtp_port' => 25,
@@ -2,11 +2,9 @@
2
2
  # Util::Mail -- bbmb.ch -- 19.11.2012 -- yasaka@ywesee.com
3
3
  # Util::Mail -- bbmb.ch -- 27.09.2006 -- hwyss@ywesee.com
4
4
 
5
+ require 'mail'
5
6
  require 'bbmb/config'
6
- require 'net/smtp'
7
- require 'rmail'
8
7
  require 'pp'
9
- require 'bbmb/util/smtp_tls'
10
8
 
11
9
  module BBMB
12
10
  module Util
@@ -14,62 +12,77 @@ module Mail
14
12
  def Mail.notify_confirmation_error(order)
15
13
  config = BBMB.config
16
14
  if to = config.confirm_error_to
17
- header, message = setup
18
15
  customer = order.customer
19
- from = header.from = config.confirm_error_from
20
- header.to = to
21
- cc = header.cc = config.confirm_error_cc
22
- header.subject = config.confirm_error_subject % customer.customer_id
23
- message.body = config.confirm_error_body % customer.customer_id
24
- Mail.sendmail message, from, to, cc
16
+ from = config.confirm_error_from
17
+ cc = config.confirm_error_cc
18
+ subject = config.confirm_error_subject % customer.customer_id
19
+ body = config.confirm_error_body % customer.customer_id
20
+ Mail.sendmail body, subject, from, to, cc
25
21
  end
26
22
  end
27
23
  def Mail.notify_debug(subject, body)
28
- header, message = setup
29
24
  config = BBMB.config
30
- from = header.from = config.mail_order_from
31
- to = header.to = config.error_recipients
32
- header.subject = sprintf "%s: %s", BBMB.config.name, subject
33
- message.body = body
34
- Mail.sendmail(message, from, to)
25
+ from = config.mail_order_from
26
+ to = config.error_recipients
27
+ subject = sprintf "%s: %s", BBMB.config.name, subject
28
+ Mail.sendmail(body, subject, from, to)
35
29
  end
36
30
  def Mail.notify_error(error)
37
- header, message = setup
38
31
  config = BBMB.config
39
- from = header.from = config.mail_order_from
40
- to = header.to = config.error_recipients
41
- header.subject = sprintf "%s: %s", BBMB.config.name, error.message
42
- message.body = [ error.class, error.message,
43
- error.backtrace.pretty_inspect ].join("\n")
44
- Mail.sendmail(message, from, to)
32
+ from = config.mail_order_from
33
+ to = config.error_recipients
34
+ subject = sprintf "%s: %s", BBMB.config.name, error.message
35
+ body = [ error.class, error.message,
36
+ error.backtrace.pretty_inspect ].join("\n")
37
+ Mail.sendmail(body, subject, from, to)
45
38
  end
46
39
  def Mail.notify_inject_error(order, opts={})
47
40
  config = BBMB.config
48
41
  if to = config.inject_error_to
49
42
  customer = order.customer
50
- header, message = setup
51
- from = header.from = config.inject_error_from
52
- header.to = to
53
- cc = header.cc = config.inject_error_cc
54
- header.subject = config.inject_error_subject % [
43
+ from = config.inject_error_from
44
+ cc = config.inject_error_cc
45
+ subject = config.inject_error_subject % [
55
46
  order.order_id,
56
47
  opts[:customer_name] || customer.customer_id,
57
48
  ]
58
- message.body = config.inject_error_body % [
49
+ body = config.inject_error_body % [
59
50
  opts[:customer_name] || customer.customer_id,
60
51
  order.commit_time.strftime('%d.%m.%Y %H:%M:%S'),
61
52
  customer.customer_id,
62
53
  ]
63
- Mail.sendmail message, from, to, cc
54
+ Mail.sendmail body, subject, from, to, cc
64
55
  end
65
56
  end
66
- def Mail.sendmail(message, from, to, cc=[])
57
+ def Mail.sendmail(my_body, my_subject, from_addr, to_addr, cc_addrs=[], my_reply_to = nil)
67
58
  config = BBMB.config
68
- Net::SMTP.start(config.smtp_server, config.smtp_port, config.smtp_helo,
69
- config.smtp_user, config.smtp_pass,
70
- config.smtp_authtype) { |smtp|
71
- smtp.sendmail(message.to_s, from, [to, cc].flatten.compact)
72
- }
59
+ if config.mail_suppress_sending
60
+ puts "#{__FILE__}:#{__LINE__} Suppress sending mail with subject: #{my_subject}"
61
+ puts " from #{from_addr} to: #{to_addr} cc: #{cc_addrs} reply_to: #{my_reply_to}"
62
+
63
+ ::Mail.defaults do delivery_method :test end
64
+ else
65
+ puts "Mail.sendmail #{config.smtp_server} #{config.smtp_port} #{config.smtp_helo} smtp_user: #{ config.smtp_user} #{ config.smtp_pass} #{ config.smtp_authtype}"
66
+ puts "Mail.sendmail from #{from_addr} to #{to_addr} cc #{cc_addrs} message: #{my_body.class}"
67
+ ::Mail.defaults do
68
+ options = { :address => config.smtp_server,
69
+ :port => config.smtp_port,
70
+ :domain => config.smtp_domain,
71
+ :user_name => config.smtp_user,
72
+ :password => config.smtp_pass,
73
+ :authentication => 'plain',
74
+ :enable_starttls_auto => true }
75
+ delivery_method :smtp, options
76
+ end
77
+ end
78
+ ::Mail.deliver do
79
+ from from_addr
80
+ to to_addr
81
+ cc cc_addrs
82
+ reply_to (my_reply_to ? my_reply_to : from_addr)
83
+ subject my_subject
84
+ body my_body
85
+ end
73
86
  end
74
87
  def Mail.send_confirmation(order)
75
88
  config = BBMB.config
@@ -92,50 +105,28 @@ module Mail
92
105
  end
93
106
  end
94
107
 
95
- header, message = setup
96
- from = header.from = config.mail_confirm_from
97
- header.to = to
98
- header.subject = config.mail_confirm_subject % order.order_id
99
- header.add('Message-ID', sprintf('<%s@%s>', order.order_id,
100
- from.tr('@', '.')))
101
- header.add('Reply-To', reply_to)
102
- message.body = sprintf body, *parts
108
+ from = config.mail_confirm_from
109
+ subject = config.mail_confirm_subject % order.order_id
110
+ body = sprintf *parts
103
111
 
104
- Mail.sendmail(message, from, to, config.mail_confirm_cc)
112
+ Mail.sendmail(body, subject, from, to, config.mail_confirm_cc, reply_to)
105
113
  end
106
114
  def Mail.send_order(order)
107
- header, message = setup
108
115
  config = BBMB.config
109
- from = header.from = config.mail_order_from
110
- to = header.to = config.mail_order_to
111
- cc = header.cc = config.mail_order_cc
112
- header.subject = config.mail_order_subject % order.order_id
113
- header.add('Message-ID', sprintf('<%s@%s>', order.order_id,
114
- from.tr('@', '.')))
115
- message.body = order.to_target_format
116
-
117
- Mail.sendmail(message, from, to, cc)
116
+ from = config.mail_order_from
117
+ to = config.mail_order_to
118
+ cc = config.mail_order_cc
119
+ subject = config.mail_order_subject % order.order_id
120
+ body = order.to_target_format
121
+ Mail.sendmail(body, subject, from, to, cc)
118
122
  end
119
123
  def Mail.send_request(email, organisation, body)
120
- header, message = setup
121
124
  config = BBMB.config
122
- from = header.from = config.mail_request_from
123
- to = header.to = config.mail_request_to
124
- cc = header.cc = config.mail_request_cc
125
- header.subject = config.mail_request_subject % organisation
126
- header.add('Reply-To', email)
127
- message.body = body
128
- Mail.sendmail(message, from, to, cc)
129
- end
130
- def Mail.setup
131
- message = RMail::Message.new
132
- header = message.header
133
- header.add('Date', Time.now.rfc822)
134
- header.add('Mime-Version', '1.0')
135
- header.add('User-Agent', BBMB.config.name)
136
- header.add('Content-Type', 'text/plain', nil, 'charset' => 'utf-8')
137
- header.add('Content-Disposition', 'inline')
138
- [header, message]
125
+ from = config.mail_request_from
126
+ to = config.mail_request_to
127
+ cc = config.mail_request_cc
128
+ subject = config.mail_request_subject % organisation
129
+ Mail.sendmail("", subject, from, to, cc, email)
139
130
  end
140
131
  end
141
132
  end
@@ -8,13 +8,15 @@ require 'bbmb/html/util/validator'
8
8
  require 'bbmb/util/invoicer'
9
9
  require 'bbmb/util/mail'
10
10
  require 'bbmb/util/updater'
11
+ require 'bbmb/model/order' # needed to be enable to invoice later
12
+ require 'bbmb/model/customer'
11
13
  require 'date'
12
14
  require 'sbsm/drbserver'
13
15
 
14
16
  module BBMB
15
17
  module Util
16
18
  class Server < SBSM::DRbServer
17
- ENABLE_ADMIN = true
19
+ ENABLE_ADMIN = true
18
20
  SESSION = Html::Util::Session
19
21
  VALIDATOR = Html::Util::Validator
20
22
  attr_reader :updater
@@ -87,6 +89,7 @@ module BBMB
87
89
  }
88
90
  end
89
91
  def run_invoicer
92
+ BBMB.logger.debug("run_invoicer starting")
90
93
  @invoicer ||= Thread.new {
91
94
  Thread.current.abort_on_exception = true
92
95
  loop {
@@ -96,11 +99,13 @@ module BBMB
96
99
  now = Time.now
97
100
  at = Time.local(day.year, day.month)
98
101
  secs = at - now
99
- BBMB.logger.debug("invoicer") {
102
+ BBMB.logger.debug("invoicer") {
100
103
  "sleeping %.2f seconds" % secs
101
104
  }
102
105
  sleep(secs)
106
+ BBMB.logger.debug("invoice starting")
103
107
  invoice(start...at)
108
+ BBMB.logger.debug("invoice finished")
104
109
  }
105
110
  }
106
111
  end
@@ -115,11 +120,11 @@ module BBMB
115
120
  at = Time.local(day.year, day.month, day.day,
116
121
  BBMB.config.update_hour)
117
122
  secs = at - now
118
- BBMB.logger.debug("updater") {
119
- "sleeping %.2f seconds" % secs
120
- }
123
+ BBMB.logger.debug("updater") { "sleeping %.2f seconds" % secs }
121
124
  sleep(secs)
125
+ BBMB.logger.debug("update starting")
122
126
  update
127
+ BBMB.logger.debug("update finished")
123
128
  }
124
129
  }
125
130
  end
@@ -2,5 +2,5 @@
2
2
  # Bbmb -- bbmb.ch -- 17.12.2019 -- zdavatz@ywesee.com
3
3
 
4
4
  module BBMB
5
- VERSION = '2.0.3'
5
+ VERSION = '2.0.4'
6
6
  end
@@ -10,25 +10,40 @@ require 'bbmb/util/mail'
10
10
  module BBMB
11
11
  module Util
12
12
  class TestMail < Minitest::Test
13
+ SendRealMail = false
14
+ if SendRealMail
15
+ TestRecipient = 'ngiger@ywesee.com'
16
+ else
17
+ TestRecipient = 'to.test@bbmb.ch'
18
+ end
13
19
  include FlexMock::TestCase
14
20
  def setup_config
15
21
  config = BBMB.config
16
- config.error_recipients = ['to.test@bbmb.ch']
22
+ config.mail_suppress_sending = true
23
+ config.error_recipients = [TestRecipient]
17
24
  config.mail_order_from = 'from.test@bbmb.ch'
18
- config.mail_order_to = 'to.test@bbmb.ch'
19
- config.mail_order_cc = 'cc.test@bbmb.ch'
25
+ config.mail_order_to = TestRecipient
20
26
  config.mail_order_subject = 'order %s'
21
27
  config.mail_request_from = 'from.request.test@bbmb.ch'
22
28
  config.mail_request_to = 'to.request.test@bbmb.ch'
23
29
  config.mail_request_cc = 'cc.request.test@bbmb.ch'
24
30
  config.mail_request_subject = 'Request %s'
25
31
  config.name = 'Application/User Agent'
26
- config.smtp_authtype = :plain
27
- config.smtp_helo = 'helo.domain'
28
32
  config.smtp_pass = 'secret'
29
33
  config.smtp_port = 25
30
34
  config.smtp_server = 'mail.test.com'
31
35
  config.smtp_user = 'user'
36
+ if SendRealMail
37
+ config.mail_suppress_sending = false
38
+ config.mail_order_cc = 'ngiger@ywesee.com'
39
+ config.mail_order_cc = 'ngiger@ywesee.com'
40
+ config.smtp_server = 'smtp.gmail.com'
41
+ config.smtp_domain = 'ywesee.com'
42
+ config.smtp_user = 'ngiger@ywesee.com'
43
+ config.smtp_pass = 'topsecret'
44
+ config.smtp_port = 587
45
+ end
46
+
32
47
  config.mail_confirm_reply_to = 'replyto-test@bbmb.ch'
33
48
  config.mail_confirm_from = 'from-test@bbmb.ch'
34
49
  config.mail_confirm_cc = []
@@ -63,8 +78,8 @@ Totale dell'ordine incl. %10.2f
63
78
  "%3i x %-36s à %7.2f, total %10.2f",
64
79
  "%3i x %-36s a %7.2f, totale %10.2f",
65
80
  ]
66
- config.inject_error_to = 'to.test@bbmb.ch'
67
- config.confirm_error_to = 'to.test@bbmb.ch'
81
+ config.inject_error_to = TestRecipient
82
+ config.confirm_error_to = TestRecipient
68
83
  config
69
84
  end
70
85
  def test_inject_error
@@ -75,39 +90,26 @@ Totale dell'ordine incl. %10.2f
75
90
  order.should_receive(:customer).and_return(customer)
76
91
  order.should_receive(:order_id).and_return('12345678-90')
77
92
  order.should_receive(:commit_time).and_return Time.local(2009, 8, 7, 11, 14, 4)
78
- smtp = flexmock('smtp')
79
- flexstub(Net::SMTP).should_receive(:start).and_return {
80
- |srv, port, helo, user, pass, type, block|
81
- assert_equal('mail.test.com', srv)
82
- assert_equal(25, port)
83
- assert_equal('helo.domain', helo)
84
- assert_equal('user', user)
85
- assert_equal('secret', pass)
86
- assert_equal(:plain, type)
87
- block.call(smtp)
88
- }
89
93
  headers = <<-EOS
90
94
  Mime-Version: 1.0
91
95
  User-Agent: Application/User Agent
92
96
  Content-Type: text/plain; charset="utf-8"
93
97
  Content-Disposition: inline
94
98
  From: errors.test@bbmb.ch
95
- To: to.test@bbmb.ch
99
+ To: #{TestRecipient}
96
100
  Cc:
97
101
  Subject: Order 12345678-90 with missing customer: Pharmacy Health
98
102
  EOS
99
103
  body = <<-EOS
100
104
  The order Pharmacy Health, committed on 07.08.2009 11:14:04, assigned to the unknown customer: 12345678
101
105
  EOS
102
- smtp.should_receive(:sendmail).and_return { |message, from, recipients|
103
- assert(message.include?(headers),
104
- "missing headers:\n#{headers}\nin message:\n#{message}")
105
- assert(message.include?(body),
106
- "missing body:\n#{body}\nin message:\n#{message}")
107
- assert_equal('errors.test@bbmb.ch', from)
108
- assert_equal(['to.test@bbmb.ch'], recipients)
109
- }
106
+ saved_length = ::Mail::TestMailer.deliveries.length
110
107
  Mail.notify_inject_error(order, :customer_name => 'Pharmacy Health')
108
+ unless SendRealMail
109
+ assert_equal(saved_length + 1, ::Mail::TestMailer.deliveries.length)
110
+ assert_equal(['errors.test@bbmb.ch'], ::Mail::TestMailer.deliveries.last.from)
111
+ assert(body.match ::Mail::TestMailer.deliveries.last.body.raw_source)
112
+ end
111
113
  end
112
114
  def test_confirm_error
113
115
  config = setup_config
@@ -134,7 +136,7 @@ User-Agent: Application/User Agent
134
136
  Content-Type: text/plain; charset="utf-8"
135
137
  Content-Disposition: inline
136
138
  From: errors.test@bbmb.ch
137
- To: to.test@bbmb.ch
139
+ To: #{TestRecipient}
138
140
  Cc:
139
141
  Subject: Customer 12345678 without email address
140
142
  EOS
@@ -147,7 +149,7 @@ Customer 12345678 does not have an email address configured
147
149
  assert(message.include?(body),
148
150
  "missing body:\n#{body}\nin message:\n#{message}")
149
151
  assert_equal('errors.test@bbmb.ch', from)
150
- assert_equal(['to.test@bbmb.ch'], recipients)
152
+ assert_equal([TestRecipient], recipients)
151
153
  }
152
154
  Mail.notify_confirmation_error(order)
153
155
  end
@@ -170,7 +172,7 @@ User-Agent: Application/User Agent
170
172
  Content-Type: text/plain; charset="utf-8"
171
173
  Content-Disposition: inline
172
174
  From: from.test@bbmb.ch
173
- To: to.test@bbmb.ch
175
+ To: #{TestRecipient}
174
176
  Subject: Application/User Agent: error-message
175
177
  EOS
176
178
  body = <<-EOS
@@ -183,7 +185,7 @@ error-message
183
185
  assert(message.include?(body),
184
186
  "missing body:\n#{body}\nin message:\n#{message}")
185
187
  assert_equal('from.test@bbmb.ch', from)
186
- assert_equal(['to.test@bbmb.ch'], recipients)
188
+ assert_equal([TestRecipient], recipients)
187
189
  }
188
190
  Mail.notify_error(RuntimeError.new("error-message"))
189
191
  end
@@ -210,7 +212,7 @@ User-Agent: Application/User Agent
210
212
  Content-Type: text/plain; charset="utf-8"
211
213
  Content-Disposition: inline
212
214
  From: from.test@bbmb.ch
213
- To: to.test@bbmb.ch
215
+ To: #{TestRecipient}
214
216
  Cc: cc.test@bbmb.ch
215
217
  Subject: order order-id
216
218
  Message-ID: <order-id@from.test.bbmb.ch>
@@ -226,7 +228,7 @@ i2-data
226
228
  #assert(message.include?(attachment),
227
229
  #"missing attachment:\n#{attachment}\nin message:\n#{message}")
228
230
  assert_equal('from.test@bbmb.ch', from)
229
- assert_equal(['to.test@bbmb.ch', 'cc.test@bbmb.ch'], recipients)
231
+ assert_equal([TestRecipient, 'cc.test@bbmb.ch'], recipients)
230
232
  }
231
233
  Mail.send_order(order)
232
234
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbmb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
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-08 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: odba
@@ -321,9 +321,9 @@ dependencies:
321
321
  description: ywesee distributed invoice manager. A Ruby gem
322
322
  email: mhatakeyama@ywesee.com, zdavatz@ywesee.com, ngiger@ywesee.com
323
323
  executables:
324
- - admin
324
+ - bbmb_admin
325
325
  - bbmbd
326
- - migrate_bbmb_to_utf_8
326
+ - update_articles_and_products
327
327
  extensions: []
328
328
  extra_rdoc_files: []
329
329
  files:
@@ -337,9 +337,9 @@ files:
337
337
  - Rakefile
338
338
  - bbmb.gemspec
339
339
  - bbmb.jpeg
340
- - bin/admin
340
+ - bin/bbmb_admin
341
341
  - bin/bbmbd
342
- - bin/migrate_bbmb_to_utf_8
342
+ - bin/update_articles_and_products
343
343
  - lib/bbmb.rb
344
344
  - lib/bbmb/config.rb
345
345
  - lib/bbmb/html/state/change_password.rb
@@ -407,7 +407,6 @@ files:
407
407
  - lib/bbmb/util/password_generator.rb
408
408
  - lib/bbmb/util/polling_manager.rb
409
409
  - lib/bbmb/util/server.rb
410
- - lib/bbmb/util/smtp_tls.rb
411
410
  - lib/bbmb/util/target_dir.rb
412
411
  - lib/bbmb/util/transfer_dat.rb
413
412
  - lib/bbmb/util/updater.rb
@@ -1,236 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- puts "#{Time.now}: Loading #{__FILE__}"
4
- STDOUT.sync = true
5
-
6
- require 'syck'
7
-
8
- here = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'lib'))
9
- $: << here
10
- require 'logger'
11
- require 'needle'
12
- require 'odba/id_server'
13
- require 'rrba/server'
14
- require 'yus/entity'
15
- require 'yus/privilege'
16
- require 'ydim/autoinvoicer'
17
- require 'ydim/client'
18
- require 'ydim/currency_converter'
19
- require 'ydim/currency_updater'
20
- require 'ydim/factory'
21
- require 'ydim/root_user'
22
- require 'ydim/server'
23
- require 'ydim/util'
24
- require 'odba/connection_pool'
25
- require 'odba/drbwrapper'
26
- require 'ydim/odba'
27
- require 'ydim/root_session'
28
- require 'ydim/root_user'
29
-
30
- require File.join(here, 'bbmb/persistence/odba.rb')
31
-
32
- module YDIM
33
- class Server
34
- # http://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8
35
- # https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences
36
- def sanitize_utf8(string)
37
- return nil if string.nil?
38
- # return string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
39
- return string if string.valid_encoding?
40
- if string.force_encoding(Encoding::ISO_8859_1).valid_encoding?
41
- string.force_encoding(Encoding::ISO_8859_1).clone.encode(Encoding::UTF_8)
42
- else
43
- string.chars.select { |c| c.valid_encoding? }.join
44
- end
45
- end
46
- def _migrate_to_utf8 queue, table, opts={}
47
- while obj = queue.shift do
48
- if obj.is_a?(Numeric)
49
- begin
50
- obj = ODBA.cache.fetch obj
51
- rescue ODBA::OdbaError
52
- return
53
- end
54
- else
55
- obj = obj.odba_instance
56
- end
57
- puts " #{__LINE__}: Migrating #{obj.class} #{obj.to_s}" if $VERBOSE
58
- return unless obj
59
- _migrate_obj_to_utf8 obj, queue, table, opts
60
- obj.odba_store unless obj.odba_unsaved?
61
- end
62
- end
63
- def _migrate_obj_to_utf8 obj, queue, table, opts={}
64
- obj.instance_variables.each do |name|
65
- child = obj.instance_variable_get name
66
- if child.respond_to?(:odba_unsaved?) && !child.odba_unsaved? \
67
- && obj.respond_to?(:odba_serializables) \
68
- && obj.odba_serializables.include?(name)
69
- child.instance_variable_set '@odba_persistent', nil
70
- end
71
- child = _migrate_child_to_utf8 child, queue, table, opts
72
- obj.instance_variable_set name, child
73
- end
74
- if obj.is_a?(Array)
75
- obj.collect! do |child|
76
- _migrate_child_to_utf8 child, queue, table, opts
77
- end
78
- end
79
- if obj.is_a?(Hash)
80
- obj.dup.each do |key, child|
81
- obj.store key, _migrate_child_to_utf8(child, queue, table, opts)
82
- end
83
- end
84
- obj
85
- end
86
- def _migrate_child_to_utf8 child, queue, table, opts={}
87
- @serialized ||= {}
88
- case child
89
- when ODBA::Persistable, ODBA::Stub
90
- if child = child.odba_instance
91
- if child.odba_unsaved?
92
- _migrate_to_utf8 [child], table, opts
93
- elsif opts[:all]
94
- odba_id = child.odba_id
95
- unless table[odba_id]
96
- table.store odba_id, true
97
- queue.push odba_id
98
- end
99
- end
100
- end
101
- when String
102
- old = child.encoding
103
- if ( child.encoding != Encoding::UTF_8 && child.force_encoding(Encoding::ISO_8859_1).valid_encoding? ) ||
104
- ( child.encoding == Encoding::UTF_8 && !child.valid_encoding? )
105
- child = child.force_encoding(Encoding::ISO_8859_1).clone.encode(Encoding::UTF_8)
106
- puts "force_encoding from ISO_8859_1 #{old}. is now #{child}"
107
- end
108
- case child.encoding.to_s
109
- when /ASCII-8BIT|US-ASCII/
110
- # nothing todo
111
- when /UTF-8/
112
- puts "UTF-8: for #{child.to_s}" if $VERBOSE
113
- child = sanitize_utf8(child)
114
- when /ISO-8859-1/i
115
- child = sanitize_utf8(child)
116
- # child = child.force_encoding('UTF-8')
117
- puts "force_encoding from #{old}. is now #{child}"
118
- else
119
- puts "Unhandeled encoding #{child.encoding}"
120
- # child = child.force_encoding
121
- end
122
- when
123
- Yus::Entity,
124
- Yus::Privilege,
125
- YDIM::AutoInvoice,
126
- YDIM::Debitor,
127
- YDIM::Debitor,
128
- YDIM::Invoice,
129
- YDIM::Invoice::Info,
130
- YDIM::Item
131
- child = _migrate_obj_to_utf8 child, queue, table, opts
132
- when Float, Fixnum, TrueClass, FalseClass, NilClass,
133
- Symbol, Time, Date, DateTime,
134
- YDIM::Factory,
135
- YDIM::CurrencyConverter,
136
- YDIM::MobileCurrencyConverter
137
- # do nothing
138
- else
139
- @ignored ||= {}
140
- unless @ignored[child.class]
141
- @ignored.store child.class, true
142
- warn "ignoring #{child.class}"
143
- end
144
- end
145
- child
146
- rescue SystemStackError
147
- puts child.class
148
- raise
149
- end
150
- end
151
- end
152
-
153
- @logger = Logger.new('/tmp/ migrate_to_utf8.log')
154
- @logger.level = Logger::DEBUG
155
- config = YDIM::Server.config
156
- module Yus
157
- class Entity
158
- include ODBA::Persistable
159
- class << self
160
- alias :all :odba_extent
161
- end
162
- end
163
- class Privilege
164
- include ODBA::Persistable
165
- class << self
166
- alias :all :odba_extent
167
- end
168
- end
169
- end
170
- module BBMB
171
- module Model
172
- class Order
173
- include ODBA::Persistable
174
- class << self
175
- alias :all :odba_extent
176
- end
177
- end
178
- class ProductInfo
179
- include ODBA::Persistable
180
- class << self
181
- alias :all :odba_extent
182
- end
183
- end
184
- class Customer
185
- include ODBA::Persistable
186
- class << self
187
- alias :all :odba_extent
188
- end
189
- end
190
- class Promotion
191
- include ODBA::Persistable
192
- class << self
193
- alias :all :odba_extent
194
- end
195
- end
196
- class Quota
197
- include ODBA::Persistable
198
- class << self
199
- alias :all :odba_extent
200
- end
201
- end
202
- class Subject
203
- include ODBA::Persistable
204
- class << self
205
- alias :all :odba_extent
206
- end
207
- end
208
- end
209
- end
210
-
211
- ODBA.storage.dbi = ODBA::ConnectionPool.new(config.db_driver_url,
212
- config.db_user, config.db_auth, :client_encoding => 'LATIN1')
213
- ODBA.cache.setup
214
- DRb.install_id_conv ODBA::DRbIdConv.new
215
-
216
- @server = YDIM::Server.new(config, @logger)
217
- puts "DB used is #{config.db_name} user: #{config.db_user} auth: #{config.db_auth}"
218
- @server.extend(DRbUndumped)
219
- session = YDIM::RootSession.new(YDIM::RootUser.new(1))
220
- session.serv = @server
221
- { # :orders => BBMB::Model::Order.odba_extent,
222
- # :products => BBMB::Model::ProductInfo.odba_extent,
223
- # :customers => BBMB::Model::Customer.odba_extent,
224
- # :promotions => BBMB::Model::Promotion.odba_extent,
225
- # :quota => BBMB::Model::Quota.odba_extent,
226
- # :subject => BBMB::Model::Subject.odba_extent,
227
- :entitites => Yus::Entity.odba_extent,
228
- :privileges => Yus::Privilege.odba_extent,
229
- :debitors => YDIM::Debitor.odba_extent,
230
- :invoices => YDIM::Invoice.odba_extent,
231
- :autoinvoices => YDIM::AutoInvoice.odba_extent,
232
- }.each do |name, to_migrate|
233
- puts "#{Time.now}: Start migrating #{to_migrate.size} #{name}"
234
- @server._migrate_to_utf8(to_migrate, {})
235
- end
236
- puts "#{Time.now}: Finished migrate_to_utf8"
@@ -1,70 +0,0 @@
1
- require "openssl"
2
- require "net/smtp"
3
-
4
- Net::SMTP.class_eval do
5
- private
6
- def do_start(helodomain, user, secret, authtype)
7
- raise IOError, 'SMTP session already started' if @started
8
-
9
- if RUBY_VERSION == '1.8.6'
10
- check_auth_args user, secret, authtype if user or secret
11
- else # > 1.8.7
12
- check_auth_args user, secret if user or secret
13
- end
14
-
15
- sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
16
- @socket = Net::InternetMessageIO.new(sock)
17
- @socket.read_timeout = 60 #@read_timeout
18
- @socket.debug_output = STDERR #@debug_output
19
-
20
- check_response(critical { recv_response() })
21
- do_helo(helodomain)
22
-
23
- raise 'openssl library not installed' unless defined?(OpenSSL)
24
- starttls
25
- ssl = OpenSSL::SSL::SSLSocket.new(sock)
26
- ssl.sync_close = true
27
- ssl.connect
28
- @socket = Net::InternetMessageIO.new(ssl)
29
- @socket.read_timeout = 60 #@read_timeout
30
- @socket.debug_output = STDERR #@debug_output
31
- do_helo(helodomain)
32
-
33
- authenticate user, secret, authtype if user
34
- @started = true
35
- ensure
36
- unless @started
37
- # authentication failed, cancel connection.
38
- @socket.close if not @started and @socket and not @socket.closed?
39
- @socket = nil
40
- end
41
- end
42
-
43
- def do_helo(helodomain)
44
- begin
45
- if @esmtp
46
- ehlo helodomain
47
- else
48
- helo helodomain
49
- end
50
- rescue Net::ProtocolError
51
- if @esmtp
52
- @esmtp = false
53
- @error_occured = false
54
- retry
55
- end
56
- raise
57
- end
58
- end
59
-
60
- def starttls
61
- getok('STARTTLS')
62
- end
63
-
64
- def quit
65
- begin
66
- getok('QUIT')
67
- rescue EOFError
68
- end
69
- end
70
- end