Class Net::POPMail
In: lib/net/pop.rb
Parent: Object

This class represents a message which exists on the POP server. Instances of this class are created by the POP3 class; they should not be directly created by the user.

Methods

all   delete   delete!   deleted?   header   inspect   mail   pop   top   uidl   unique_id  

External Aliases

length -> size

Attributes

length  [R]  The length of the message in octets.
number  [R]  The sequence number of the message on the server.

Public Instance methods

all( dest = '' )

Alias for pop

Marks a message for deletion on the server. Deletion does not actually occur until the end of the session; deletion may be cancelled for all marked messages by calling POP3#reset().

This method raises a POPError if an error occurs.

Example

    POP3.start('pop.example.com', 110,
               'YourAccount, 'YourPassword') do |pop|
      n = 1
      pop.mails.each do |popmail|
        File.open("inbox/#{n}", 'w') do |f|
          f.write popmail.pop
        end
        popmail.delete         ####
        n += 1
      end
    end

[Source]

     # File lib/net/pop.rb, line 837
837:     def delete
838:       @command.dele @number
839:       @deleted = true
840:     end
delete!()

Alias for delete

True if the mail has been deleted.

[Source]

     # File lib/net/pop.rb, line 845
845:     def deleted?
846:       @deleted
847:     end

Fetches the message header.

The optional dest argument is obsolete.

This method raises a POPError if an error occurs.

[Source]

     # File lib/net/pop.rb, line 813
813:     def header(dest = '')
814:       top(0, dest)
815:     end

Provide human-readable stringification of class state.

[Source]

     # File lib/net/pop.rb, line 739
739:     def inspect
740:       "#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>"
741:     end
mail( dest = '' )

Alias for pop

This method fetches the message. If called with a block, the message is yielded to the block one chunk at a time. If called without a block, the message is returned as a String. The optional dest argument will be prepended to the returned String; this argument is essentially obsolete.

Example without block

    POP3.start('pop.example.com', 110,
               'YourAccount, 'YourPassword') do |pop|
      n = 1
      pop.mails.each do |popmail|
        File.open("inbox/#{n}", 'w') do |f|
          f.write popmail.pop
        end
        popmail.delete
        n += 1
      end
    end

Example with block

    POP3.start('pop.example.com', 110,
               'YourAccount, 'YourPassword') do |pop|
      n = 1
      pop.mails.each do |popmail|
        File.open("inbox/#{n}", 'w') do |f|
          popmail.pop do |chunk|            ####
            f.write chunk
          end
        end
        n += 1
      end
    end

This method raises a POPError if an error occurs.

[Source]

     # File lib/net/pop.rb, line 781
781:     def pop( dest = '', &block ) # :yield: message_chunk
782:       if block_given?
783:         @command.retr(@number, &block)
784:         nil
785:       else
786:         @command.retr(@number) do |chunk|
787:           dest << chunk
788:         end
789:         dest
790:       end
791:     end

Fetches the message header and lines lines of body.

The optional dest argument is obsolete.

This method raises a POPError if an error occurs.

[Source]

     # File lib/net/pop.rb, line 801
801:     def top(lines, dest = '')
802:       @command.top(@number, lines) do |chunk|
803:         dest << chunk
804:       end
805:       dest
806:     end
uidl()

Alias for unique_id

Returns the unique-id of the message. Normally the unique-id is a hash string of the message.

This method raises a POPError if an error occurs.

[Source]

     # File lib/net/pop.rb, line 853
853:     def unique_id
854:       return @uid if @uid
855:       @pop.set_all_uids
856:       @uid
857:     end

[Validate]