dsiemailhelper 0.0.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 +7 -0
- data/lib/dsiemailhelper.rb +69 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a54b0021f6a6a02452513928c7a2a26444ba7d214b38fb4d56cd1093f1daf498
|
|
4
|
+
data.tar.gz: 46ecf68e572bae394726c72359aa7fc38ed2dfdfa926f1a5aa1e9338ab200872
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fa1b22f5e64d88427a1a40bd44441a5ae194f8c8e07511a4c89ea6216db4a10c3f5de35d216a9aed88bbe197cf87958d1ecf38e50676df47eabe929c189f6abd
|
|
7
|
+
data.tar.gz: 86ff6efdeeb69f59a4258d21902da2b1caf7ce3da4ade1e008d6bec5aa7587a54008d19f06881e1e9f75aed499413f4d6d87fe5924f4c705a5da40407decc774
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'timeout'
|
|
2
|
+
require 'gmail'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module DSIEmailHelper
|
|
6
|
+
|
|
7
|
+
HTTPS_REGEXP = /https?:\/\/[\S]+/
|
|
8
|
+
|
|
9
|
+
def self.connect
|
|
10
|
+
# using connect! because only it will throw an exception if an error occurs
|
|
11
|
+
# during the connection process with gmail
|
|
12
|
+
raise "Please ensure QA_INBOX_EMAIL and QA_INBOX_PASSWORD env vars are configured" unless ENV['QA_INBOX_EMAIL'] && ENV['QA_INBOX_PASSWORD']
|
|
13
|
+
@inbox = Gmail.connect!(ENV['QA_INBOX_EMAIL'], ENV['QA_INBOX_PASSWORD'])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.get_all_emails
|
|
17
|
+
# returns an array of Message objects
|
|
18
|
+
@inbox.inbox.emails
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.find_email_by_gmail_search(search_string, start_time, acceptable_offset=0)
|
|
22
|
+
message = nil
|
|
23
|
+
Timeout.timeout(120) do
|
|
24
|
+
while filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset).length < 1
|
|
25
|
+
sleep 0.5
|
|
26
|
+
end
|
|
27
|
+
message = filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset)[-1]
|
|
28
|
+
message
|
|
29
|
+
end
|
|
30
|
+
rescue Timeout::Error => e
|
|
31
|
+
puts "Search string passed: #{search_string}"
|
|
32
|
+
puts "Start time passed: #{start_time} (offset: #{acceptable_offset})."
|
|
33
|
+
puts "Messages matching search string: #{@inbox.inbox.find(gm: search_string)}"
|
|
34
|
+
puts "Message: #{message || @inbox.inbox.find(gm: search_string)}"
|
|
35
|
+
raise e
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.filter_messages_by_time(messages, time, acceptable_offset=0)
|
|
39
|
+
messages.delete_if { | message |
|
|
40
|
+
message.message.date.to_time.to_f <= time.to_time.round.to_f - acceptable_offset
|
|
41
|
+
}
|
|
42
|
+
messages
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.get_email_body(message)
|
|
46
|
+
# expects a Message object and returns the body of the email without encoding
|
|
47
|
+
message.text_part.body.decoded
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.parse_link_from_body(decoded_message)
|
|
51
|
+
decoded_message.scan(HTTPS_REGEXP)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.get_most_recent_email
|
|
55
|
+
# Noticed the most recent email in the inbox folder always has the highest index,
|
|
56
|
+
# so we can use the size of the array to determine what the most recent message is
|
|
57
|
+
messages = get_all_emails
|
|
58
|
+
messages[messages.length - 1]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.get_newest_password_reset_link(email)
|
|
62
|
+
message = find_email_by_gmail_search("subject: Update Your Password to: #{email}", Date.today)
|
|
63
|
+
body = get_email_body(message)
|
|
64
|
+
# TODO: Archiving doesn't seem to be working, need to look into why
|
|
65
|
+
message.delete!
|
|
66
|
+
parse_link_from_body(body)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dsiemailhelper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bilal Hussein
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Wrapper to slightly simplify interactions with gmail
|
|
14
|
+
email: bilal.hussein@daysmart.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/dsiemailhelper.rb
|
|
20
|
+
homepage: http://www.daysmart.com
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.0.2
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: DSI Email Helper
|
|
43
|
+
test_files: []
|