Class: Imap::Backup::Account::Folder
- Inherits:
-
Object
- Object
- Imap::Backup::Account::Folder
- Extended by:
- Forwardable
- Includes:
- RetryOnError
- Defined in:
- lib/imap/backup/account/folder.rb
Constant Summary collapse
- BODY_ATTRIBUTE =
"BODY[]".freeze
- UID_FETCH_RETRY_CLASSES =
[EOFError].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
- #fetch_multi(uids) ⇒ Object
-
#folder ⇒ Object
Deprecated: use #name.
-
#initialize(connection, name) ⇒ Folder
constructor
A new instance of Folder.
- #uid_validity ⇒ Object
- #uids ⇒ Object
Methods included from RetryOnError
Constructor Details
#initialize(connection, name) ⇒ Folder
Returns a new instance of Folder.
22 23 24 25 26 |
# File 'lib/imap/backup/account/folder.rb', line 22 def initialize(connection, name) @connection = connection @name = name @uid_validity = nil end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
17 18 19 |
# File 'lib/imap/backup/account/folder.rb', line 17 def connection @connection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/imap/backup/account/folder.rb', line 18 def name @name end |
Instance Method Details
#append(message) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/imap/backup/account/folder.rb', line 107 def append() body = .imap_body date = .date&.to_time response = client.append(utf7_encoded_name, body, nil, date) extract_uid(response) end |
#create ⇒ Object
40 41 42 43 44 |
# File 'lib/imap/backup/account/folder.rb', line 40 def create return if exist? client.create(utf7_encoded_name) end |
#exist? ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/imap/backup/account/folder.rb', line 33 def exist? examine true rescue FolderNotFound false end |
#fetch(uid) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/imap/backup/account/folder.rb', line 71 def fetch(uid) examine fetch_data_items = retry_on_error(errors: UID_FETCH_RETRY_CLASSES) do client.uid_fetch([uid.to_i], [BODY_ATTRIBUTE]) end return nil if fetch_data_items.nil? fetch_data_item = fetch_data_items[0] attributes = fetch_data_item.attr attributes[BODY_ATTRIBUTE] rescue FolderNotFound nil end |
#fetch_multi(uids) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/imap/backup/account/folder.rb', line 87 def fetch_multi(uids) examine fetch_data_items = retry_on_error(errors: UID_FETCH_RETRY_CLASSES) do client.uid_fetch(uids, [BODY_ATTRIBUTE]) end return nil if fetch_data_items.nil? fetch_data_items.map do |item| attributes = item.attr { uid: attributes["UID"], body: attributes[BODY_ATTRIBUTE] } end rescue FolderNotFound nil end |
#folder ⇒ Object
Deprecated: use #name
29 30 31 |
# File 'lib/imap/backup/account/folder.rb', line 29 def folder name end |
#uid_validity ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/imap/backup/account/folder.rb', line 46 def uid_validity @uid_validity ||= begin examine client.responses["UIDVALIDITY"][-1] end end |
#uids ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/imap/backup/account/folder.rb', line 54 def uids examine client.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.logger.warn [] end |