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
#account, #connection, #each_connection, #symbolized
Instance Method Details
#accounts ⇒ Object
9
10
11
12
|
# File 'lib/imap/backup/cli/local.rb', line 9
def accounts
accounts = CLI::Accounts.new
accounts.each { |a| Kernel.puts a.username }
end
|
#folders(email) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/imap/backup/cli/local.rb', line 15
def folders(email)
connection = connection(email)
connection.local_folders.each do |_s, f|
Kernel.puts %("#{f.name}")
end
end
|
#list(email, folder_name) ⇒ Object
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
49
50
51
52
53
|
# File 'lib/imap/backup/cli/local.rb', line 24
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/imap/backup/cli/local.rb', line 61
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
|