Class: Imap::Backup::CLI::Local
- Inherits:
-
Thor
- Object
- Thor
- Imap::Backup::CLI::Local
show all
- Includes:
- Helpers, Thor::Actions
- Defined in:
- lib/imap/backup/cli/local.rb
Instance Method Summary
collapse
Methods included from Helpers
#each_connection, #symbolized
Instance Method Details
#accounts ⇒ Object
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| puts a[:username] }
end
|
#folders(email) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/imap/backup/cli/local.rb', line 13
def folders(email)
connections = Imap::Backup::Configuration::List.new
account = connections.accounts.find { |a| a[:username] == email }
raise "#{email} is not a configured account" if !account
account_connection = Imap::Backup::Account::Connection.new(account)
account_connection.local_folders.each do |_s, f|
puts %("#{f.name}")
end
end
|
#list(email, folder_name) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/imap/backup/cli/local.rb', line 25
def list(email, folder_name)
connections = Imap::Backup::Configuration::List.new
account = connections.accounts.find { |a| a[:username] == email }
raise "#{email} is not a configured account" if !account
account_connection = Imap::Backup::Account::Connection.new(account)
folder_serializer, folder = account_connection.local_folders.find do |(_s, f)|
f.name == folder_name
end
raise "Folder '#{folder_name}' not found" if !folder_serializer
max_subject = 60
puts format("%-10<uid>s %-#{max_subject}<subject>s - %<date>s", {uid: "UID", subject: "Subject", date: "Date"})
puts "-" * (12 + max_subject + 28)
uids = folder_serializer.uids
folder_serializer.each_message(uids).map do |uid, message|
m = {
uid: uid,
date: message.parsed.date.to_s,
subject: message.parsed.subject || ""
}
if m[:subject].length > max_subject
puts format("% 10<uid>u: %.#{max_subject - 3}<subject>s... - %<date>s", m)
else
puts format("% 10<uid>u: %-#{max_subject}<subject>s - %<date>s", m)
end
end
end
|
#show(email, folder_name, uids) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/imap/backup/cli/local.rb', line 62
def show(email, folder_name, uids)
connections = Imap::Backup::Configuration::List.new
account = connections.accounts.find { |a| a[:username] == email }
raise "#{email} is not a configured account" if !account
account_connection = Imap::Backup::Account::Connection.new(account)
folder_serializer, _folder = account_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
puts <<~HEADER
#{"-" * 80}
#{format("| UID: %-71s |", uid)}
#{"-" * 80}
HEADER
end
puts message.supplied_body
end
end
|