Class: Imap::Backup::Account
- Inherits:
-
Object
- Object
- Imap::Backup::Account
- Defined in:
- lib/imap/backup/account.rb,
lib/imap/backup/account/backup.rb,
lib/imap/backup/account/folder.rb,
lib/imap/backup/account/restore.rb,
lib/imap/backup/account/folder_backup.rb,
lib/imap/backup/account/backup_folders.rb,
lib/imap/backup/account/client_factory.rb,
lib/imap/backup/account/folder_ensurer.rb,
lib/imap/backup/account/serialized_folders.rb,
lib/imap/backup/account/local_only_folder_deleter.rb
Overview
Contains the attributes relating to an email account.
Defined Under Namespace
Classes: Backup, BackupFolders, ClientFactory, Folder, FolderBackup, FolderEnsurer, LocalOnlyFolderDeleter, Restore, SerializedFolders
Constant Summary collapse
- DEFAULT_MULTI_FETCH_SIZE =
By default, the backup process fetches one email at a time
1
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Tracks changes to the Account’s attributes.
-
#connection_options ⇒ Hash, void
Extra options to be passed to the IMAP server when connecting.
-
#download_strategy ⇒ String
The name of the download strategy to adopt during backups.
-
#folder_blacklist ⇒ Boolean
Indicates whether the configured folders are a whitelist or a blacklist.
- #folders ⇒ Object
-
#local_path ⇒ String
The path where backups will be saved.
-
#mirror_mode ⇒ Object
Should all emails be backed up progressively, or should emails which are deleted from the server be deleted locally?.
-
#password ⇒ Object
The password of the Account.
-
#reset_seen_flags_after_fetch ⇒ Boolean
Should ‘Seen’ flags be cached before fetchiong emails and rewritten to the server afterwards?.
-
#server ⇒ String
The address of the IMAP server.
-
#username ⇒ String
The username of the account (usually the same as the email address).
Instance Method Summary collapse
-
#capabilities ⇒ Array<String>
Returns the capabilites of the IMAP server.
-
#clear_changes ⇒ Object
Resets the store of changes, indicating that the current state is the saved state.
-
#client ⇒ Account::Client::Default
Initializes a client for the account’s IMAP server.
-
#initialize(options) ⇒ Account
constructor
A new instance of Account.
-
#mark_for_deletion ⇒ void
Sets a flag indicating the Account should be excluded from the next save operation.
-
#marked_for_deletion? ⇒ Boolean
Indicates whether the account has been flagged for deletion during setup.
- #modified? ⇒ Boolean
-
#multi_fetch_size ⇒ Integer
The number of emails to fetch from the IMAP server at a time.
-
#multi_fetch_size=(value) ⇒ void
Sets the multi_fetch_size attribute and marks it as modified, storing the original value.
-
#namespaces ⇒ Array<String>
Returns the namespaces configured for the account on the IMAP server.
-
#restore ⇒ void
Restore the local backup to the server.
-
#to_h ⇒ Hash
Returns all Account data for serialization.
-
#valid? ⇒ Boolean
Indicates whether the account has been configured, and is ready to be used.
Constructor Details
#initialize(options) ⇒ Account
Returns a new instance of Account.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/imap/backup/account.rb', line 67 def initialize() @username = [:username] @password = [:password] @local_path = [:local_path] @folders = [:folders] @folder_blacklist = [:folder_blacklist] @mirror_mode = [:mirror_mode] @server = [:server] @connection_options = [:connection_options] @download_strategy = [:download_strategy] @multi_fetch_size_orignal = [:multi_fetch_size] @reset_seen_flags_after_fetch = [:reset_seen_flags_after_fetch] @client = nil @changes = {} @marked_for_deletion = false end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Tracks changes to the Account’s attributes
65 66 67 |
# File 'lib/imap/backup/account.rb', line 65 def changes @changes end |
#connection_options ⇒ Hash, void
Extra options to be passed to the IMAP server when connecting
47 48 49 |
# File 'lib/imap/backup/account.rb', line 47 def @connection_options end |
#download_strategy ⇒ String
The name of the download strategy to adopt during backups
50 51 52 |
# File 'lib/imap/backup/account.rb', line 50 def download_strategy @download_strategy end |
#folder_blacklist ⇒ Boolean
Indicates whether the configured folders are a whitelist or a blacklist. When true, any folders attribute will be taken as a list of folders to skip when running backups. When false, the folders attribute is used as the list of folders to backup. If no folders are configured, all folders on the server are backed up irrespective of the folder_blacklist setting
38 39 40 |
# File 'lib/imap/backup/account.rb', line 38 def folder_blacklist @folder_blacklist end |
#folders ⇒ Array<String>, void #folders=(value) ⇒ void
30 31 32 |
# File 'lib/imap/backup/account.rb', line 30 def folders @folders end |
#local_path ⇒ String
The path where backups will be saved
21 22 23 |
# File 'lib/imap/backup/account.rb', line 21 def local_path @local_path end |
#mirror_mode ⇒ Object
Should all emails be backed up progressively, or should emails which are deleted from the server be deleted locally?
41 42 43 |
# File 'lib/imap/backup/account.rb', line 41 def mirror_mode @mirror_mode end |
#password ⇒ Object
The password of the Account
18 19 20 |
# File 'lib/imap/backup/account.rb', line 18 def password @password end |
#reset_seen_flags_after_fetch ⇒ Boolean
Should ‘Seen’ flags be cached before fetchiong emails and rewritten to the server afterwards?
Some IMAP providers, notably Apple Mail, set the ‘Seen’ flag on emails when they are fetched. By setting ‘:reset_seen_flags_after_fetch`, a workaround is activated which checks which emails are ’unseen’ before and after the fetch, and removes the ‘Seen’ flag from those which have changed. As this check is susceptible to ‘race conditions’, i.e. when a different client sets the ‘Seen’ flag while imap-backup is fetching, it is best to only use it when required (i.e. for IMAP providers which always mark messages as ‘Seen’ when accessed).
63 64 65 |
# File 'lib/imap/backup/account.rb', line 63 def reset_seen_flags_after_fetch @reset_seen_flags_after_fetch end |
#server ⇒ String
The address of the IMAP server
44 45 46 |
# File 'lib/imap/backup/account.rb', line 44 def server @server end |
#username ⇒ String
The username of the account (usually the same as the email address)
16 17 18 |
# File 'lib/imap/backup/account.rb', line 16 def username @username end |
Instance Method Details
#capabilities ⇒ Array<String>
Returns the capabilites of the IMAP server
101 102 103 |
# File 'lib/imap/backup/account.rb', line 101 def capabilities client.capability end |
#clear_changes ⇒ Object
Resets the store of changes, indicating that the current state is the saved state
126 127 128 |
# File 'lib/imap/backup/account.rb', line 126 def clear_changes @changes = {} end |
#client ⇒ Account::Client::Default
Initializes a client for the account’s IMAP server
87 88 89 |
# File 'lib/imap/backup/account.rb', line 87 def client @client ||= Account::ClientFactory.new(account: self).run end |
#mark_for_deletion ⇒ void
This method returns an undefined value.
Sets a flag indicating the Account should be excluded from the next save operation
133 134 135 |
# File 'lib/imap/backup/account.rb', line 133 def mark_for_deletion @marked_for_deletion = true end |
#marked_for_deletion? ⇒ Boolean
Indicates whether the account has been flagged for deletion during setup
140 141 142 |
# File 'lib/imap/backup/account.rb', line 140 def marked_for_deletion? @marked_for_deletion end |
#modified? ⇒ Boolean
121 122 123 |
# File 'lib/imap/backup/account.rb', line 121 def modified? changes.any? end |
#multi_fetch_size ⇒ Integer
The number of emails to fetch from the IMAP server at a time
214 215 216 217 218 219 220 221 222 223 |
# File 'lib/imap/backup/account.rb', line 214 def multi_fetch_size @multi_fetch_size ||= begin int = @multi_fetch_size_orignal.to_i if int.positive? int else DEFAULT_MULTI_FETCH_SIZE end end end |
#multi_fetch_size=(value) ⇒ void
This method returns an undefined value.
Sets the multi_fetch_size attribute and marks it as modified, storing the original value. If the supplied value is not a positive integer, uses DEFAULT_MULTI_FETCH_SIZE
229 230 231 232 233 |
# File 'lib/imap/backup/account.rb', line 229 def multi_fetch_size=(value) parsed = value.to_i parsed = DEFAULT_MULTI_FETCH_SIZE if !parsed.positive? update(:multi_fetch_size, parsed) end |
#namespaces ⇒ Array<String>
Returns the namespaces configured for the account on the IMAP server
94 95 96 |
# File 'lib/imap/backup/account.rb', line 94 def namespaces client.namespace end |
#restore ⇒ void
This method returns an undefined value.
Restore the local backup to the server
108 109 110 111 |
# File 'lib/imap/backup/account.rb', line 108 def restore restore = Account::Restore.new(account: self) restore.run end |
#to_h ⇒ Hash
Returns all Account data for serialization
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/imap/backup/account.rb', line 147 def to_h h = {username: @username, password: @password} h[:local_path] = @local_path if @local_path h[:folders] = @folders if @folders h[:folder_blacklist] = true if @folder_blacklist h[:mirror_mode] = true if @mirror_mode h[:server] = @server if @server h[:connection_options] = @connection_options if @connection_options h[:multi_fetch_size] = multi_fetch_size if @reset_seen_flags_after_fetch h[:reset_seen_flags_after_fetch] = @reset_seen_flags_after_fetch end h end |
#valid? ⇒ Boolean
Indicates whether the account has been configured, and is ready to be used
117 118 119 |
# File 'lib/imap/backup/account.rb', line 117 def valid? username && password ? true : false end |