Class: Catfriend::ImapServer
- Inherits:
-
Object
- Object
- Catfriend::ImapServer
- 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
-
#cert_file ⇒ Object
writeonly
Sets the attribute cert_file.
-
#host ⇒ Object
writeonly
Sets the attribute host.
-
#id ⇒ Object
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.
-
#mailbox ⇒ Object
writeonly
Sets the attribute mailbox.
-
#no_ssl ⇒ Object
writeonly
Sets the attribute no_ssl.
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#user ⇒ Object
writeonly
Sets the attribute user.
-
#work_account ⇒ Object
Returns the value of attribute work_account.
Instance Method Summary collapse
-
#configure(args) ⇒ Object
Configure all attributes based on hash then make sure this represents a total valid configuration.
- #disconnect ⇒ Object
-
#get_unseen_count ⇒ Object
Ask IMAP server for count of unseen messages.
-
#initialize(args = nil) ⇒ ImapServer
constructor
Create new IMAP server with optional full configuration hash.
-
#kill ⇒ Object
Disconnect from the imap server and stop the associated thread.
-
#stopping? ⇒ Boolean
Returns false until kill/disconnect have been called.
Methods included from Thread
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
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
178 179 180 |
# File 'lib/catfriend/imap.rb', line 178 def host=(value) @host = value end |
#id ⇒ Object
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
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
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
178 179 180 |
# File 'lib/catfriend/imap.rb', line 178 def password=(value) @password = value end |
#user=(value) ⇒ Object (writeonly)
Sets the attribute user
178 179 180 |
# File 'lib/catfriend/imap.rb', line 178 def user=(value) @user = value end |
#work_account ⇒ Object
Returns the value of attribute work_account.
179 180 181 |
# File 'lib/catfriend/imap.rb', line 179 def work_account @work_account end |
Instance Method Details
#configure(args) ⇒ Object
Configure all attributes based on hash then make sure this represents a total valid configuration.
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 |
#disconnect ⇒ Object
171 172 173 174 |
# File 'lib/catfriend/imap.rb', line 171 def disconnect @stopping = true @imap.disconnect end |
#get_unseen_count ⇒ Object
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 |
#kill ⇒ Object
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.
118 119 120 |
# File 'lib/catfriend/imap.rb', line 118 def stopping? stopped? or @stopping end |