mail-relayer 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +19 -0
- data/LICENSE +20 -0
- data/README.md +34 -0
- data/VERSION +1 -0
- data/bin/mail-relayer +40 -0
- data/lib/mail/relayer.rb +80 -0
- data/lib/mail_relayer.rb +3 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7000ec5bbfcc9779972081b7508bee5768abd044ccf812d39529f4745a26adb
|
4
|
+
data.tar.gz: deeca4cc2f1bb7248f0a936b93547e1f6f2bc1ea4c09138d485a03cec0dfde2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1537b9b92e2a48cce91677b8b17355c96f8ed2ea83d858db462c32140fa3f7fff818b1077980192ea8e6c1c3e18467e2494af0a502efa56224d22ff17a9c5cba
|
7
|
+
data.tar.gz: 67f2dc3fb60869a1cbd3623b253ffddcba5f62b5ef4c4e8a3125b857d4db10229fd451aa397791b91112e22a7f2a2dab6c10542f3996636f336beb57c939a77f
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## v0.2.1 - Dec 20, 2019
|
4
|
+
|
5
|
+
Re-release v0.2.0 as v0.2.1.
|
6
|
+
|
7
|
+
## v0.2.0 - Dec 19, 2019
|
8
|
+
|
9
|
+
Adds option parsing to `mail-relayer` executable.
|
10
|
+
|
11
|
+
## v0.1.0 - Dec 19, 2019
|
12
|
+
|
13
|
+
Adds executable `mail-relayer` for CLI usage.
|
14
|
+
|
15
|
+
## v0.0.1 - Dec 17, 2019
|
16
|
+
|
17
|
+
Initial release.
|
18
|
+
|
19
|
+
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,34 @@
|
|
1
|
+
# Mail Relayer
|
2
|
+
|
3
|
+
This project is an attempt to simplify relaying incoming emails, e.g. to ActionMailbox.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
1. `gem install mail-relayer`
|
8
|
+
|
9
|
+
2. Then pipe the email content from `STDIN` to `mail-relayer` executable. You need to specify the target URL and password (HTTP Basic Auth) either via command line arguments or via environment variables.
|
10
|
+
|
11
|
+
3. Profit
|
12
|
+
|
13
|
+
### Configuration
|
14
|
+
|
15
|
+
- target URL: `--url` or `MAIL_RELAYER_URL`
|
16
|
+
- ingress username: `--ingress-username` or `MAIL_RELAYER_INGRESS_USERNAME` (optional, default: `mail_relayer`)
|
17
|
+
- ingress password: `--ingress-password` or `MAIL_RELAYER_INGRESS_PASSWORD`
|
18
|
+
|
19
|
+
## Development
|
20
|
+
|
21
|
+
1. Install ruby - see `.ruby-version`
|
22
|
+
2. Install bundler - `gem install bundler`
|
23
|
+
3. Install dependencies - `bundle install`
|
24
|
+
|
25
|
+
## Tests
|
26
|
+
|
27
|
+
- `rake test` runs all MiniTest tests in `/test`
|
28
|
+
- `rubocop` run static code checks
|
29
|
+
|
30
|
+
## Build / Release
|
31
|
+
|
32
|
+
1. Update version number in `VERSION` if required.
|
33
|
+
2. `gem build mail-relayer.gemspec`
|
34
|
+
3. `gem install ./mail-relayer-<VERSION>.gem` to install locally
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/bin/mail-relayer
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
require "mail_relayer"
|
8
|
+
|
9
|
+
options = {
|
10
|
+
url: ENV["MAIL_RELAYER_URL"],
|
11
|
+
username: ENV["MAIL_RELAYER_INGRESS_USERNAME"],
|
12
|
+
password: ENV["MAIL_RELAYER_INGRESS_PASSWORD"]
|
13
|
+
}
|
14
|
+
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.on("--url URL") do |url|
|
17
|
+
options[:url] = url
|
18
|
+
end
|
19
|
+
opts.on("--ingress-username INGRESS_USERNAME") do |user|
|
20
|
+
options[:username] = user
|
21
|
+
end
|
22
|
+
opts.on("--ingress-password INGRESS_PASSWORD") do |password|
|
23
|
+
options[:password] = password
|
24
|
+
end
|
25
|
+
opts.on("-v", "--version") do
|
26
|
+
puts "mail-relayer v#{Mail::Relayer::VERSION}"
|
27
|
+
exit 0
|
28
|
+
end
|
29
|
+
end.parse!
|
30
|
+
|
31
|
+
unless options[:url] && options[:password]
|
32
|
+
puts "4.3.5 URL and INGRESS_PASSWORD are required"
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
relayer = Mail::Relayer.new(**options.compact)
|
37
|
+
result = relayer.relay(STDIN.read)
|
38
|
+
|
39
|
+
puts "#{result.status_code} #{result.message}"
|
40
|
+
exit result.success?
|
data/lib/mail/relayer.rb
ADDED
@@ -0,0 +1,80 @@
|
|
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) # rubocop:disable Style/StructInheritance
|
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 = URI(url)
|
36
|
+
@username = username
|
37
|
+
@password = password
|
38
|
+
end
|
39
|
+
|
40
|
+
def relay(source)
|
41
|
+
case response = post(source)
|
42
|
+
when Net::HTTPSuccess
|
43
|
+
Result.new "2.0.0", "Successfully relayed message to ingress"
|
44
|
+
when Net::HTTPUnauthorized
|
45
|
+
Result.new "4.7.0", "Invalid credentials for ingress"
|
46
|
+
else
|
47
|
+
Result.new "4.0.0", "HTTP #{response.code}"
|
48
|
+
end
|
49
|
+
rescue IOError, SocketError, SystemCallError => error
|
50
|
+
Result.new "4.4.2", "Network error relaying to ingress: #{error.message}"
|
51
|
+
rescue Timeout::Error
|
52
|
+
Result.new "4.4.2", "Timed out relaying to ingress"
|
53
|
+
rescue => error # rubocop:disable Style/RescueStandardError
|
54
|
+
Result.new "4.0.0", "Error relaying to ingress: #{error.message}"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def post(source)
|
60
|
+
client.post uri, source,
|
61
|
+
"Content-Type" => CONTENT_TYPE,
|
62
|
+
"User-Agent" => USER_AGENT,
|
63
|
+
"Authorization" => "Basic #{Base64.strict_encode64(username + ':' + password)}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def client
|
67
|
+
@client ||= Net::HTTP.new(uri.host, uri.port).tap do |connection|
|
68
|
+
if uri.scheme == "https"
|
69
|
+
require "openssl"
|
70
|
+
|
71
|
+
connection.use_ssl = true
|
72
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
73
|
+
end
|
74
|
+
|
75
|
+
connection.open_timeout = 1
|
76
|
+
connection.read_timeout = 10
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/mail_relayer.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mail-relayer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.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: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
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://gitlab.com/axelthegerman/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: []
|