email-verification 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7f15443c9ec1e533893b1eb3a32775b2fbc3ab0c98c7a79d8b48a30c5cf6600
4
- data.tar.gz: d513f67f6824f045487e8783d13db9dbf5ffea4605ab689dbb8e64a7cf302c07
3
+ metadata.gz: 280d7dfab6e3eb5b6f4fe8aa6e95423d19f6f7a0fc575c42b8c357d113ea4801
4
+ data.tar.gz: 53805c28a691d7285c7c12c05be4f14e46328829c46a501e9954a4b14dc6f81b
5
5
  SHA512:
6
- metadata.gz: 9bc77e4d23247da0cb79006e16b0bcd93d5aaf591ba97c3cb0801dbc2676fdeddb3796078f00339ae9c140c898bb72a14cf1f8ce1ba7f3271746ae2774b5af0a
7
- data.tar.gz: aa20717ebbbc67c2bd56c23af65b3576ffd8dd2216f0627ac73b9e4ac7c51055208d8c4841c538006e2c3f8b1740b7f0f0fd149ddc08ffb1cf82c43e093efaa8
6
+ metadata.gz: 6813e1ef4ae7155ea78180943982d5f1acf775d3612ed32ebde9c6fa7abc94558ad71d5acc4c1ff9617cff00ba589f8b8d4cfce561b446b4d0e3834a838e07e2
7
+ data.tar.gz: 1b3d4bd66d845ba96cc4c53c0c3fc0708adb730189acf3197c5415fe513a7c03cb55a53e664203a3bc1f088f7195a5aaa18e94c2731c4eeb238b66db73af3409
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- email-verification (0.1.9)
4
+ email-verification (0.2.0)
5
5
  gmail (~> 0.7.1)
6
6
  highline (~> 2.0, >= 2.0.2)
7
+ net-imap-proxy (~> 0.1.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -20,7 +21,10 @@ GEM
20
21
  mini_mime (>= 0.1.1)
21
22
  method_source (0.9.2)
22
23
  mini_mime (1.0.2)
24
+ net-imap-proxy (0.1.0)
25
+ proxifier (~> 1.0, >= 1.0.3)
23
26
  oauth (0.5.4)
27
+ proxifier (1.0.3)
24
28
  pry (0.12.2)
25
29
  coderay (~> 1.1.0)
26
30
  method_source (~> 0.9.0)
data/README.md CHANGED
@@ -27,7 +27,7 @@ Email::Verification expects a settings hash in the following format:
27
27
  ```ruby
28
28
  settings = {
29
29
  address: "confirmation@foo.com",
30
- from: "Confirmation",
30
+ from: "Confirmation", # Optional
31
31
  subject: /Confirm your email!/i,
32
32
  regex: /<a href=['"](?<match>[^"]*)['"]>\s*Click here\s*<\/a>/i
33
33
  }
@@ -41,6 +41,18 @@ Then the client is invoked using:
41
41
  Email::Verification.retrieve_verification_code(email: 'email.address@gmail.com', password: 's0mEpasSwOrD', settings: settings)
42
42
  ```
43
43
 
44
+ ### Proxy support
45
+
46
+ Email::Verification can also be used together with proxies to fetch IMAP messages.
47
+
48
+ Simply provide a hash { host: "http://someproxyhost.com", port: 8080 } to the retrieve_verification_code method:
49
+
50
+ ```ruby
51
+ Email::Verification.retrieve_verification_code(email: 'email.address@gmail.com', password: 's0mEpasSwOrD', settings: settings, proxy: {host: "http://someproxyhost.com", port: 8080})
52
+ ```
53
+
54
+ Proxy authentication is also supported using the format {host: "http://user:password@someproxyhost.com", port: 8080}
55
+
44
56
  ## Development
45
57
 
46
58
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
 
37
37
  spec.add_dependency "gmail", "~> 0.7.1"
38
38
  spec.add_dependency "highline", "~> 2.0", ">= 2.0.2"
39
+ spec.add_dependency "net-imap-proxy", "~> 0.1.0"
39
40
 
40
41
  spec.add_development_dependency "bundler", "~> 1.17"
41
42
  spec.add_development_dependency "rake", "~> 10.0"
@@ -7,19 +7,36 @@ module Email
7
7
  self.configuration = configuration
8
8
  end
9
9
 
10
- def retrieve_verification_code(email:, password:, host:, port: 993, enable_ssl: true, count: :all, mailboxes: %w(Inbox), settings: {})
10
+ def set_retriever(email:, password:, host:, port: 993, enable_ssl: true, proxy: nil)
11
+ retriever = :imap
12
+
13
+ options = {
14
+ address: host,
15
+ port: port,
16
+ user_name: email,
17
+ password: password,
18
+ enable_ssl: enable_ssl
19
+ }
20
+
21
+ if proxy && !proxy.empty? && !proxy[:host].to_s.empty? && !proxy[:port].to_s.empty?
22
+ retriever = ::Net::IMAP::Proxy::RetrieverMethod
23
+ proxy[:host] = "http://#{proxy[:host]}" unless proxy[:host] =~ /^http(s)?:\/\//i
24
+ options = options.merge(proxy_address: proxy[:host], proxy_port: proxy[:port])
25
+ log("Using proxy #{proxy[:host]}:#{proxy[:port]} to fetch messages from #{options[:address]}:#{options[:port]}")
26
+ end
27
+
28
+ Mail.defaults do
29
+ retriever_method retriever, options
30
+ end
31
+ end
32
+
33
+ def retrieve_verification_code(email:, password:, host:, port: 993, enable_ssl: true, count: :all, mailboxes: %w(Inbox), settings: {}, proxy: nil)
11
34
  emails = []
12
35
  result = nil
13
36
 
14
37
  begin
15
- Mail.defaults do
16
- retriever_method :imap, address: host,
17
- port: port,
18
- user_name: email,
19
- password: password,
20
- enable_ssl: enable_ssl
21
- end
22
-
38
+ set_retriever(email: email, password: password, host: host, port: port, enable_ssl: enable_ssl, proxy: proxy)
39
+
23
40
  mailboxes.each do |mailbox|
24
41
  Mail.find(mailbox: mailbox, order: :desc, count: count)&.each do |email|
25
42
  log("From: #{email.from&.first&.strip}. Subject: #{email.subject}")
@@ -2,7 +2,15 @@ module Email
2
2
  module Verification
3
3
  class Gmail < Base
4
4
 
5
- def retrieve_verification_code(email:, password:, mark_as_read: true, count: :all, mailboxes: %w(Inbox), settings: {})
5
+ def retrieve_verification_code(email:, password:, mark_as_read: true, count: :all, mailboxes: %w(Inbox), settings: {}, proxy: nil)
6
+ if proxy && !proxy.empty? && !proxy[:host].to_s.empty? && !proxy[:port].to_s.empty?
7
+ return super(email: email, password: password, host: "imap.gmail.com", port: 993, enable_ssl: true, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy)
8
+ else
9
+ return normal_retrieve_verification_code(email: email, password: password, mark_as_read: mark_as_read, count: count, mailboxes: mailboxes, settings: settings)
10
+ end
11
+ end
12
+
13
+ def normal_retrieve_verification_code(email:, password:, mark_as_read: true, count: :all, mailboxes: %w(Inbox), settings: {})
6
14
  emails = []
7
15
  result = nil
8
16
 
@@ -2,8 +2,8 @@ module Email
2
2
  module Verification
3
3
  class Hotmail < Base
4
4
 
5
- def retrieve_verification_code(email:, password:, mailboxes: %w(Inbox Junk), count: :all, settings: {})
6
- super(email: email, password: password, host: "outlook.office365.com", port: 993, enable_ssl: true, mailboxes: mailboxes, count: count, settings: settings)
5
+ def retrieve_verification_code(email:, password:, mailboxes: %w(Inbox Junk), count: :all, settings: {}, proxy: nil)
6
+ super(email: email, password: password, host: "outlook.office365.com", port: 993, enable_ssl: true, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy)
7
7
  end
8
8
 
9
9
  end
@@ -18,14 +18,14 @@ module Email
18
18
  end
19
19
  end
20
20
 
21
- def retrieve_verification_code(email:, password:, mailboxes: %w(Inbox), count: :all, settings: {}, wait: 3, retries: 3)
21
+ def retrieve_verification_code(email:, password:, mailboxes: %w(Inbox), count: :all, settings: {}, proxy: nil, wait: 3, retries: 3)
22
22
  service = determine_email_service(email)
23
23
 
24
24
  result = case service
25
25
  when :gmail
26
- perform_retrieval(::Email::Verification::Gmail.new, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, wait: wait, retries: retries)
26
+ perform_retrieval(::Email::Verification::Gmail.new, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy, wait: wait, retries: retries)
27
27
  when :hotmail
28
- perform_retrieval(::Email::Verification::Hotmail.new, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, wait: wait, retries: retries)
28
+ perform_retrieval(::Email::Verification::Hotmail.new, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy, wait: wait, retries: retries)
29
29
  when :protonmail, :tutanota
30
30
  if self.mode.eql?(:interactive)
31
31
  puts "[Email::Verification::Verifier] - #{Time.now}: You're using an email account that doesn't have support for POP3 or IMAP. You have to manually retrieve the code or URL from the account and post it below."
@@ -40,7 +40,7 @@ module Email
40
40
  return result
41
41
  end
42
42
 
43
- def perform_retrieval(verifier, email:, password: nil, mailboxes: %w(Inbox), count: :all, settings: {}, wait: 3, retries: 3)
43
+ def perform_retrieval(verifier, email:, password: nil, mailboxes: %w(Inbox), count: :all, settings: {}, proxy: nil, wait: 3, retries: 3)
44
44
  result = nil
45
45
 
46
46
  if password.to_s.empty? && self.mode.eql?(:interactive)
@@ -50,20 +50,20 @@ module Email
50
50
  raise ::Email::Verification::Errors::InvalidCredentialsError.new("Password wasn't provided for #{email} and automatic mode is enabled. Please provide a password or switch to interactive mode.")
51
51
  else
52
52
  if settings_provided?(settings) && !wait.nil? && !retries.nil?
53
- result = retrieve_with_retries(verifier, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, wait: wait, retries: retries)
53
+ result = retrieve_with_retries(verifier, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy, wait: wait, retries: retries)
54
54
  else
55
- result = verifier.retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, count: count, settings: settings)
55
+ result = verifier.retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy)
56
56
  end
57
57
  end
58
58
 
59
59
  return result
60
60
  end
61
61
 
62
- def retrieve_with_retries(verifier, email:, password: nil, mailboxes: %w(Inbox), count: :all, settings: {}, wait: 3, retries: 3)
62
+ def retrieve_with_retries(verifier, email:, password: nil, mailboxes: %w(Inbox), count: :all, settings: {}, proxy: nil, wait: 3, retries: 3)
63
63
  result = nil
64
64
 
65
65
  begin
66
- result = verifier.retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, count: count, settings: settings)
66
+ result = verifier.retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, proxy: proxy)
67
67
 
68
68
  if result.to_s.empty?
69
69
  sleep wait if wait
@@ -1,5 +1,5 @@
1
1
  module Email
2
2
  module Verification
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -3,6 +3,8 @@ require "mail"
3
3
  require "yaml"
4
4
  require "highline"
5
5
 
6
+ require "net/imap/proxy"
7
+
6
8
  require "email/verification/version"
7
9
 
8
10
  require "email/verification/configuration"
@@ -35,8 +37,8 @@ module Email
35
37
  yield(configuration)
36
38
  end
37
39
 
38
- def self.retrieve_verification_code(email:, password: nil, mailboxes: %w(Inbox), settings: {}, mode: :interactive)
39
- ::Email::Verification::Verifier.new(mode: mode).retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, settings: settings)
40
+ def self.retrieve_verification_code(email:, password: nil, mailboxes: %w(Inbox), settings: {}, mode: :interactive, proxy: nil)
41
+ ::Email::Verification::Verifier.new(mode: mode).retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, settings: settings, proxy: proxy)
40
42
  end
41
43
 
42
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email-verification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Johnsson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-13 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gmail
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.0.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: net-imap-proxy
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.0
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: bundler
49
63
  requirement: !ruby/object:Gem::Requirement