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, #symbolized

Instance Method Details

#accountsObject


11
12
13
14
# File 'lib/imap/backup/cli/local.rb', line 11

def accounts
  accounts = CLI::Accounts.new
  accounts.each { |a| Kernel.puts a.username }
end

#folders(email) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/imap/backup/cli/local.rb', line 17

def folders(email)
  connection = connection(email)

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

#list(email, folder_name) ⇒ Object


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

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

  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|
    list_message uid, message
  end
end

#show(email, folder_name, uids) ⇒ Object


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

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 <<~HEADER
        #{'-' * 80}
        #{format('| UID: %-71s |', uid)}
        #{'-' * 80}
      HEADER
    end
    Kernel.puts message.supplied_body
  end
end