lib/imap/backup/cli/local.rb in imap-backup-4.0.0.rc5 vs lib/imap/backup/cli/local.rb in imap-backup-4.0.0.rc6
- old
+ new
@@ -19,12 +19,12 @@
account_connection.local_folders.each do |_s, f|
puts %("#{f.name}")
end
end
- desc "emails EMAIL FOLDER", "List emails in a folder"
- def emails(email, folder_name)
+ desc "list EMAIL FOLDER", "List emails in a folder"
+ 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)
@@ -51,24 +51,36 @@
puts format("% 10<uid>u: %-#{max_subject}<subject>s - %<date>s", m)
end
end
end
- desc "email EMAIL FOLDER UID", "Show an email"
- def email(email, folder_name, uid)
+ desc "show EMAIL FOLDER UID[,UID]", "Show one or more emails"
+ long_desc <<~DESC
+ Prints out the requested emails.
+ If more than one UID is given, they are separated by a header indicating
+ the UID.
+ DESC
+ 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
- loaded_message = folder_serializer.load(uid)
- raise "Message #{uid} not found in folder '#{folder_name}'" if !loaded_message
-
- puts loaded_message.supplied_body
+ 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
end
end