email-verification 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cafa6a875dafeb9ca51dba2da2f099c7f543bed34ecc933f26009bb5647c53f
4
- data.tar.gz: 7abe43cef996eac4b977d4848bb561ea93a57fee80af97e03b8399a1eb098916
3
+ metadata.gz: b7f15443c9ec1e533893b1eb3a32775b2fbc3ab0c98c7a79d8b48a30c5cf6600
4
+ data.tar.gz: d513f67f6824f045487e8783d13db9dbf5ffea4605ab689dbb8e64a7cf302c07
5
5
  SHA512:
6
- metadata.gz: 0bfef6b3de29a8644c955721c9fc7627011b1eaf3ccfc791bdf89b064acb0bb1bf41de97c92876ebfd8289a6c33db7e6500c29955d4265b02df7824435db04ce
7
- data.tar.gz: aa79c4d837a23790f67f2a907d13d4fe4f48ba3d0e573e3bd2f8b09dbca9c65162da04090e00e53d8bb7316d1530d1af6158317299d8d075b38aa6f3067c00f4
6
+ metadata.gz: 9bc77e4d23247da0cb79006e16b0bcd93d5aaf591ba97c3cb0801dbc2676fdeddb3796078f00339ae9c140c898bb72a14cf1f8ce1ba7f3271746ae2774b5af0a
7
+ data.tar.gz: aa20717ebbbc67c2bd56c23af65b3576ffd8dd2216f0627ac73b9e4ac7c51055208d8c4841c538006e2c3f8b1740b7f0f0fd149ddc08ffb1cf82c43e093efaa8
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  email-verification (0.1.9)
5
5
  gmail (~> 0.7.1)
6
+ highline (~> 2.0, >= 2.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -14,6 +15,7 @@ GEM
14
15
  mail (>= 2.2.1)
15
16
  gmail_xoauth (0.4.2)
16
17
  oauth (>= 0.3.6)
18
+ highline (2.0.2)
17
19
  mail (2.7.1)
18
20
  mini_mime (>= 0.1.1)
19
21
  method_source (0.9.2)
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ["lib"]
36
36
 
37
37
  spec.add_dependency "gmail", "~> 0.7.1"
38
+ spec.add_dependency "highline", "~> 2.0", ">= 2.0.2"
38
39
 
39
40
  spec.add_development_dependency "bundler", "~> 1.17"
40
41
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,6 +1,7 @@
1
1
  require "gmail"
2
2
  require "mail"
3
3
  require "yaml"
4
+ require "highline"
4
5
 
5
6
  require "email/verification/version"
6
7
 
@@ -34,8 +35,8 @@ module Email
34
35
  yield(configuration)
35
36
  end
36
37
 
37
- def self.retrieve_verification_code(email:, password:, mailboxes: %w(Inbox), settings: {})
38
- ::Email::Verification::Verifier.new.retrieve_verification_code(email: email, password: password, mailboxes: mailboxes, settings: settings)
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)
39
40
  end
40
41
 
41
42
  end
@@ -1,5 +1,12 @@
1
1
  gmail:
2
2
  - gmail.com
3
+
4
+ protonmail:
5
+ - protonmail.com
6
+ - protonmail.ch
7
+
8
+ tutanota:
9
+ - tutanota.com
3
10
 
4
11
  hotmail:
5
12
  - hotmail.be
@@ -4,6 +4,7 @@ module Email
4
4
 
5
5
  class Error < StandardError; end
6
6
  class InvalidCredentialsError < Email::Verification::Errors::Error; end
7
+ class ImapNotSupportedError < Email::Verification::Errors::Error; end
7
8
 
8
9
  end
9
10
  end
@@ -1,9 +1,12 @@
1
1
  module Email
2
2
  module Verification
3
3
  class Verifier
4
- attr_accessor :mapping
4
+ attr_accessor :mapping, :mode, :cli
5
5
 
6
- def initialize
6
+ def initialize(mode: :interactive)
7
+ self.mode = mode&.to_sym
8
+ self.cli = self.mode.eql?(:interactive) ? ::HighLine.new : nil
9
+
7
10
  set_mapping
8
11
  end
9
12
 
@@ -16,19 +19,36 @@ module Email
16
19
  end
17
20
 
18
21
  def retrieve_verification_code(email:, password:, mailboxes: %w(Inbox), count: :all, settings: {}, wait: 3, retries: 3)
19
- result = nil
20
22
  service = determine_email_service(email)
21
23
 
22
- verifier = case service
24
+ result = case service
23
25
  when :gmail
24
- ::Email::Verification::Gmail.new
26
+ perform_retrieval(::Email::Verification::Gmail.new, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, wait: wait, retries: retries)
25
27
  when :hotmail
26
- ::Email::Verification::Hotmail.new
28
+ perform_retrieval(::Email::Verification::Hotmail.new, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, wait: wait, retries: retries)
29
+ when :protonmail, :tutanota
30
+ if self.mode.eql?(:interactive)
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."
32
+ capture_cli_input(email)
33
+ else
34
+ raise ::Email::Verification::Errors::ImapNotSupportedError.new("#{service} doesn't have support for IMAP or POP3 retrieval! Please switch to interactive mode or use another provider!")
35
+ end
27
36
  else
28
37
  nil
29
38
  end
30
39
 
31
- if verifier
40
+ return result
41
+ end
42
+
43
+ def perform_retrieval(verifier, email:, password: nil, mailboxes: %w(Inbox), count: :all, settings: {}, wait: 3, retries: 3)
44
+ result = nil
45
+
46
+ if password.to_s.empty? && self.mode.eql?(:interactive)
47
+ puts "[Email::Verification::Verifier] - #{Time.now}: Password wasn't provided, you need to manually retrieve the code or URL from the account #{email}."
48
+ result = capture_cli_input(email)
49
+ elsif password.to_s.empty? && self.mode.eql?(:automatic)
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
+ else
32
52
  if settings_provided?(settings) && !wait.nil? && !retries.nil?
33
53
  result = retrieve_with_retries(verifier, email: email, password: password, mailboxes: mailboxes, count: count, settings: settings, wait: wait, retries: retries)
34
54
  else
@@ -39,7 +59,7 @@ module Email
39
59
  return result
40
60
  end
41
61
 
42
- def retrieve_with_retries(verifier, email:, password:, 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: {}, wait: 3, retries: 3)
43
63
  result = nil
44
64
 
45
65
  begin
@@ -73,6 +93,10 @@ module Email
73
93
  settings && !settings.empty?
74
94
  end
75
95
 
96
+ def capture_cli_input(email)
97
+ self.cli.ask("Please enter the code or URL sent to #{email}:")&.strip
98
+ end
99
+
76
100
  end
77
101
  end
78
102
  end
@@ -1,5 +1,5 @@
1
1
  module Email
2
2
  module Verification
3
- VERSION = "0.1.9"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.9
4
+ version: 0.2.0
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-11 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gmail
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.7.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.2
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: bundler
29
49
  requirement: !ruby/object:Gem::Requirement