Class: Imap::Backup::CLI::Local

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/imap/backup/cli/local.rb,
lib/imap/backup/cli/local/check.rb

Overview

Implements the CLI functions relating to local storage

Defined Under Namespace

Classes: Check

Instance Method Summary collapse

Methods included from Helpers

#account, included, #load_config, #options, #requested_accounts

Instance Method Details

#accountsvoid

This method returns an undefined value.

Lists configured accounts



25
26
27
28
29
30
31
32
33
34
# File 'lib/imap/backup/cli/local.rb', line 25

def accounts
  names = config.accounts.map(&:username)
  case options[:format]
  when "json"
    list = names.map { |n| {username: n} }
    Kernel.puts list.to_json
  else
    names.each { |n| Kernel.puts n }
  end
end

#checkvoid

This method returns an undefined value.

Runs integrity checks on backups



52
53
54
55
# File 'lib/imap/backup/cli/local.rb', line 52

def check
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  Check.new(non_logging_options).run
end

#folders(email) ⇒ void

This method returns an undefined value.

Lists backed-up folders for an account



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/imap/backup/cli/local.rb', line 64

def folders(email)
   = (config, email)

  serialized_folders = Account::SerializedFolders.new(account: )
  case options[:format]
  when "json"
    list = serialized_folders.map { |_s, f| {name: f.name} }
    Kernel.puts list.to_json
  else
    serialized_folders.each_value do |f|
      Kernel.puts %("#{f.name}")
    end
  end
end

#list(email, folder_name) ⇒ void

This method returns an undefined value.

Lists backed-up emails for an account folder

Raises:

  • (RuntimeError)

    if the folder does not exist



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/imap/backup/cli/local.rb', line 87

def list(email, folder_name)
   = (config, email)

  serialized_folders = Account::SerializedFolders.new(account: )
  serializer, _folder = serialized_folders.find do |_s, f|
    f.name == folder_name
  end
  raise "Folder '#{folder_name}' not found" if !serializer

  case options[:format]
  when "json"
    list_emails_as_json serializer
  else
    list_emails_as_text serializer
  end
end

#show(email, folder_name, uids) ⇒ void

This method returns an undefined value.

Shows the content of one or more backed-up email messages

Raises:

  • (RuntimeError)

    if the folder does not exist



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/imap/backup/cli/local.rb', line 117

def show(email, folder_name, uids)
   = (config, email)

  serialized_folders = Account::SerializedFolders.new(account: )
  serializer, _folder = serialized_folders.find do |_s, f|
    f.name == folder_name
  end
  raise "Folder '#{folder_name}' not found" if !serializer

  uid_list = uids.split(",")

  case options[:format]
  when "json"
    show_emails_as_json serializer, uid_list
  else
    show_emails_as_text serializer, uid_list
  end
end