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

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

Constant Summary collapse

MAX_SUBJECT =
60

Instance Method Summary collapse

Methods included from Helpers

#account, #connection, #each_connection, included, #load_config, #options

Instance Method Details

#accountsObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/imap/backup/cli/local.rb', line 11

def accounts
  config = load_config(**options)
  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

#folders(email) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/imap/backup/cli/local.rb', line 26

def folders(email)
  config = load_config(**options)
  connection = connection(config, email)

  folders = connection.local_folders
  case options[:format]
  when "json"
    list = folders.map { |_s, f| {name: f.name} }
    Kernel.puts list.to_json
  else
    folders.each do |_s, f|
      Kernel.puts %("#{f.name}")
    end
  end
end

#list(email, folder_name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/imap/backup/cli/local.rb', line 45

def list(email, folder_name)
  config = load_config(**options)
  connection = connection(config, email)

  serializer, _folder = connection.local_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



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

def show(email, folder_name, uids)
  config = load_config(**options)
  connection = connection(config, email)

  serializer, _folder = connection.local_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