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

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

Instance Method Summary collapse

Methods included from Helpers

#account, #connection, #each_connection, #symbolized

Instance Method Details

#accountsObject



7
8
9
10
# File 'lib/imap/backup/cli/local.rb', line 7

def accounts
  connections = Imap::Backup::Configuration::List.new
  connections.accounts.each { |a| Kernel.puts a[:username] }
end

#folders(email) ⇒ Object



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

def folders(email)
  connection = connection(email)

  connection.local_folders.each do |_s, f|
    Kernel.puts %("#{f.name}")
  end
end

#list(email, folder_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/imap/backup/cli/local.rb', line 22

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

  folder_serializer, _folder = connection.local_folders.find do |(_s, f)|
    f.name == folder_name
  end
  raise "Folder '#{folder_name}' not found" if !folder_serializer

  max_subject = 60
  Kernel.puts format("%-10<uid>s  %-#{max_subject}<subject>s - %<date>s", {uid: "UID", subject: "Subject", date: "Date"})
  Kernel.puts "-" * (12 + max_subject + 28)

  uids = folder_serializer.uids

  folder_serializer.each_message(uids).map do |uid, message|
    m = {
      uid: uid,
      date: message.date.to_s,
      subject: message.subject || ""
    }
    if m[:subject].length > max_subject
      Kernel.puts format("% 10<uid>u: %.#{max_subject - 3}<subject>s... - %<date>s", m)
    else
      Kernel.puts format("% 10<uid>u: %-#{max_subject}<subject>s - %<date>s", m)
    end
  end
end

#show(email, folder_name, uids) ⇒ Object



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

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

  folder_serializer, _folder = connection.local_folders.find do |(_s, f)|
    f.name == folder_name
  end
  raise "Folder '#{folder_name}' not found" if !folder_serializer

  uid_list = uids.split(",")
  folder_serializer.each_message(uid_list).each do |uid, message|
    if uid_list.count > 1
      Kernel.puts "        \#{'-' * 80}\n        \#{format('| UID: %-71s |', uid)}\n        \#{'-' * 80}\n      HEADER\n    end\n    Kernel.puts message.supplied_body\n  end\nend\n"