mail_plugger 1.0.0.beta1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'base64'
4
+ require 'mail/indifferent_hash'
4
5
 
5
6
  module MailPlugger
6
7
  module MailHelper
@@ -42,6 +43,8 @@ module MailPlugger
42
43
  data = {}
43
44
 
44
45
  delivery_options.each do |option|
46
+ option = option.to_sym unless option.is_a?(Symbol)
47
+
45
48
  data[option] =
46
49
  case option
47
50
  when :from, :to, :cc, :bcc, :subject
@@ -50,12 +53,14 @@ module MailPlugger
50
53
  extract_attachments
51
54
  when :body, :html_part, :text_part
52
55
  @message.public_send(option)&.decoded
56
+ when :message_obj
57
+ @message
53
58
  else
54
- message_field_value_from(@message[option.to_s])
59
+ message_field_value_from(@message[option])
55
60
  end
56
61
  end
57
62
 
58
- data
63
+ Mail::IndifferentHash.new(data)
59
64
  end
60
65
 
61
66
  # Tries to set up a default delivery system, if the 'delivery_system'
@@ -65,11 +70,7 @@ module MailPlugger
65
70
  #
66
71
  # @return [Stirng] the first key of the 'delivery_options' or 'client'
67
72
  def default_delivery_system_get
68
- if @delivery_options.is_a?(Hash)
69
- @delivery_options
70
- elsif @client.is_a?(Hash)
71
- @client
72
- end&.keys&.first
73
+ extract_keys&.first
73
74
  end
74
75
 
75
76
  # Extract 'delivery_options'. If it's a hash then it'll return the right
@@ -95,16 +96,30 @@ module MailPlugger
95
96
  # @return [String] with the name of the delivery system
96
97
  def delivery_system
97
98
  @delivery_system ||=
98
- (@message && message_field_value_from(@message['delivery_system'])) ||
99
+ (@message && message_field_value_from(@message[:delivery_system])) ||
99
100
  @default_delivery_system
100
101
 
101
- if @delivery_system.nil? &&
102
- (@delivery_options.is_a?(Hash) || @client.is_a?(Hash))
102
+ delivery_system_value_check
103
+
104
+ @delivery_system
105
+ end
106
+
107
+ # Check the given 'delivery_options' or 'client' are hashes and
108
+ # if one of that does then check the 'delivery_system' is valid or not.
109
+ # If the given 'delivery_system' is nil or doesn't match with extracted keys
110
+ # then it will raise error.
111
+ def delivery_system_value_check
112
+ return unless @delivery_options.is_a?(Hash) || @client.is_a?(Hash)
113
+
114
+ if @delivery_system.nil?
103
115
  raise Error::WrongDeliverySystem,
104
116
  '"delivery_system" was not defined as a Mail::Message parameter'
105
117
  end
106
118
 
107
- @delivery_system
119
+ return if extract_keys&.include?(@delivery_system)
120
+
121
+ raise Error::WrongDeliverySystem,
122
+ "\"delivery_system\" '#{@delivery_system}' does not exist"
108
123
  end
109
124
 
110
125
  # Extract attachments.
@@ -112,21 +127,29 @@ module MailPlugger
112
127
  # @return [Array] with extracted attachment hashes
113
128
  def extract_attachments
114
129
  @message.attachments&.map do |attachment|
115
- hash =
116
- if attachment.inline?
117
- { cid: attachment.cid }
118
- else
119
- { filename: attachment.filename }
120
- end
130
+ hash = attachment.inline? ? { cid: attachment.cid } : {}
121
131
 
122
132
  hash.merge(
133
+ filename: attachment.filename,
123
134
  type: attachment.mime_type,
124
135
  content: Base64.encode64(attachment.decoded)
125
136
  )
126
137
  end
127
138
  end
128
139
 
129
- # How to Extract the (uparsed) value of the mail message fields.
140
+ # Extract keys from 'delivery_options' or 'client', depends on which is a
141
+ # hash. If none of these are hashes then returns nil.
142
+ #
143
+ # @return [Array/NilClass] with the keys of 'delivery_options' or 'client'
144
+ def extract_keys
145
+ if @delivery_options.is_a?(Hash)
146
+ @delivery_options
147
+ elsif @client.is_a?(Hash)
148
+ @client
149
+ end&.keys
150
+ end
151
+
152
+ # How to Extract the (unparsed) value of the mail message fields.
130
153
  #
131
154
  # @return [String] version dependent method call
132
155
  def mail_field_value
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MailPlugger
4
- VERSION = '1.0.0.beta1'
4
+ VERSION = '1.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_plugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norbert Szivós
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -24,55 +24,36 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.5'
27
- description: Delivery Method to send emails via the defined API(s), e.g. for Rails
28
- ActionMailer.
27
+ description: Delivery Method to send emails via API(s). We can use this Delivery Method
28
+ with Ruby on Rails ActionMailer or other solutions.
29
29
  email:
30
30
  - sysqa@yahoo.com
31
31
  executables: []
32
32
  extensions: []
33
- extra_rdoc_files: []
33
+ extra_rdoc_files:
34
+ - LICENSE.txt
35
+ - README.md
34
36
  files:
35
- - ".github/ISSUE_TEMPLATE/bug_report.md"
36
- - ".github/ISSUE_TEMPLATE/feature_request.md"
37
- - ".gitignore"
38
- - ".rspec"
39
- - ".rubocop.yml"
40
- - ".travis.yml"
41
- - Appraisals
42
37
  - CHANGELOG.md
43
- - CODE_OF_CONDUCT.md
44
- - CONTRIBUTING.md
45
- - Gemfile
46
- - Gemfile.lock
47
38
  - LICENSE.txt
48
39
  - README.md
49
- - Rakefile
50
- - bin/console
51
- - bin/setup
52
- - docs/usage_in_ruby_on_rails.md
53
- - docs/usage_in_script_or_console.md
54
- - gemfiles/.bundle/config
55
- - gemfiles/mail_2.6.gemfile
56
- - gemfiles/mail_2.6.gemfile.lock
57
- - gemfiles/mail_2.7.0.gemfile
58
- - gemfiles/mail_2.7.0.gemfile.lock
59
- - gemfiles/mail_2.7.gemfile
60
- - gemfiles/mail_2.7.gemfile.lock
61
- - images/mail_plugger.png
40
+ - lib/fake_plugger/delivery_method.rb
41
+ - lib/fake_plugger/railtie.rb
62
42
  - lib/mail_plugger.rb
63
43
  - lib/mail_plugger/delivery_method.rb
64
44
  - lib/mail_plugger/error.rb
65
45
  - lib/mail_plugger/mail_helper.rb
66
46
  - lib/mail_plugger/railtie.rb
67
47
  - lib/mail_plugger/version.rb
68
- - mail_plugger.gemspec
69
48
  homepage: https://github.com/norbertszivos/mail_plugger
70
49
  licenses:
71
50
  - MIT
72
51
  metadata:
73
52
  homepage_uri: https://github.com/norbertszivos/mail_plugger
74
53
  source_code_uri: https://github.com/norbertszivos/mail_plugger
75
- changelog_uri: https://github.com/norbertszivos/mail_plugger/CHANGELOG.md
54
+ changelog_uri: https://github.com/norbertszivos/mail_plugger/blob/main/CHANGELOG.md
55
+ bug_tracker_uri: https://github.com/norbertszivos/mail_plugger/issues
56
+ documentation_uri: https://rubydoc.info/gems/mail_plugger
76
57
  post_install_message:
77
58
  rdoc_options: []
78
59
  require_paths:
@@ -84,11 +65,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
65
  version: 2.5.0
85
66
  required_rubygems_version: !ruby/object:Gem::Requirement
86
67
  requirements:
87
- - - ">"
68
+ - - ">="
88
69
  - !ruby/object:Gem::Version
89
- version: 1.3.1
70
+ version: '0'
90
71
  requirements: []
91
- rubygems_version: 3.2.3
72
+ rubygems_version: 3.1.4
92
73
  signing_key:
93
74
  specification_version: 4
94
75
  summary: Plug in the required mailer API(s) with MailPlugger.
@@ -1,22 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- ---
5
-
6
- **Describe the bug**
7
- A clear and concise description of what the bug is.
8
-
9
- **To Reproduce**
10
- This is important! Providing us with a reliable way to reproduce a problem will expedite its solution.
11
-
12
- **Expected behavior**
13
- A clear and concise description of what you expected to happen.
14
-
15
- **Actual behavior
16
- Describe here what actually happened.
17
-
18
- **Screenshots**
19
- If applicable, add screenshots to help explain your problem.
20
-
21
- **Additional context**
22
- Add any other context about the problem here.
@@ -1,16 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- ---
5
-
6
- **Is your feature request related to a problem? Please describe.**
7
- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
8
-
9
- **Describe the solution you'd like**
10
- A clear and concise description of what you want to happen.
11
-
12
- **Describe alternatives you've considered**
13
- A clear and concise description of any alternative solutions or features you've considered.
14
-
15
- **Additional context**
16
- Add any other context or screenshots about the feature request here.
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,50 +0,0 @@
1
- require:
2
- - rubocop-performance
3
- - rubocop-rspec
4
-
5
- AllCops:
6
- NewCops: enable
7
- SuggestExtensions: false
8
- Exclude:
9
- - 'gemfiles/**/*'
10
-
11
- Layout/LineLength:
12
- Max: 80
13
-
14
- Metrics/BlockLength:
15
- Exclude:
16
- - spec/**/*
17
-
18
- Metrics/MethodLength:
19
- Max: 20
20
-
21
- Metrics/ModuleLength:
22
- Max: 150
23
-
24
- Lint/AmbiguousBlockAssociation:
25
- Exclude:
26
- - spec/**/*
27
-
28
- Style/Documentation:
29
- Enabled: false
30
-
31
- Style/DocumentationMethod:
32
- Enabled: true
33
-
34
- RSpec/ContextWording:
35
- Enabled: false
36
-
37
- RSpec/MessageChain:
38
- Enabled: false
39
-
40
- RSpec/MessageSpies:
41
- EnforcedStyle: receive
42
-
43
- RSpec/MultipleExpectations:
44
- Enabled: false
45
-
46
- RSpec/MultipleMemoizedHelpers:
47
- Max: 10
48
-
49
- RSpec/NestedGroups:
50
- Enabled: false
@@ -1,22 +0,0 @@
1
- ---
2
- env:
3
- global:
4
- - CC_TEST_REPORTER_ID=b510dcaf1de6f05f2fcdd623d5870628f3ab45124249a0819a63bea1257e8e79
5
- language: ruby
6
- cache: bundler
7
- rvm:
8
- - 2.5
9
- - 2.6
10
- - 2.7
11
- - 3.0
12
- before_install: gem install bundler -v 2.2.3
13
- before_script:
14
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
- - chmod +x ./cc-test-reporter
16
- - ./cc-test-reporter before-build
17
- gemfile:
18
- - gemfiles/mail_2.7.gemfile
19
- - gemfiles/mail_2.7.0.gemfile
20
- - gemfiles/mail_2.6.gemfile
21
- after_script:
22
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Appraisals DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- appraise 'mail-2.7' do
4
- gem 'mail', '~> 2.7.0'
5
- end
6
-
7
- appraise 'mail-2.7.0' do
8
- gem 'mail', '2.7.0'
9
- end
10
-
11
- appraise 'mail-2.6' do
12
- gem 'mail', '~> 2.6.0'
13
- end
@@ -1,14 +0,0 @@
1
- # The MailPlugger Community Code of Conduct
2
-
3
- **Note:** We have picked the following code of conduct based on [Ruby's own code of conduct](https://www.ruby-lang.org/en/conduct/).
4
-
5
- This document provides a few simple community guidelines for a safe, respectful,
6
- productive, and collaborative place for any person who is willing to contribute
7
- to the MailPlugger community. It applies to all "collaborative spaces", which are
8
- defined as community communications channels (such as mailing lists, submitted
9
- patches, commit comments, etc.).
10
-
11
- * Participants will be tolerant of opposing views.
12
- * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
13
- * When interpreting the words and actions of others, participants should always assume good intentions.
14
- * Behaviour which can be reasonably considered harassment will not be tolerated.
@@ -1,26 +0,0 @@
1
- # Contributing
2
-
3
- If you discover issues, have ideas for improvements or new features,
4
- please report them to the [issue tracker](https://github.com/norbertszivos/mail_plugger/issues) of the repository or
5
- submit a pull request. Please, try to follow these guidelines when you
6
- do so.
7
-
8
- ## Issue reporting
9
-
10
- * Check that the issue has not already been reported.
11
- * Check that the issue has not already been fixed in the latest code.
12
- * Be clear, concise and precise in your description of the problem.
13
- * Open an issue with a descriptive title and summary.
14
- * Include any relevant code to the issue summary.
15
-
16
- ## Pull requests
17
-
18
- * Fork the project.
19
- * Use a feature branch to easily amend a pull request later, if necessary.
20
- * Write good commit messages.
21
- * Use the same coding conventions as the rest of the project.
22
- * If your change has a corresponding open GitHub issue, prefix the commit message with `[#github-issue-number]`.
23
- * Make sure to add tests for it.
24
- * Make sure the test suite is passing (usually this is as simple as running `bundle exec rake`).
25
- * Squash related commits together.
26
- * Open a pull request that relates to *only* one subject with a clear title and description.
data/Gemfile DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in mail_plugger.gemspec
6
- gemspec
7
-
8
- gem 'appraisal'
9
-
10
- gem 'rake', '~> 13.0'
11
-
12
- # Ruby static code analyzer and code formatter, code linter in short
13
- gem 'rubocop', '~> 1.7', require: false
14
- gem 'rubocop-performance', require: false
15
- gem 'rubocop-rspec', require: false
16
-
17
- gem 'rspec', '~> 3.0'
18
- gem 'simplecov', require: false
19
- gem 'webmock', '~> 3.0'
@@ -1,92 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mail_plugger (1.0.0.beta1)
5
- mail (~> 2.5)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- addressable (2.7.0)
11
- public_suffix (>= 2.0.2, < 5.0)
12
- appraisal (2.3.0)
13
- bundler
14
- rake
15
- thor (>= 0.14.0)
16
- ast (2.4.1)
17
- crack (0.4.5)
18
- rexml
19
- diff-lcs (1.4.4)
20
- docile (1.3.4)
21
- hashdiff (1.0.1)
22
- mail (2.7.1)
23
- mini_mime (>= 0.1.1)
24
- mini_mime (1.0.2)
25
- parallel (1.20.1)
26
- parser (3.0.0.0)
27
- ast (~> 2.4.1)
28
- public_suffix (4.0.6)
29
- rainbow (3.0.0)
30
- rake (13.0.3)
31
- regexp_parser (2.0.3)
32
- rexml (3.2.4)
33
- rspec (3.10.0)
34
- rspec-core (~> 3.10.0)
35
- rspec-expectations (~> 3.10.0)
36
- rspec-mocks (~> 3.10.0)
37
- rspec-core (3.10.1)
38
- rspec-support (~> 3.10.0)
39
- rspec-expectations (3.10.1)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.10.0)
42
- rspec-mocks (3.10.1)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.10.0)
45
- rspec-support (3.10.1)
46
- rubocop (1.7.0)
47
- parallel (~> 1.10)
48
- parser (>= 2.7.1.5)
49
- rainbow (>= 2.2.2, < 4.0)
50
- regexp_parser (>= 1.8, < 3.0)
51
- rexml
52
- rubocop-ast (>= 1.2.0, < 2.0)
53
- ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 2.0)
55
- rubocop-ast (1.3.0)
56
- parser (>= 2.7.1.5)
57
- rubocop-performance (1.9.2)
58
- rubocop (>= 0.90.0, < 2.0)
59
- rubocop-ast (>= 0.4.0)
60
- rubocop-rspec (2.1.0)
61
- rubocop (~> 1.0)
62
- rubocop-ast (>= 1.1.0)
63
- ruby-progressbar (1.11.0)
64
- simplecov (0.20.0)
65
- docile (~> 1.1)
66
- simplecov-html (~> 0.11)
67
- simplecov_json_formatter (~> 0.1)
68
- simplecov-html (0.12.3)
69
- simplecov_json_formatter (0.1.2)
70
- thor (1.0.1)
71
- unicode-display_width (1.7.0)
72
- webmock (3.11.0)
73
- addressable (>= 2.3.6)
74
- crack (>= 0.3.2)
75
- hashdiff (>= 0.4.0, < 2.0.0)
76
-
77
- PLATFORMS
78
- ruby
79
-
80
- DEPENDENCIES
81
- appraisal
82
- mail_plugger!
83
- rake (~> 13.0)
84
- rspec (~> 3.0)
85
- rubocop (~> 1.7)
86
- rubocop-performance
87
- rubocop-rspec
88
- simplecov
89
- webmock (~> 3.0)
90
-
91
- BUNDLED WITH
92
- 2.2.3