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

Defined Under Namespace

Classes: Check

Instance Method Summary collapse

Methods included from Helpers

#account, #load_config, #options, #requested_accounts

Instance Method Details

#accountsObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/imap/backup/cli/local.rb', line 22

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

#checkObject



47
48
49
50
# File 'lib/imap/backup/cli/local.rb', line 47

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

#folders(email) ⇒ Object



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

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 do |_s, f|
      Kernel.puts %("#{f.name}")
    end
  end
end

#list(email, folder_name) ⇒ Object



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

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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/imap/backup/cli/local.rb', line 104

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