email - How to check if a mailserver uses SSL for IMAP communication (Ruby) -


i have service need user give me access email via imap.

i need user_name, password, address , port user.

i need know if imap connection uses ssl (enable_ssl can true or false), , prefer not ask user. because don't know.

is possible make query mailserver see if uses ssl?

my solution far has been try out both options. first try connect ssl, , - if fails - try connect without ssl. mailservers strike out when this, maybe because first failed connection still open reason.

here working (but clumsy) implementation.

require 'net/imap' class imapmailss   def self.test_connection(address, port, enable_ssl, user_name, password)     imap = net::imap.new(address, port, enable_ssl)     imap.login(user_name, password)     flags = imap.list("", "*")   end end  enable_ssl == nil # first try connect ssl begin   true_test = imapmailss.test_connection(address, port, true, user_name, password)   if true_test.class.to_s == "array" # if mailserver allows me access array of folders e.g.: [#<struct net::imap::mailboxlist attr=[:hasnochildren], delim="/", name="feedback requests">, #<struct net::imap::mailboxlist attr=[:hasnochildren], delim="/", name="inbox">, #<struct net::imap::mailboxlist attr=[:haschildren, :noselect], delim="/", name="[gmail]">, #<struct net::imap::mailboxlist attr=[:hasnochildren, :sent], delim="/", name="[gmail]/sent mail">]     enable_ssl   = true   end rescue => e   true_error = e end  # try connect without ssl if enable_ssl == nil   begin     false_test = imapmails.test_connection(address, port, false, user_name, password)   if false_test.class.to_s == "array"     enable_ssl   = false   end   rescue => e     false_error = e   end end 


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -