Class: MailRoom::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_room/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(mailbox) ⇒ Connection

Returns a new instance of Connection.


3
4
5
6
7
8
9
# File 'lib/mail_room/connection.rb', line 3

def initialize(mailbox)
  @mailbox = mailbox

  # log in and set the mailbox
  reset
  setup
end

Instance Method Details

#disconnected?Boolean

is the imap connection closed?

Returns:

  • (Boolean)

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

def disconnected?
  @imap.disconnected?
end

#idling?Boolean

is the connection blocked idling?

Returns:

  • (Boolean)

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

def idling?
  @idling
end

#logged_in?Boolean

is the connection logged in?

Returns:

  • (Boolean)

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

def logged_in?
  @logged_in
end

#on_new_message(&block) ⇒ Object


11
12
13
# File 'lib/mail_room/connection.rb', line 11

def on_new_message(&block)
  @new_message_handler = block
end

#quitObject


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

def quit
  stop_idling
  reset
end

#ready_to_idle?Boolean

is the connection ready to idle?

Returns:

  • (Boolean)

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

def ready_to_idle?
  logged_in? && !idling?
end

#waitObject


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

def wait
  begin
    # in case we missed any between idles
    process_mailbox

    idle

    process_mailbox
  rescue Net::IMAP::Error, IOError
    @mailbox.logger.warn({ context: @mailbox.context, action: "Disconnected. Resetting..." })
    reset
    setup
  end
end