Class: MailDaemon::Imap::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_daemon/imap/watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Watcher

Returns a new instance of Watcher.



6
7
8
9
# File 'lib/mail_daemon/imap/watcher.rb', line 6

def initialize(options)
  @options = options

end

Instance Method Details

#mailboxObject



37
38
39
# File 'lib/mail_daemon/imap/watcher.rb', line 37

def mailbox
  @options[:mailbox]
end

#restartObject



28
29
30
31
# File 'lib/mail_daemon/imap/watcher.rb', line 28

def restart
  stop
  start
end

#running?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mail_daemon/imap/watcher.rb', line 33

def running?
  @connection.running?
end

#start(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mail_daemon/imap/watcher.rb', line 11

def start(&block)
  
  @connection = Imap::Connection.new(@options, &block)
  @connection.
  # @thread = Thread.new do
    @connection.wait_for_messages do |message|
      yield :type => "incoming_email", :mailbox => @options, :inbound_message => message
    end
  # end
  # @thread.join
end

#stopObject



23
24
25
26
# File 'lib/mail_daemon/imap/watcher.rb', line 23

def stop
  @connection.disconnect
  # @thread.terminate
end