Class: Net::POPMail

Inherits:
Object
  • Object
show all
Defined in:
lib/net/pop.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num, len, pop, cmd) ⇒ POPMail

:nodoc:



603
604
605
606
607
608
609
610
# File 'lib/net/pop.rb', line 603

def initialize( num, len, pop, cmd )   #:nodoc:
  @number = num
  @length = len
  @pop = pop
  @command = cmd
  @deleted = false
  @uid = nil
end

Instance Attribute Details

#lengthObject (readonly) Also known as: size

The length of the message in octets.



616
617
618
# File 'lib/net/pop.rb', line 616

def length
  @length
end

#numberObject (readonly)

The sequence number of the message on the server.



613
614
615
# File 'lib/net/pop.rb', line 613

def number
  @number
end

Instance Method Details

#deleteObject Also known as: delete!

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


718
719
720
721
# File 'lib/net/pop.rb', line 718

def delete
  @command.dele @number
  @deleted = true
end

#deleted?Boolean

True if the mail has been deleted.

Returns:

  • (Boolean)


726
727
728
# File 'lib/net/pop.rb', line 726

def deleted?
  @deleted
end

#header(dest = '') ⇒ Object

Fetches the message header.

The optional dest argument is obsolete.

This method raises a POPError if an error occurs.



694
695
696
# File 'lib/net/pop.rb', line 694

def header( dest = '' )
  top(0, dest)
end

#inspectObject

Provide human-readable stringification of class state.



620
621
622
# File 'lib/net/pop.rb', line 620

def inspect
  "#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>"
end

#pop(dest = '', &block) ⇒ Object Also known as: all, mail

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.



662
663
664
665
666
667
668
669
670
671
672
# File 'lib/net/pop.rb', line 662

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

#top(lines, dest = '') ⇒ Object

Fetches the message header and lines lines of body.

The optional dest argument is obsolete.

This method raises a POPError if an error occurs.



682
683
684
685
686
687
# File 'lib/net/pop.rb', line 682

def top( lines, dest = '' )
  @command.top(@number, lines) do |chunk|
    dest << chunk
  end
  dest
end

#uid=(uid) ⇒ Object

:nodoc: internal use only (used from POP3#set_all_uids)



742
743
744
# File 'lib/net/pop.rb', line 742

def uid=( uid )   #:nodoc: internal use only (used from POP3#set_all_uids)
  @uid = uid
end

#unique_idObject Also known as: uidl

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.



734
735
736
737
738
# File 'lib/net/pop.rb', line 734

def unique_id
  return @uid if @uid
  @pop.set_all_uids
  @uid
end