Method: CARPS::IMAP#with_connection

Defined in:
lib/carps/email/imap.rb

#with_connectionObject

Perform an action with an IMAP connection



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/carps/email/imap.rb', line 97

def with_connection
   imap = nil
   begin
      imap = attempt_connection
      yield imap
   rescue Net::IMAP::NoResponseError => e
      if e.message =~ /(A|a)uthentication failed/
         UI::put_error e.message, false
         @password = UI::secret "Enter IMAP password for #{@username}" 
      else
         warn_delay
      end
      UI::put_error e.message, false
   rescue StandardError => e
      warn_delay
      UI::put_error e.message, false
   ensure
      if imap
         imap.logout
         imap.disconnect
      end
   end 
end