Class: Imapcli::Command
- Inherits:
-
Object
- Object
- Imapcli::Command
- Defined in:
- lib/imapcli/command.rb
Overview
Provides entry points for Imapcli.
Most of the methods in this class return
Class Method Summary collapse
Instance Method Summary collapse
-
#check ⇒ Object
Checks if the server accepts the login with the given credentials.
-
#info ⇒ Object
Collects basic information about the server.
-
#initialize(client) ⇒ Command
constructor
A new instance of Command.
-
#list ⇒ Object
Lists all mailboxes.
-
#stats(mailbox_names = [], options = {}) ⇒ Object
Collects statistics about mailboxes.
Constructor Details
Class Method Details
.unknown_mailbox_prefix ⇒ Object
77 78 79 |
# File 'lib/imapcli/command.rb', line 77 def self.unknown_mailbox_prefix '!!! ' end |
Instance Method Details
#check ⇒ Object
Checks if the server accepts the login with the given credentials.
Returns true if successful, false if not.
14 15 16 |
# File 'lib/imapcli/command.rb', line 14 def check @client.login end |
#info ⇒ Object
Collects basic information about the server.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/imapcli/command.rb', line 19 def info perform do output = [] output << "greeting: #{@client.greeting}" output << "capability: #{@client.capability.join(' ')}" output << "hierarchy separator: #{@client.separator}" if @client.supports_quota usage = Filesize.from(@client.quota[0] + ' kB').pretty available = Filesize.from(@client.quota[1] + ' kB').pretty output << "quota: #{usage} used, #{available} available (#{@client.quota[2].round(1)}%)" else output << "quota: IMAP QUOTA extension not supported by this server" end end end |
#list ⇒ Object
Lists all mailboxes
36 37 38 39 40 |
# File 'lib/imapcli/command.rb', line 36 def list perform do traverse_mailbox_tree(@client.mailbox_root) end end |
#stats(mailbox_names = [], options = {}) ⇒ Object
Collects statistics about mailboxes.
If a block is given, it is called with the current mailbox count and the total mailbox count so that current progress can be computed.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imapcli/command.rb', line 46 def stats(mailbox_names = [], = {}) mailbox_names = [mailbox_names] unless mailbox_names.is_a? Array perform do output = [] # Map the command line arguments to Imapcli::Mailbox objects mailboxes = find_mailboxes(mailbox_names) list = mailboxes.inject([]) do |ary, mailbox| ary + mailbox.to_list(determine_max_level(mailbox, )) end raise 'mailbox not found' unless list.count > 0 current_count = 0 yield list.length if block_given? total_stats = Stats.new list.each do |mailbox| # Since we are working on a flat list of mailboxes, set the maximum # level to 0 when collecting stats. mailbox.collect_stats(@client, 0) do |stats| total_stats.add(stats) current_count += 1 yield current_count if block_given? end end sorted_list(list, ).each do |mailbox| output << stats_to_table(mailbox.full_name, mailbox.stats) end # output << Array.new(8, '======') output << stats_to_table('Total', total_stats) if list.length > 1 output end end |