howitzer 2.4.0 → 2.5.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 +4 -4
- data/CHANGELOG.md +13 -0
- data/generators/config/templates/default.yml +7 -0
- data/lib/howitzer/mail_adapters/mailtrap.rb +3 -3
- data/lib/howitzer/mail_adapters/onesecmail.rb +80 -0
- data/lib/howitzer/mail_adapters/testmail.rb +102 -0
- data/lib/howitzer/mailtrap_api/client.rb +18 -0
- data/lib/howitzer/onesecmail_api/client.rb +44 -0
- data/lib/howitzer/onesecmail_api.rb +7 -0
- data/lib/howitzer/testmail_api/client.rb +44 -0
- data/lib/howitzer/testmail_api.rb +7 -0
- data/lib/howitzer/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1044884bf6fe39dc63128f59f930a0d75ae80297a946d34d2464f47a30fe17fe
|
4
|
+
data.tar.gz: b5501960e801914414fc6569996a9cc219e601ea78dfea1dac28c7db9d582ac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 450f74b4dec7185673b2faa9138c8afb4b9568be8680f38718728105ad5893a5e1abfb1d908e759a021fcd3af13093e67775537b3a109219b065b00c30a7f293
|
7
|
+
data.tar.gz: 0bc01379c520937ec1bd004fffcc44b9c558ff9c1c5eea1a292067d65f5d1661f9f5aaf806c5b0183d34e46c2591fc3bd9b71a0cc8288fc7e12b56d9946478d0
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,19 @@
|
|
4
4
|
|
5
5
|
### Bug-fixes
|
6
6
|
|
7
|
+
## [2.5.0](https://github.com/strongqa/howitzer/compare/v2.4.0...v2.5.0) (2022-08-16)
|
8
|
+
|
9
|
+
|
10
|
+
### Features
|
11
|
+
|
12
|
+
* 1secMail integration ([#316](https://github.com/strongqa/howitzer/issues/316)) ([6850758](https://github.com/strongqa/howitzer/commit/6850758370bd293d241f95c2a3cc0163c6fb3062))
|
13
|
+
* testmail.app integration ([#314](https://github.com/strongqa/howitzer/issues/314)) ([7f62bae](https://github.com/strongqa/howitzer/commit/7f62bae2e7e91200e02ed98acded9070726f3fc1))
|
14
|
+
|
15
|
+
|
16
|
+
### Bug Fixes
|
17
|
+
|
18
|
+
* mailtrap integration update ([#313](https://github.com/strongqa/howitzer/issues/313)) ([49e7390](https://github.com/strongqa/howitzer/commit/49e73909f7033d2986b0f5713bbbcbea7231ade0))
|
19
|
+
|
7
20
|
## [2.4.0](https://github.com/strongqa/howitzer/compare/v2.3.0...v2.4.0) (2022-07-22)
|
8
21
|
|
9
22
|
|
@@ -24,19 +24,19 @@ module Howitzer
|
|
24
24
|
# @return [String] plain text body of the email message
|
25
25
|
|
26
26
|
def plain_text_body
|
27
|
-
message
|
27
|
+
Howitzer::MailtrapApi::Client.new.get_txt_body(message)
|
28
28
|
end
|
29
29
|
|
30
30
|
# @return [String] html body of the email message
|
31
31
|
|
32
32
|
def html_body
|
33
|
-
message
|
33
|
+
Howitzer::MailtrapApi::Client.new.get_html_body(message)
|
34
34
|
end
|
35
35
|
|
36
36
|
# @return [String] stripped text
|
37
37
|
|
38
38
|
def text
|
39
|
-
message
|
39
|
+
Howitzer::MailtrapApi::Client.new.get_raw_body(message)
|
40
40
|
end
|
41
41
|
|
42
42
|
# @return [String] an email address specified in `From` field
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'howitzer/exceptions'
|
2
|
+
require 'howitzer/mail_adapters/abstract'
|
3
|
+
require 'howitzer/onesecmail_api/client'
|
4
|
+
|
5
|
+
module Howitzer
|
6
|
+
module MailAdapters
|
7
|
+
# This class represents 1secMail mail adapter
|
8
|
+
class Onesecmail < Abstract
|
9
|
+
# Finds an email in storage
|
10
|
+
# @param recipient [String] an email
|
11
|
+
# @param subject [String]
|
12
|
+
# @param wait [Integer] how much time is required to wait an email
|
13
|
+
# @raise [EmailNotFoundError] if blank message
|
14
|
+
|
15
|
+
def self.find(recipient, subject, wait:)
|
16
|
+
message = {}
|
17
|
+
retryable(find_retry_params(wait)) { message = retrieve_message(recipient, subject) }
|
18
|
+
return new(message) if message.present?
|
19
|
+
|
20
|
+
raise Howitzer::EmailNotFoundError,
|
21
|
+
"Message with subject '#{subject}' for recipient '#{recipient}' was not found."
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] plain text body of the email message
|
25
|
+
|
26
|
+
def plain_text_body
|
27
|
+
message['body']
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] html body of the email message
|
31
|
+
|
32
|
+
def html_body
|
33
|
+
message['htmlBody']
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String] stripped text
|
37
|
+
|
38
|
+
def text
|
39
|
+
message['textBody']
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] an email address specified in `From` field
|
43
|
+
|
44
|
+
def mail_from
|
45
|
+
message['from']
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] when email was received
|
49
|
+
|
50
|
+
def received_time
|
51
|
+
Time.parse(message['date']).to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String] a real sender email address
|
55
|
+
|
56
|
+
def sender_email
|
57
|
+
message['from']
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_retry_params(wait)
|
61
|
+
{
|
62
|
+
timeout: wait,
|
63
|
+
sleep: Howitzer.mail_sleep_time,
|
64
|
+
silent: true,
|
65
|
+
logger: Howitzer::Log,
|
66
|
+
on: Howitzer::EmailNotFoundError
|
67
|
+
}
|
68
|
+
end
|
69
|
+
private_class_method :find_retry_params
|
70
|
+
|
71
|
+
def self.retrieve_message(recipient, subject)
|
72
|
+
message = Howitzer::OnesecmailApi::Client.new.find_message(recipient, subject)
|
73
|
+
raise Howitzer::EmailNotFoundError, 'Message not received yet, retry...' unless message
|
74
|
+
|
75
|
+
message
|
76
|
+
end
|
77
|
+
private_class_method :retrieve_message
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'howitzer/exceptions'
|
2
|
+
require 'howitzer/mail_adapters/abstract'
|
3
|
+
require 'howitzer/testmail_api/client'
|
4
|
+
|
5
|
+
module Howitzer
|
6
|
+
module MailAdapters
|
7
|
+
# This class represents testmail.app mail adapter
|
8
|
+
class Testmail < Abstract
|
9
|
+
# Finds an email in storage
|
10
|
+
# @param recipient [String] an email
|
11
|
+
# @param subject [String]
|
12
|
+
# @param wait [Integer] how much time is required to wait an email
|
13
|
+
# @raise [EmailNotFoundError] if blank message
|
14
|
+
|
15
|
+
def self.find(recipient, subject, wait:)
|
16
|
+
message = {}
|
17
|
+
retryable(find_retry_params(wait)) { message = retrieve_message(recipient, subject) }
|
18
|
+
return new(message) if message.present?
|
19
|
+
|
20
|
+
raise Howitzer::EmailNotFoundError,
|
21
|
+
"Message with subject '#{subject}' for recipient '#{recipient}' was not found."
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] plain text body of the email message
|
25
|
+
|
26
|
+
def plain_text_body
|
27
|
+
message['text']
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] html body of the email message
|
31
|
+
|
32
|
+
def html_body
|
33
|
+
message['html']
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String] stripped text
|
37
|
+
|
38
|
+
def text
|
39
|
+
message['text']
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] an email address specified in `From` field
|
43
|
+
|
44
|
+
def mail_from
|
45
|
+
message['from']
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] recipient emails separated with `, `
|
49
|
+
|
50
|
+
def recipients
|
51
|
+
message['to'].split ', '
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String] when email was received
|
55
|
+
|
56
|
+
def received_time
|
57
|
+
Time.parse(message['timestamp']).to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String] a real sender email address
|
61
|
+
|
62
|
+
def sender_email
|
63
|
+
message['from']
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Array] attachments
|
67
|
+
|
68
|
+
def mime_part
|
69
|
+
message['attachments']
|
70
|
+
end
|
71
|
+
|
72
|
+
# @raise [NoAttachmentsError] if no attachments present
|
73
|
+
# @return [Array] attachments
|
74
|
+
|
75
|
+
def mime_part!
|
76
|
+
files = mime_part
|
77
|
+
return files if files.present?
|
78
|
+
|
79
|
+
raise Howitzer::NoAttachmentsError, 'No attachments were found.'
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.find_retry_params(wait)
|
83
|
+
{
|
84
|
+
timeout: wait,
|
85
|
+
sleep: Howitzer.mail_sleep_time,
|
86
|
+
silent: true,
|
87
|
+
logger: Howitzer::Log,
|
88
|
+
on: Howitzer::EmailNotFoundError
|
89
|
+
}
|
90
|
+
end
|
91
|
+
private_class_method :find_retry_params
|
92
|
+
|
93
|
+
def self.retrieve_message(recipient, subject)
|
94
|
+
message = Howitzer::TestmailApi::Client.new.find_message(recipient, subject)
|
95
|
+
raise Howitzer::EmailNotFoundError, 'Message not received yet, retry...' unless message
|
96
|
+
|
97
|
+
message
|
98
|
+
end
|
99
|
+
private_class_method :retrieve_message
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -32,6 +32,24 @@ module Howitzer
|
|
32
32
|
JSON.parse(RestClient.get("#{BASE_URL}/messages/#{message['id']}/attachments", 'Api-Token' => @api_token))
|
33
33
|
end
|
34
34
|
|
35
|
+
def get_html_body(message)
|
36
|
+
RestClient.get("#{BASE_URL}/messages/#{message['id']}/body.html", 'Api-Token' => @api_token).body
|
37
|
+
rescue => e
|
38
|
+
raise Howitzer::CommunicationError, e.message
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_txt_body(message)
|
42
|
+
RestClient.get("#{BASE_URL}/messages/#{message['id']}/body.txt", 'Api-Token' => @api_token).body
|
43
|
+
rescue => e
|
44
|
+
raise Howitzer::CommunicationError, e.message
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_raw_body(message)
|
48
|
+
RestClient.get("#{BASE_URL}/messages/#{message['id']}/body.raw", 'Api-Token' => @api_token).body
|
49
|
+
rescue => e
|
50
|
+
raise Howitzer::CommunicationError, e.message
|
51
|
+
end
|
52
|
+
|
35
53
|
private
|
36
54
|
|
37
55
|
def messages(recipient)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Howitzer
|
5
|
+
module OnesecmailApi
|
6
|
+
# A Onesecmail::Client object is used to communicate with the 1secMail API.
|
7
|
+
class Client
|
8
|
+
BASE_URL = 'https://www.1secmail.com/api/v1/'.freeze # :nodoc:
|
9
|
+
|
10
|
+
# Finds message according to given parameters
|
11
|
+
#
|
12
|
+
# @param recipient [String] this is recipient mail address for message filtering
|
13
|
+
# @param subject [String] this is subject of the message to filter particular message
|
14
|
+
# @return [Hash] json message parsed to ruby hash
|
15
|
+
|
16
|
+
def find_message(recipient, subject)
|
17
|
+
messages = filter_by_subject(recipient[/[^@]+/], subject)
|
18
|
+
latest_message(messages)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def messages(recipient_name)
|
24
|
+
JSON.parse(RestClient.get("#{BASE_URL}?action=getMessages&login=#{recipient_name}" \
|
25
|
+
"&domain=#{Howitzer.onesecmail_domain}"))
|
26
|
+
end
|
27
|
+
|
28
|
+
def latest_message(messages)
|
29
|
+
messages[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
def filter_by_subject(recipient_name, subject)
|
33
|
+
result_messages = []
|
34
|
+
messages(recipient_name).each do |msg|
|
35
|
+
if msg['subject'] == subject
|
36
|
+
result_messages << JSON.parse(RestClient.get("#{BASE_URL}?action=readMessage&login=#{recipient_name}" \
|
37
|
+
"&domain=#{Howitzer.onesecmail_domain}&id=#{msg['id']}"))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
result_messages
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Howitzer
|
5
|
+
module TestmailApi
|
6
|
+
# A Testmail::Client object is used to communicate with the testmail.app API.
|
7
|
+
class Client
|
8
|
+
BASE_URL = "https://api.testmail.app/api/json?apikey=#{Howitzer.testmail_api_key}" \
|
9
|
+
"&namespace=#{Howitzer.testmail_namespace}".freeze # :nodoc:
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@api_token = Howitzer.testmail_api_key
|
13
|
+
end
|
14
|
+
|
15
|
+
# Finds message according to given parameters
|
16
|
+
#
|
17
|
+
# @param recipient [String] this is recipient mail address for message filtering
|
18
|
+
# @param subject [String] this is subject of the message to filter particular message
|
19
|
+
# @return [Hash] json message parsed to ruby hash
|
20
|
+
|
21
|
+
def find_message(recipient, subject)
|
22
|
+
recipient = recipient.gsub(/.*\.([^@]+)@.*/, '\1')
|
23
|
+
messages = filter_by_subject(messages(recipient), subject)
|
24
|
+
latest_message(messages)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def messages(recipient)
|
30
|
+
JSON.parse(RestClient.get("#{BASE_URL}&tag=#{recipient}"))
|
31
|
+
end
|
32
|
+
|
33
|
+
def latest_message(messages)
|
34
|
+
messages[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
def filter_by_subject(messages, subject)
|
38
|
+
result_messages = []
|
39
|
+
messages['emails'].each { |msg| result_messages << msg if msg['subject'] == subject }
|
40
|
+
result_messages
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/howitzer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: howitzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Parashchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -302,6 +302,8 @@ files:
|
|
302
302
|
- lib/howitzer/mail_adapters/gmail.rb
|
303
303
|
- lib/howitzer/mail_adapters/mailgun.rb
|
304
304
|
- lib/howitzer/mail_adapters/mailtrap.rb
|
305
|
+
- lib/howitzer/mail_adapters/onesecmail.rb
|
306
|
+
- lib/howitzer/mail_adapters/testmail.rb
|
305
307
|
- lib/howitzer/mailgun_api.rb
|
306
308
|
- lib/howitzer/mailgun_api/client.rb
|
307
309
|
- lib/howitzer/mailgun_api/connector.rb
|
@@ -314,7 +316,11 @@ files:
|
|
314
316
|
- lib/howitzer/meta/entry.rb
|
315
317
|
- lib/howitzer/meta/iframe.rb
|
316
318
|
- lib/howitzer/meta/section.rb
|
319
|
+
- lib/howitzer/onesecmail_api.rb
|
320
|
+
- lib/howitzer/onesecmail_api/client.rb
|
317
321
|
- lib/howitzer/tasks/framework.rake
|
322
|
+
- lib/howitzer/testmail_api.rb
|
323
|
+
- lib/howitzer/testmail_api/client.rb
|
318
324
|
- lib/howitzer/utils.rb
|
319
325
|
- lib/howitzer/utils/string_extensions.rb
|
320
326
|
- lib/howitzer/version.rb
|
@@ -336,7 +342,7 @@ licenses:
|
|
336
342
|
metadata:
|
337
343
|
bug_tracker_uri: https://github.com/strongqa/howitzer/issues
|
338
344
|
changelog_uri: https://github.com/strongqa/howitzer/blob/master/CHANGELOG.md
|
339
|
-
documentation_uri: https://www.rubydoc.info/gems/howitzer/2.
|
345
|
+
documentation_uri: https://www.rubydoc.info/gems/howitzer/2.5.0
|
340
346
|
source_code_uri: https://github.com/strongqa/howitzer
|
341
347
|
rubygems_mfa_required: 'false'
|
342
348
|
post_install_message:
|