Class: MailRoom::IMAP::Connection

Inherits:
Connection show all
Defined in:
lib/mail_room/imap/connection.rb

Instance Attribute Summary

Attributes inherited from Connection

#mailbox, #new_message_handler

Instance Method Summary collapse

Methods inherited from Connection

#on_new_message, #stopped?

Constructor Details

#initialize(mailbox) ⇒ Connection

Returns a new instance of Connection.


6
7
8
9
10
11
12
# File 'lib/mail_room/imap/connection.rb', line 6

def initialize(mailbox)
  super

  # log in and set the mailbox
  reset
  setup
end

Instance Method Details

#disconnected?Boolean

is the imap connection closed?

Returns:

  • (Boolean)

28
29
30
# File 'lib/mail_room/imap/connection.rb', line 28

def disconnected?
  imap.disconnected?
end

#idling?Boolean

is the connection blocked idling?

Returns:

  • (Boolean)

22
23
24
# File 'lib/mail_room/imap/connection.rb', line 22

def idling?
  @idling
end

#logged_in?Boolean

is the connection logged in?

Returns:

  • (Boolean)

16
17
18
# File 'lib/mail_room/imap/connection.rb', line 16

def logged_in?
  @logged_in
end

#quitObject


38
39
40
41
# File 'lib/mail_room/imap/connection.rb', line 38

def quit
  stop_idling
  reset
end

#ready_to_idle?Boolean

is the connection ready to idle?

Returns:

  • (Boolean)

34
35
36
# File 'lib/mail_room/imap/connection.rb', line 34

def ready_to_idle?
  logged_in? && !idling?
end

#waitObject


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mail_room/imap/connection.rb', line 43

def wait
  # in case we missed any between idles
  process_mailbox

  idle

  process_mailbox
rescue Net::IMAP::Error, IOError => e
  @mailbox.logger.warn({ context: @mailbox.context, action: 'Disconnected. Resetting...', error: e.message })
  reset
  setup
end