Class: Imap::Backup::Account

Inherits:
Object
  • Object
show all
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

Defined Under Namespace

Classes: Backup, BackupFolders, ClientFactory, Folder, FolderBackup, FolderEnsurer, LocalOnlyFolderDeleter, Restore, SerializedFolders

Constant Summary collapse

DEFAULT_MULTI_FETCH_SIZE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Account

Returns a new instance of Account.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/imap/backup/account.rb', line 24

def initialize(options)
  @username = options[:username]
  @password = options[:password]
  @local_path = options[:local_path]
  @folders = options[:folders]
  @folder_blacklist = options[:folder_blacklist]
  @mirror_mode = options[:mirror_mode]
  @server = options[:server]
  @connection_options = options[:connection_options]
  @download_strategy = options[:download_strategy]
  @multi_fetch_size_orignal = options[:multi_fetch_size]
  @reset_seen_flags_after_fetch = options[:reset_seen_flags_after_fetch]
  @client = nil
  @changes = {}
  @marked_for_deletion = false
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



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

def changes
  @changes
end

#connection_optionsObject

Returns the value of attribute connection_options.



19
20
21
# File 'lib/imap/backup/account.rb', line 19

def connection_options
  @connection_options
end

#download_strategyObject

Returns the value of attribute download_strategy.



20
21
22
# File 'lib/imap/backup/account.rb', line 20

def download_strategy
  @download_strategy
end

#folder_blacklistObject

Returns the value of attribute folder_blacklist.



16
17
18
# File 'lib/imap/backup/account.rb', line 16

def folder_blacklist
  @folder_blacklist
end

#foldersObject

Returns the value of attribute folders.



15
16
17
# File 'lib/imap/backup/account.rb', line 15

def folders
  @folders
end

#local_pathObject

Returns the value of attribute local_path.



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

def local_path
  @local_path
end

#mirror_modeObject

Returns the value of attribute mirror_mode.



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

def mirror_mode
  @mirror_mode
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#reset_seen_flags_after_fetchObject

Returns the value of attribute reset_seen_flags_after_fetch.



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

def reset_seen_flags_after_fetch
  @reset_seen_flags_after_fetch
end

#serverObject

Returns the value of attribute server.



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

def server
  @server
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#capabilitiesObject



49
50
51
# File 'lib/imap/backup/account.rb', line 49

def capabilities
  client.capability
end

#clear_changesObject



66
67
68
# File 'lib/imap/backup/account.rb', line 66

def clear_changes
  @changes = {}
end

#clientObject



41
42
43
# File 'lib/imap/backup/account.rb', line 41

def client
  @client ||= Account::ClientFactory.new(account: self).run
end

#mark_for_deletionObject



70
71
72
# File 'lib/imap/backup/account.rb', line 70

def mark_for_deletion
  @marked_for_deletion = true
end

#marked_for_deletion?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/imap/backup/account.rb', line 74

def marked_for_deletion?
  @marked_for_deletion
end

#modified?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/imap/backup/account.rb', line 62

def modified?
  changes.any?
end

#multi_fetch_sizeObject



133
134
135
136
137
138
139
140
141
142
# File 'lib/imap/backup/account.rb', line 133

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) ⇒ Object



144
145
146
147
148
# File 'lib/imap/backup/account.rb', line 144

def multi_fetch_size=(value)
  parsed = value.to_i
  parsed = DEFAULT_MULTI_FETCH_SIZE if !parsed.positive?
  update(:multi_fetch_size, parsed)
end

#namespacesObject



45
46
47
# File 'lib/imap/backup/account.rb', line 45

def namespaces
  client.namespace
end

#restoreObject



53
54
55
56
# File 'lib/imap/backup/account.rb', line 53

def restore
  restore = Account::Restore.new(account: self)
  restore.run
end

#to_hObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/imap/backup/account.rb', line 78

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

Returns:

  • (Boolean)


58
59
60
# File 'lib/imap/backup/account.rb', line 58

def valid?
  username && password ? true : false
end