mail-relayer 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 612517f1606c90a9d55decffa42f197787ddb2964c57e3a7198bdb3745399c7e
4
+ data.tar.gz: f2dc0f483c86759ca6b20daf3718bf308a0c530c44ee71beaa6aebc3ac53c528
5
+ SHA512:
6
+ metadata.gz: c6da27657694057750e4153f8ca61f1fe946900062627c2f2a592129b4f4610cc6f1def579e1918ad3981611817aa19894444d3b588c1b3f27560907e356806b
7
+ data.tar.gz: 17b8fad6fdd4c785f019ac57d1151a2ad5702684447d5a413a19d3c05b33af5b542775e27e0cc800e6a1a74e5396671cf14d5466c936ecc8a3f569aa2d65d17b
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.0.1 - TBD
4
+
5
+ Initial release.
6
+
7
+ Contains `Mail::Relayer` class adapted from `ActionMailbox::Relayer` - https://github.com/rails/rails/blob/master/actionmailbox/lib/action_mailbox/relayer.rb
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2019 Axel Gustav
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # Mail Relayer
2
+
3
+ This project is an attempt to simplify relaying incoming emails, e.g. to ActionMailbox.
4
+
5
+ ## Development
6
+
7
+ 1. Install ruby - see `.ruby-version`
8
+ 2. Install bundler - `gem install bundler`
9
+ 3. Install dependencies - `bundle install`
10
+
11
+ ## Tests
12
+
13
+ - `rake test` runs all MiniTest tests in `/test`
14
+ - `rubocop` run static code checks
15
+
16
+ ## Build / Release
17
+
18
+ 1. Update version number in `VERSION` if required.
19
+ 2. `gem build mail-relayer.gemspec`
20
+ 3. `gem install ./mail-relayer-<VERSION>.gem` to install locally
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "mail-relayer"
6
+
7
+ # postfix implementation
8
+ url, password = ENV.values_at("URL", "INGRESS_PASSWORD")
9
+
10
+ if url.blank? || password.blank?
11
+ print "4.3.5 URL and INGRESS_PASSWORD are required"
12
+ exit 1
13
+ end
14
+
15
+ Mail::Relayer.new(url: url, password: password)
16
+ .relay(STDIN.read)
17
+ .tap do |result|
18
+ print "#{result.status_code} #{result.message}"
19
+ exit result.success?
20
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mail/relayer"
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "uri"
5
+
6
+ module Mail
7
+ class Relayer
8
+ class Result < Struct.new(:status_code, :message)
9
+ def success?
10
+ !failure?
11
+ end
12
+
13
+ def failure?
14
+ transient_failure? || permanent_failure?
15
+ end
16
+
17
+ def transient_failure?
18
+ status_code.start_with?("4.")
19
+ end
20
+
21
+ def permanent_failure?
22
+ status_code.start_with?("5.")
23
+ end
24
+ end
25
+
26
+ VERSION = File.read(File.expand_path("../../VERSION", __dir__)).strip
27
+
28
+ CONTENT_TYPE = "message/rfc822"
29
+ USER_AGENT = "Mail relayer v#{VERSION}"
30
+
31
+ attr_reader :uri, :username, :password
32
+
33
+ def initialize(url:, username: "mail_relayer", password:)
34
+ @uri, @username, @password = URI(url), username, password
35
+ end
36
+
37
+ def relay(source)
38
+ case response = post(source)
39
+ when Net::HTTPSuccess
40
+ Result.new "2.0.0", "Successfully relayed message to ingress"
41
+ when Net::HTTPUnauthorized
42
+ Result.new "4.7.0", "Invalid credentials for ingress"
43
+ else
44
+ Result.new "4.0.0", "HTTP #{response.code}"
45
+ end
46
+ rescue IOError, SocketError, SystemCallError => error
47
+ Result.new "4.4.2", "Network error relaying to ingress: #{error.message}"
48
+ rescue Timeout::Error
49
+ Result.new "4.4.2", "Timed out relaying to ingress"
50
+ rescue => error
51
+ Result.new "4.0.0", "Error relaying to ingress: #{error.message}"
52
+ end
53
+
54
+ private
55
+
56
+ def post(source)
57
+ client.post uri, source,
58
+ "Content-Type" => CONTENT_TYPE,
59
+ "User-Agent" => USER_AGENT,
60
+ "Authorization" => "Basic #{Base64.strict_encode64(username + ":" + password)}"
61
+ end
62
+
63
+ def client
64
+ @client ||= Net::HTTP.new(uri.host, uri.port).tap do |connection|
65
+ if uri.scheme == "https"
66
+ require "openssl"
67
+
68
+ connection.use_ssl = true
69
+ connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
70
+ end
71
+
72
+ connection.open_timeout = 1
73
+ connection.read_timeout = 10
74
+ end
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail-relayer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Axel Gustav
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.77.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.77.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ description: A small wrapper around ActionMailbox::Relayer without any dependencies.
70
+ email: dev@axelgustav.de
71
+ executables:
72
+ - mail-relayer
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - LICENSE
78
+ - README.md
79
+ - VERSION
80
+ - bin/mail-relayer
81
+ - lib/mail-relayer.rb
82
+ - lib/mail/relayer.rb
83
+ homepage: https://rubygems.org/gems/mail-relayer
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.5.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.0.6
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Extracts ActionMailbox::Relayer for stand-alone use
106
+ test_files: []