Class: Net::POPMail (Ruby 2.2.2)
Description: Class : Net::POPMail - Ruby 2.2.2

- Home
- Core 2.2.2
- Std-lib 2.2.2
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- net/pop.rb

### Parent

Object

### Methods

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

### Class/Module Index

Quicksearch

- Net
- Net::APOP
- Net::APOPSession
- Net::POP3
- Net::POPAuthenticationError
- Net::POPBadResponse
- Net::POPError
- Net::POPMail

No matching classes.

# Net::POPMail

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.

### Attributes

length[R]

The length of the message in octets.

number[R]

The sequence number of the message on the server.

size[R]

The length of the message in octets.

### Public Instance Methods

all( dest = '' ) click to toggle source
Alias for: pop
delete() click to toggle source

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 Net::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

                   # File net/pop.rb, line 857
    def delete
      @command.dele @number
      @deleted = true
    end

Also aliased as: delete!
delete!() click to toggle source
Alias for: delete
deleted?() click to toggle source

True if the mail has been deleted.

                   # File net/pop.rb, line 865
    def deleted?
      @deleted
    end

header(dest = '') click to toggle source

Fetches the message header.

The optional `dest` argument is obsolete.

This method raises a POPError if an error occurs.

                   # File net/pop.rb, line 833
    def header(dest = '')
      top(0, dest)
    end

inspect() click to toggle source

Provide human-readable stringification of class state.

                   # File net/pop.rb, line 759
    def inspect
      "#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>"
    end

mail( dest = '' ) click to toggle source
Alias for: pop
pop( dest = '' ) click to toggle source

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.

                   # File net/pop.rb, line 801
    def pop( dest = '', &block ) # :yield: message_chunk
      if block_given?
        @command.retr(@number, &block)
        nil
      else
        @command.retr(@number) do |chunk|
          dest << chunk
        end
        dest
      end
    end

Also aliased as: all, mail
top(lines, dest = '') click to toggle source

Fetches the message header and `lines` lines of body.

The optional `dest` argument is obsolete.

This method raises a POPError if an error occurs.

                   # File net/pop.rb, line 821
    def top(lines, dest = '')
      @command.top(@number, lines) do |chunk|
        dest << chunk
      end
      dest
    end

uidl() click to toggle source
Alias for: unique_id
unique_id() click to toggle source

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.

                   # File net/pop.rb, line 873
    def unique_id
      return @uid if @uid
      @pop.set_all_uids
      @uid
    end

Also aliased as: uidl