lib/dsiemailhelper.rb in dsiemailhelper-0.0.2 vs lib/dsiemailhelper.rb in dsiemailhelper-0.0.3
- old
+ new
@@ -1,12 +1,12 @@
-require "dsiemailhelper/version"
+require_relative "dsiemailhelper/version"
require 'timeout'
require 'gmail'
module DSIEmailHelper
-
+
HTTPS_REGEXP = /https?:\/\/[\S]+/
def self.connect
# using connect! because only it will throw an exception if an error occurs
# during the connection process with gmail
@@ -20,11 +20,12 @@
end
def self.find_email_by_gmail_search(search_string, start_time, acceptable_offset=0)
message = nil
Timeout.timeout(120) do
- while filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset).length < 1
+ while message.nil?
+ message = @inbox
sleep 0.5
end
message = filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset)[-1]
message
end
@@ -63,8 +64,12 @@
message = find_email_by_gmail_search("subject: Update Your Password to: #{email}", Date.today)
body = get_email_body(message)
# TODO: Archiving doesn't seem to be working, need to look into why
message.delete!
parse_link_from_body(body)
+ end
+
+ def self.find_with_filters(*args)
+ @inbox.inbox.find(*args)
end
end