mail-relayer 0.1.0
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 +7 -0
- data/CHANGELOG.md +11 -0
- data/LICENSE +20 -0
- data/README.md +20 -0
- data/VERSION +1 -0
- data/bin/mail-relayer +20 -0
- data/lib/mail-relayer.rb +3 -0
- data/lib/mail/relayer.rb +78 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91d61c76888e98c510ebc89367ae2308c81e9a0d86deb435cab7a002a25d84ec
|
4
|
+
data.tar.gz: e79c169436b9963319b16e4e8a19fc0d3814ec6c9ec143479f8ec8478bfcdf18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a6bc66b94878889ff49562ecc255dbc1c228bd0a55a332a4810351d66c41033858ccc398e601e5185a10ca5b2b3d05a0c448294d819521f1e5566704c5eec1f
|
7
|
+
data.tar.gz: 48fe0a136889b42396f79205d3673adb8d0fb0064b8d09f85f8ffb2f0aea14137f153aa67c4193f457493a58b76d521b2a713a3d93b7a5a62fb0ab6881e79c71
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## v0.1.0 - Dec 19, 2019
|
4
|
+
|
5
|
+
Adds executable `mail-relayer` for CLI usage.
|
6
|
+
|
7
|
+
## v0.0.1 - Dec 18, 2019
|
8
|
+
|
9
|
+
Initial release.
|
10
|
+
|
11
|
+
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.
|
data/README.md
ADDED
@@ -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.1.0
|
data/bin/mail-relayer
ADDED
@@ -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
|
+
unless url && password
|
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
|
data/lib/mail-relayer.rb
ADDED
data/lib/mail/relayer.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
module Mail
|
8
|
+
class Relayer
|
9
|
+
class Result < Struct.new(:status_code, :message)
|
10
|
+
def success?
|
11
|
+
!failure?
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure?
|
15
|
+
transient_failure? || permanent_failure?
|
16
|
+
end
|
17
|
+
|
18
|
+
def transient_failure?
|
19
|
+
status_code.start_with?("4.")
|
20
|
+
end
|
21
|
+
|
22
|
+
def permanent_failure?
|
23
|
+
status_code.start_with?("5.")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
VERSION = File.read(File.expand_path("../../VERSION", __dir__)).strip
|
28
|
+
|
29
|
+
CONTENT_TYPE = "message/rfc822"
|
30
|
+
USER_AGENT = "Mail relayer v#{VERSION}"
|
31
|
+
|
32
|
+
attr_reader :uri, :username, :password
|
33
|
+
|
34
|
+
def initialize(url:, username: "mail_relayer", password:)
|
35
|
+
@uri, @username, @password = URI(url), username, password
|
36
|
+
end
|
37
|
+
|
38
|
+
def relay(source)
|
39
|
+
case response = post(source)
|
40
|
+
when Net::HTTPSuccess
|
41
|
+
Result.new "2.0.0", "Successfully relayed message to ingress"
|
42
|
+
when Net::HTTPUnauthorized
|
43
|
+
Result.new "4.7.0", "Invalid credentials for ingress"
|
44
|
+
else
|
45
|
+
Result.new "4.0.0", "HTTP #{response.code}"
|
46
|
+
end
|
47
|
+
rescue IOError, SocketError, SystemCallError => error
|
48
|
+
Result.new "4.4.2", "Network error relaying to ingress: #{error.message}"
|
49
|
+
rescue Timeout::Error
|
50
|
+
Result.new "4.4.2", "Timed out relaying to ingress"
|
51
|
+
rescue => error
|
52
|
+
Result.new "4.0.0", "Error relaying to ingress: #{error.message}"
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def post(source)
|
58
|
+
client.post uri, source,
|
59
|
+
"Content-Type" => CONTENT_TYPE,
|
60
|
+
"User-Agent" => USER_AGENT,
|
61
|
+
"Authorization" => "Basic #{Base64.strict_encode64(username + ":" + password)}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def client
|
65
|
+
@client ||= Net::HTTP.new(uri.host, uri.port).tap do |connection|
|
66
|
+
if uri.scheme == "https"
|
67
|
+
require "openssl"
|
68
|
+
|
69
|
+
connection.use_ssl = true
|
70
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
71
|
+
end
|
72
|
+
|
73
|
+
connection.open_timeout = 1
|
74
|
+
connection.read_timeout = 10
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
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.1.0
|
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: []
|