midi-smtp-server 3.1.2 → 3.2.1

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
  SHA256:
3
- metadata.gz: 0c84077c17fd5b68cffd37292da0e473245f16662041fb9a17218cd897961730
4
- data.tar.gz: 299e676ad777d512b53d6c81a2a3b696eca00fb2d11adcaf2a3f24b6075c5fe1
3
+ metadata.gz: 2376ca7f3510ebe230523b2fd5629dc39a5c44f3415ce3980d1e27d156ac3397
4
+ data.tar.gz: eaeb5ae1fe8dd868b772d9dfa267665e2b0e8b6f63c4761cab2d861cac412499
5
5
  SHA512:
6
- metadata.gz: 68446f6bb248f579689091fa094752f95db702ca6fc9f6de5588b68c1c564ee45499d71acee7b674b8784b78403a275e15afb5249e867571542e96c93ae608bd
7
- data.tar.gz: 65c78a6d3ec2241756befc2a80a03691e74b37eed18093c0796ebd5a420f522b44f514e77b904f1a2ab7a97fb5862daaf7da2bcc3a5c2ba20000079111c3e994
6
+ metadata.gz: da5d3c16c081cd3c34be74d1f745bcc015e5c1fa9bbcdf6d55552e1e2c30df831ad63c025c86e4ffda078dc37b1c7bcf16d14fe512dbb91bbabb54dd9b2ca944
7
+ data.tar.gz: acbdac6c519f20758e9af7922094032ce3d3bc67e4874d8b37bac283e408ca303cd3fc47ae51b360e3ef9d1bfddc68bc620f5a105e4a68ca4a3d0ca3fef73ef6
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ We suggest everybody using MidiSmtpServer to switch at least to latest 2.3.y. or
5
5
  For upgrades from previous versions or outdated _MiniSmtpServer_ gem you may follow the guides at [Appendix Upgrade](https://midi-smtp-server.readthedocs.io/appendix_upgrade/) to get your code ready for the latest releases.
6
6
 
7
7
 
8
+ #### 3.2.1 (2023-08-15)
9
+
10
+ 1. New feature [proxy](https://midi-smtp-server.readthedocs.io/feature_proxy) ([check issue 49](https://github.com/4commerce-technologies-AG/midi-smtp-server/issues/49))
11
+ 2. mkdocs update for readthedocs
12
+
13
+
8
14
  #### 3.1.2 (2023-05-06)
9
15
 
10
16
  1. Minor fix for backwards compatibility to method `start` when not using pre_fork options.
data/README.md CHANGED
@@ -76,7 +76,11 @@ This source code shows the example to receive messages via SMTP and store them t
76
76
 
77
77
  ## Installation
78
78
 
79
- MidiSmtpServer is packaged as a RubyGem so that you can easily install by entering following at your command line:
79
+ MidiSmtpServer is packaged as a RubyGem and hosted on rubygems.
80
+
81
+ #### CLI
82
+
83
+ You can easily install the package by entering following at your command line:
80
84
 
81
85
  `gem install midi-smtp-server`
82
86
 
@@ -84,6 +88,14 @@ Use the component in your project sources by:
84
88
 
85
89
  `require 'midi-smtp-server'`
86
90
 
91
+ #### Gemfile
92
+
93
+ When a `Gemfile` handles your dependencies, please consider to use the [pessimistic operator](https://thoughtbot.com/blog/rubys-pessimistic-operator) at least:
94
+
95
+ `gem 'midi-smtp-server', '~> 3.1.2''`
96
+
97
+ All changes by PATCH versions are always functional and compatible with no issues on update!
98
+
87
99
  <br>
88
100
 
89
101
 
@@ -147,9 +159,10 @@ We suggest everybody using MidiSmtpServer to switch at least to latest 2.3.y. or
147
159
  For upgrades from previous versions or outdated _MiniSmtpServer_ gem you may follow the guides (see appendix) how to change your existing code to be compatible with the latest releases.
148
160
 
149
161
 
150
- #### Latest release: 3.1.2 (2023-05-06)
162
+ #### Latest release: 3.2.1 (2023-08-15)
151
163
 
152
- 1. Minor fix for backwards compatibility to method `start` when not using pre_fork options.
164
+ 1. New feature [proxy](https://midi-smtp-server.readthedocs.io/feature_proxy) ([check issue 49](https://github.com/4commerce-technologies-AG/midi-smtp-server/issues/49))
165
+ 2. mkdocs update for readthedocs
153
166
 
154
167
 
155
168
  #### Changelog history
@@ -6,12 +6,12 @@ module MidiSmtpServer
6
6
  module VERSION
7
7
 
8
8
  MAJOR = 3
9
- MINOR = 1
10
- TINY = 2
9
+ MINOR = 2
10
+ TINY = 1
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
13
13
 
14
- DATE = '2023-05-06'
14
+ DATE = '2023-08-15'
15
15
 
16
16
  end
17
17
 
@@ -33,6 +33,7 @@ module MidiSmtpServer
33
33
  DEFAULT_IO_BUFFER_MAX_SIZE = 1 * 1024 * 1024
34
34
 
35
35
  # default value for SMTPD extensions support
36
+ DEFAULT_PROXY_EXTENSION_ENABLED = false
36
37
  DEFAULT_PIPELINING_EXTENSION_ENABLED = false
37
38
  DEFAULT_INTERNATIONALIZATION_EXTENSIONS_ENABLED = false
38
39
 
@@ -214,6 +215,8 @@ module MidiSmtpServer
214
215
  attr_reader :pipelining_extension
215
216
  # handle SMTP 8BITMIME and SMTPUTF8 extension
216
217
  attr_reader :internationalization_extensions
218
+ # handle PROXY connections
219
+ attr_reader :proxy_extension
217
220
 
218
221
  # logging object, may be overridden by special loggers like YELL or others
219
222
  attr_reader :logger
@@ -233,6 +236,7 @@ module MidiSmtpServer
233
236
  # +io_buffer_max_size+:: max size of buffer (max line length) until \lf ist expected (DEFAULT_IO_BUFFER_MAX_SIZE, nil => disabled test)
234
237
  # +pipelining_extension+:: set to true for support of SMTP PIPELINING extension (DEFAULT_PIPELINING_EXTENSION_ENABLED)
235
238
  # +internationalization_extensions+:: set to true for support of SMTP 8BITMIME and SMTPUTF8 extensions (DEFAULT_INTERNATIONALIZATION_EXTENSIONS_ENABLED)
239
+ # +proxy_extension+:: set to true for supporting PROXY connections (DEFAULT_PROXY_EXTENSION_ENABLED)
236
240
  # +auth_mode+:: enable builtin authentication support (:AUTH_FORBIDDEN [default], :AUTH_OPTIONAL, :AUTH_REQUIRED)
237
241
  # +tls_mode+:: enable builtin TLS support (:TLS_FORBIDDEN [default], :TLS_OPTIONAL, :TLS_REQUIRED)
238
242
  # +tls_cert_path+:: path to tls certificate chain file
@@ -257,6 +261,7 @@ module MidiSmtpServer
257
261
  io_buffer_max_size: nil,
258
262
  pipelining_extension: nil,
259
263
  internationalization_extensions: nil,
264
+ proxy_extension: nil,
260
265
  auth_mode: nil,
261
266
  tls_mode: nil,
262
267
  tls_cert_path: nil,
@@ -397,6 +402,8 @@ module MidiSmtpServer
397
402
  # smtp extensions
398
403
  @pipelining_extension = pipelining_extension.nil? ? DEFAULT_PIPELINING_EXTENSION_ENABLED : pipelining_extension
399
404
  @internationalization_extensions = internationalization_extensions.nil? ? DEFAULT_INTERNATIONALIZATION_EXTENSIONS_ENABLED : internationalization_extensions
405
+ @proxy_extension = proxy_extension.nil? ? DEFAULT_PROXY_EXTENSION_ENABLED : proxy_extension
406
+ require 'ipaddr' if @proxy_extension
400
407
 
401
408
  # check for authentication
402
409
  @auth_mode = auth_mode.nil? ? DEFAULT_AUTH_MODE : auth_mode
@@ -482,6 +489,13 @@ module MidiSmtpServer
482
489
  # the value is not allowed to return CR nor LF chars and will be stripped
483
490
  def on_helo_event(ctx, helo_data) end
484
491
 
492
+ # event on PROXY
493
+ # you may raise an exception if you want to block some addresses
494
+ # you also may change or add any value of the hash:
495
+ # {proto, source_ip, source_host, source_port, dest_ip, dest_host, dest_port}
496
+ # a returned value hash is set as ctx[:server][:proxy]
497
+ def on_proxy_event(ctx, proxy_data) end
498
+
485
499
  # check the authentication on AUTH
486
500
  # if any value returned, that will be used for ongoing processing
487
501
  # otherwise the original value will be used for authorization_id
@@ -772,7 +786,7 @@ module MidiSmtpServer
772
786
  # process commands and handle special SmtpdExceptions
773
787
  begin
774
788
  # check for pipelining extension or violation
775
- raise Smtpd500PipeliningException unless @pipelining_extension || !io_buffer_line_lf || (session[:cmd_sequence] == :CMD_DATA)
789
+ raise Smtpd500PipeliningException unless !io_buffer_line_lf || @pipelining_extension || (proxy_extension && (session[:cmd_sequence] == :CMD_HELO)) || (session[:cmd_sequence] == :CMD_DATA)
776
790
 
777
791
  # handle input line based on @crlf_mode
778
792
  case crlf_mode
@@ -952,6 +966,88 @@ module MidiSmtpServer
952
966
  return "250 OK #{session[:ctx][:server][:helo_response].to_s.strip}".strip
953
967
  end
954
968
 
969
+ when @proxy_extension && (/^PROXY(\s+)/i)
970
+ # PROXY
971
+ # 250 Requested mail action okay, completed
972
+ # 421 <domain> Service not available, closing transmission channel
973
+ # 500 Syntax error, command unrecognised
974
+ # 501 Syntax error in parameters or arguments
975
+ # ---------
976
+ # Documentation at https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt
977
+ # syntax
978
+ # PROXY PROTO source-ip dest-ip source-port dest-port
979
+ # supported commands:
980
+ # PROXY TCP4 255.255.255.255 255.255.255.255 65535 65535
981
+ # PROXY TCP6 ffff:f...f:ffff ffff:f...f:ffff 65535 65535
982
+ # PROXY UNKNOWN
983
+ # PROXY UNKNOWN ffff:f...f:ffff ffff:f...f:ffff 65535 65535
984
+ # ---------
985
+ # check valid command sequence
986
+ raise Smtpd503Exception if session[:cmd_sequence] != :CMD_HELO
987
+ # check valid command
988
+ raise Smtpd421Exception, 'Abort connection while illegal PROXY command!' unless line.match?(/^PROXY(\s+)(UNKNOWN(|(\s+).*)|TCP(4|6)(\s+)([0-9a-f.:]+)(\s+)([0-9a-f.:]+)(\s+)([0-9]+)(\s+)([0-9]+)(\s*))$/i)
989
+ # check command usage is allowed only once
990
+ raise Smtpd421Exception, 'Abort connection while PROXY already set!' if session[:ctx][:server][:proxy]
991
+ # get values from proxy command
992
+ cmd_data = line.gsub(/^PROXY\ /i, '').strip.gsub(/\s+/, ' ').split
993
+ # create an empty hash to inspect by event
994
+ proxy_data = {
995
+ proto: cmd_data[0].upcase,
996
+ source_ip: nil,
997
+ source_host: nil,
998
+ source_port: nil,
999
+ dest_ip: nil,
1000
+ dest_host: nil,
1001
+ dest_port: nil
1002
+ }
1003
+ # test proto
1004
+ unless proxy_data[:proto] == 'UNKNOWN'
1005
+ begin
1006
+ # try to build valid addresses from given strings
1007
+ proxy_data[:source_ip] = IPAddr.new(cmd_data[1])
1008
+ proxy_data[:source_port] = cmd_data[3].to_i
1009
+ proxy_data[:dest_ip] = IPAddr.new(cmd_data[2])
1010
+ proxy_data[:dest_port] = cmd_data[4].to_i
1011
+ # check that given addresses correct by type
1012
+ if proxy_data[:proto] == 'TCP4'
1013
+ raise unless proxy_data[:source_ip].ipv4?
1014
+ raise unless proxy_data[:dest_ip].ipv4?
1015
+ else
1016
+ raise unless proxy_data[:source_ip].ipv6?
1017
+ raise unless proxy_data[:dest_ip].ipv6?
1018
+ end
1019
+ # check that ports within valid ranges
1020
+ raise unless proxy_data[:source_port].between?(1, 65_535)
1021
+ raise unless proxy_data[:dest_port].between?(1, 65_535)
1022
+
1023
+ # update hash to inspect by event
1024
+ # normalize ip addresses
1025
+ proxy_data[:source_ip] = proxy_data[:source_ip].to_s
1026
+ proxy_data[:source_host] = proxy_data[:source_ip]
1027
+ proxy_data[:dest_ip] = proxy_data[:dest_ip].to_s
1028
+ proxy_data[:dest_host] = proxy_data[:dest_ip]
1029
+
1030
+ rescue StandardError
1031
+ # change exception into Smtpd exception and drop connection
1032
+ raise Smtpd421Exception, 'Abort connection for unsupported PROXY parameters!'
1033
+ end
1034
+ end
1035
+
1036
+ # call event to handle data
1037
+ return_value = on_proxy_event(session[:ctx], proxy_data)
1038
+ if return_value
1039
+ # overwrite data with returned value
1040
+ proxy_data = return_value
1041
+ end
1042
+ # if no error raised, append to server hash
1043
+ session[:ctx][:server][:proxy] = proxy_data
1044
+
1045
+ # reply nothing
1046
+ # otherwise on buffering clients or enabled feature pipelining
1047
+ # the original client will receive unhandleable responses
1048
+ # and gets interrupted
1049
+ return ''
1050
+
955
1051
  when /^STARTTLS\s*$/i
956
1052
  # STARTTLS
957
1053
  # 220 Ready to start TLS
@@ -1294,6 +1390,7 @@ module MidiSmtpServer
1294
1390
  remote_host: +'',
1295
1391
  remote_ip: +'',
1296
1392
  remote_port: +'',
1393
+ proxy: nil,
1297
1394
  helo: +'',
1298
1395
  helo_response: +'',
1299
1396
  connected: +'',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midi-smtp-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Freudenberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-06 00:00:00.000000000 Z
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: MidiSmtpServer is the highly customizable ruby SMTP-Server and SMTP-Service
14
14
  library with builtin support for AUTH and SSL/STARTTLS, 8BITMIME and SMTPUTF8, IPv4
@@ -34,7 +34,7 @@ metadata:
34
34
  source_code_uri: https://github.com/4commerce-technologies-AG/midi-smtp-server
35
35
  changelog_uri: https://github.com/4commerce-technologies-AG/midi-smtp-server#changes-and-updates
36
36
  bug_tracker_uri: https://github.com/4commerce-technologies-AG/midi-smtp-server/issues
37
- documentation_uri: https://www.rubydoc.info/gems/midi-smtp-server/3.1.2
37
+ documentation_uri: https://www.rubydoc.info/gems/midi-smtp-server/3.2.1
38
38
  wiki_uri: https://midi-smtp-server.readthedocs.io/
39
39
  post_install_message:
40
40
  rdoc_options: []
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.4.1
54
+ rubygems_version: 3.4.10
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: MidiSmtpServer Class