Class: Imap::Backup::CLI::Local
- Inherits:
-
Thor
- Object
- Thor
- Imap::Backup::CLI::Local
- 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
-
#accounts ⇒ void
Lists configured accounts.
-
#check ⇒ void
Runs integrity checks on backups.
-
#folders(email) ⇒ void
Lists backed-up folders for an account.
-
#list(email, folder_name) ⇒ void
Lists backed-up emails for an account folder.
-
#show(email, folder_name, uids) ⇒ void
Shows the content of one or more backed-up email messages.
Methods included from Helpers
#account, included, #load_config, #options, #requested_accounts
Instance Method Details
#accounts ⇒ void
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 [:format] when "json" list = names.map { |n| {username: n} } Kernel.puts list.to_json else names.each { |n| Kernel.puts n } end end |
#check ⇒ void
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 = Imap::Backup::Logger.setup_logging() Check.new().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) account = account(config, email) serialized_folders = Account::SerializedFolders.new(account: account) case [: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
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) account = account(config, email) serialized_folders = Account::SerializedFolders.new(account: account) serializer, _folder = serialized_folders.find do |_s, f| f.name == folder_name end raise "Folder '#{folder_name}' not found" if !serializer case [: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
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) account = account(config, email) serialized_folders = Account::SerializedFolders.new(account: 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 [:format] when "json" show_emails_as_json serializer, uid_list else show_emails_as_text serializer, uid_list end end |