Class: Imap::Backup::Account::Folder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/imap/backup/account/folder.rb

Constant Summary collapse

REQUESTED_ATTRIBUTES =
['RFC822', 'FLAGS', 'INTERNALDATE']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, name) ⇒ Folder

Returns a new instance of Folder.



17
18
19
20
# File 'lib/imap/backup/account/folder.rb', line 17

def initialize(connection, name)
  @connection = connection
  @name = name
end

Instance Attribute Details

#connection ⇒ Object (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/imap/backup/account/folder.rb', line 12

def connection
  @connection
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/imap/backup/account/folder.rb', line 13

def name
  @name
end

Instance Method Details

#fetch(uid) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/imap/backup/account/folder.rb', line 34

def fetch(uid)
  imap.examine(name)
  message = imap.uid_fetch([uid.to_i], REQUESTED_ATTRIBUTES)[0][1]
  message['RFC822'].force_encoding('utf-8') if RUBY_VERSION > '1.9'
  message
rescue Net::IMAP::NoResponseError => e
  Imap::Backup.logger.warn "Folder '#{name}' does not exist"
  nil
end

#folder ⇒ Object



22
23
24
# File 'lib/imap/backup/account/folder.rb', line 22

def folder
  name
end

#uids ⇒ Object



26
27
28
29
30
31
32
# File 'lib/imap/backup/account/folder.rb', line 26

def uids
  imap.examine(name)
  imap.uid_search(['ALL']).sort
rescue Net::IMAP::NoResponseError => e
  Imap::Backup.logger.warn "Folder '#{name}' does not exist"
  []
end