# File lib/net/pop.rb, line 580
    def command
      raise IOError, 'POP session not opened yet' \
                                      if not @socket or @socket.closed?
      @command
    end
    private :command

    #

    # POP protocol wrapper

    #


    # Returns the number of messages on the POP server.

    def n_mails
      return @n_mails if @n_mails
      @n_mails, @n_bytes = command().stat
      @n_mails
    end

    # Returns the total size in bytes of all the messages on the POP server.

    def n_bytes
      return @n_bytes if @n_bytes
      @n_mails, @n_bytes = command().stat
      @n_bytes
    end

    # Returns an array of Net::POPMail objects, representing all the

    # messages on the server.  This array is renewed when the session

    # restarts; otherwise, it is fetched from the server the first time

    # this method is called (directly or indirectly) and cached.

    #

    # This method raises a POPError if an error occurs.

    def mails
      return @mails.dup if @mails
      if n_mails() == 0
        # some popd raises error for LIST on the empty mailbox.

        @mails = []
        return []
      end

      @mails = command().list.map {|num, size|
        POPMail.new(num, size, self, command())
      }
      @mails.dup
    end

    # Yields each message to the passed-in block in turn.

    # Equivalent to:

    # 

    #   pop3.mails.each do |popmail|

    #     ....

    #   end

    #

    # This method raises a POPError if an error occurs.

    def each_mail(&block)  # :yield: message

      mails().each(&block)
    end

    alias each each_mail

    # Deletes all messages on the server.

    #

    # If called with a block, yields each message in turn before deleting it.

    #

    # === Example

    #

    #     n = 1

    #     pop.delete_all do |m|

    #       File.open("inbox/#{n}") do |f|

    #         f.write m.pop

    #       end

    #       n += 1

    #     end

    #

    # This method raises a POPError if an error occurs.

    #

    def delete_all # :yield: message

      mails().each do |m|
        yield m if block_given?
        m.delete unless m.deleted?
      end
    end

    # Resets the session.  This clears all "deleted" marks from messages.

    #

    # This method raises a POPError if an error occurs.

    def reset
      command().rset
      mails().each do |m|
        m.instance_eval {
          @deleted = false
        }
      end
    end

    def set_all_uids   #:nodoc: internal use only (called from POPMail#uidl)

      command().uidl.each do |num, uid|
        @mails.find {|m| m.number == num }.uid = uid
      end
    end

    def logging(msg)
      @debug_output << msg + "\n" if @debug_output
    end

  end