Class: Catfriend::ImapServer

Inherits:
Object
  • Object
show all
Includes:
AccessorsFromHash, Thread, Events::Emitter
Defined in:
lib/catfriend/imap.rb

Overview

This class represents a thread capable of checking and creating notifications for a single mailbox on a single IMAP server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Thread

#join, #start, #stopped?

Constructor Details

#initialize(args = nil) ⇒ ImapServer

Create new IMAP server with optional full configuration hash. If the hash is not supplied at construction a further call must be made to #configure before #start is called to start the thread.



27
28
29
# File 'lib/catfriend/imap.rb', line 27

def initialize(args = nil)
  configure args if args
end

Instance Attribute Details

#cert_file=(value) ⇒ Object (writeonly)

Sets the attribute cert_file

Parameters:

  • value

    the value to set the attribute cert_file to.



178
179
180
# File 'lib/catfriend/imap.rb', line 178

def cert_file=(value)
  @cert_file = value
end

#host=(value) ⇒ Object (writeonly)

Sets the attribute host

Parameters:

  • value

    the value to set the attribute host to.



178
179
180
# File 'lib/catfriend/imap.rb', line 178

def host=(value)
  @host = value
end

#idObject

The id is a token which represents this server when displaying notifications and is set to the host unless over-ridden by the configuration file



44
# File 'lib/catfriend/imap.rb', line 44

def id ; @id || @host ; end

#mailbox=(value) ⇒ Object (writeonly)

Sets the attribute mailbox

Parameters:

  • value

    the value to set the attribute mailbox to.



178
179
180
# File 'lib/catfriend/imap.rb', line 178

def mailbox=(value)
  @mailbox = value
end

#no_ssl=(value) ⇒ Object (writeonly)

Sets the attribute no_ssl

Parameters:

  • value

    the value to set the attribute no_ssl to.



178
179
180
# File 'lib/catfriend/imap.rb', line 178

def no_ssl=(value)
  @no_ssl = value
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



178
179
180
# File 'lib/catfriend/imap.rb', line 178

def password=(value)
  @password = value
end

#user=(value) ⇒ Object (writeonly)

Sets the attribute user

Parameters:

  • value

    the value to set the attribute user to.



178
179
180
# File 'lib/catfriend/imap.rb', line 178

def user=(value)
  @user = value
end

#work_accountObject

Returns the value of attribute work_account.



179
180
181
# File 'lib/catfriend/imap.rb', line 179

def 
  @work_account
end

Instance Method Details

#configure(args) ⇒ Object

Configure all attributes based on hash then make sure this represents a total valid configuration.

Raises:



33
34
35
36
37
38
39
# File 'lib/catfriend/imap.rb', line 33

def configure args
  super args

  raise ConfigError, "imap user not set" unless @user
  raise ConfigError, "imap host not set" unless @host
  raise ConfigError, "imap password not set" unless @password
end

#disconnectObject



171
172
173
174
# File 'lib/catfriend/imap.rb', line 171

def disconnect
  @stopping = true
  @imap.disconnect
end

#get_unseen_countObject

Ask IMAP server for count of unseen messages.



129
130
131
132
133
134
135
136
137
# File 'lib/catfriend/imap.rb', line 129

def get_unseen_count
  begin
    # fetch raises an exception when the mailbox is empty
    @imap.status(@mailbox || "INBOX", ["UNSEEN"])["UNSEEN"]
  rescue => e
    error "failed to get count of unseen messages"
    0
  end
end

#killObject

Disconnect from the imap server and stop the associated thread.



123
124
125
126
# File 'lib/catfriend/imap.rb', line 123

def kill
  disconnect
  super
end

#stopping?Boolean

Returns false until kill/disconnect have been called.

Returns:

  • (Boolean)


118
119
120
# File 'lib/catfriend/imap.rb', line 118

def stopping?
  stopped? or @stopping
end