Class: Imap::Backup::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/account.rb,
lib/imap/backup/account/folder.rb,
lib/imap/backup/account/connection.rb,
lib/imap/backup/account/connection/folder_names.rb,
lib/imap/backup/account/connection/backup_folders.rb

Defined Under Namespace

Classes: Connection, Folder

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.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imap/backup/account.rb', line 18

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]
  @multi_fetch_size = options[:multi_fetch_size]
  @reset_seen_flags_after_fetch = options[:reset_seen_flags_after_fetch]
  @connection = nil
  @changes = {}
  @marked_for_deletion = false
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.


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

def changes
  @changes
end

#connection_optionsObject

Returns the value of attribute connection_options.


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

def connection_options
  @connection_options
end

#folder_blacklistObject

Returns the value of attribute folder_blacklist.


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

def folder_blacklist
  @folder_blacklist
end

#foldersObject

Returns the value of attribute folders.


10
11
12
# File 'lib/imap/backup/account.rb', line 10

def folders
  @folders
end

#local_pathObject

Returns the value of attribute local_path.


9
10
11
# File 'lib/imap/backup/account.rb', line 9

def local_path
  @local_path
end

#mirror_modeObject

Returns the value of attribute mirror_mode.


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

def mirror_mode
  @mirror_mode
end

#passwordObject

Returns the value of attribute password.


8
9
10
# File 'lib/imap/backup/account.rb', line 8

def password
  @password
end

#reset_seen_flags_after_fetchObject

Returns the value of attribute reset_seen_flags_after_fetch.


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

def reset_seen_flags_after_fetch
  @reset_seen_flags_after_fetch
end

#serverObject

Returns the value of attribute server.


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

def server
  @server
end

#usernameObject

Returns the value of attribute username.


7
8
9
# File 'lib/imap/backup/account.rb', line 7

def username
  @username
end

Instance Method Details

#clear_changesObject


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

def clear_changes
  @changes = {}
end

#connectionObject


34
35
36
# File 'lib/imap/backup/account.rb', line 34

def connection
  @connection ||= Account::Connection.new(self)
end

#mark_for_deletionObject


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

def mark_for_deletion
  @marked_for_deletion = true
end

#marked_for_deletion?Boolean

Returns:

  • (Boolean)

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

def marked_for_deletion?
  @marked_for_deletion
end

#modified?Boolean

Returns:

  • (Boolean)

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

def modified?
  changes.any?
end

#multi_fetch_sizeObject


113
114
115
116
117
118
119
120
# File 'lib/imap/backup/account.rb', line 113

def multi_fetch_size
  int = @multi_fetch_size.to_i
  if int.positive?
    int
  else
    DEFAULT_MULTI_FETCH_SIZE
  end
end

#multi_fetch_size=(value) ⇒ Object


122
123
124
125
126
# File 'lib/imap/backup/account.rb', line 122

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

#to_hObject


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/imap/backup/account.rb', line 58

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 @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)

38
39
40
# File 'lib/imap/backup/account.rb', line 38

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