Class: Imap::Backup::Account::Folder
- Inherits:
-
Object
- Object
- Imap::Backup::Account::Folder
- Extended by:
- Forwardable
- Defined in:
- lib/imap/backup/account/folder.rb
Constant Summary collapse
- REQUESTED_ATTRIBUTES =
%w[RFC822 FLAGS INTERNALDATE].freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #append(message) ⇒ Object
- #create ⇒ Object
- #exist? ⇒ Boolean
- #fetch(uid) ⇒ Object
-
#folder ⇒ Object
Deprecated: use #name.
-
#initialize(connection, name) ⇒ Folder
constructor
A new instance of Folder.
- #uid_validity ⇒ Object
- #uids ⇒ Object
Constructor Details
#initialize(connection, name) ⇒ Folder
Returns a new instance of Folder.
18 19 20 21 22 |
# File 'lib/imap/backup/account/folder.rb', line 18 def initialize(connection, name) @connection = connection @name = name @uid_validity = nil end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
13 14 15 |
# File 'lib/imap/backup/account/folder.rb', line 13 def connection @connection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/imap/backup/account/folder.rb', line 14 def name @name end |
Instance Method Details
#append(message) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/imap/backup/account/folder.rb', line 81 def append() body = .imap_body date = .date&.to_time response = imap.append(name, body, nil, date) extract_uid(response) end |
#create ⇒ Object
36 37 38 39 40 |
# File 'lib/imap/backup/account/folder.rb', line 36 def create return if exist? imap.create(name) end |
#exist? ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/imap/backup/account/folder.rb', line 29 def exist? examine true rescue FolderNotFound false end |
#fetch(uid) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/imap/backup/account/folder.rb', line 67 def fetch(uid) examine fetch_data_items = imap.uid_fetch([uid.to_i], REQUESTED_ATTRIBUTES) return nil if fetch_data_items.nil? fetch_data_item = fetch_data_items[0] attributes = fetch_data_item.attr return nil if !attributes.key?("RFC822") attributes rescue FolderNotFound nil end |
#folder ⇒ Object
Deprecated: use #name
25 26 27 |
# File 'lib/imap/backup/account/folder.rb', line 25 def folder name end |
#uid_validity ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/imap/backup/account/folder.rb', line 42 def uid_validity @uid_validity ||= begin examine imap.responses["UIDVALIDITY"][-1] end end |
#uids ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/imap/backup/account/folder.rb', line 50 def uids examine imap.uid_search(["ALL"]).sort rescue FolderNotFound [] rescue NoMethodError = <<~MESSAGE Folder '#{name}' caused NoMethodError probably `undefined method `[]' for nil:NilClass (NoMethodError)` in `search_internal` in stdlib net/imap.rb. This is caused by `@responses["SEARCH"] being unset/undefined MESSAGE Imap::Backup.logger.warn [] end |