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

Constant Summary collapse

MAX_SUBJECT =
60

Instance Method Summary collapse

Methods included from Helpers

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

Instance Method Details

#accountsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/imap/backup/cli/local.rb', line 18

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



43
44
45
46
# File 'lib/imap/backup/cli/local.rb', line 43

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

#folders(email) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imap/backup/cli/local.rb', line 53

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/imap/backup/cli/local.rb', line 73

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/imap/backup/cli/local.rb', line 100

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