Class: Net::POPMail
- Inherits:
-
Object
- Object
- Net::POPMail
- 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
-
#length ⇒ Object
(also: #size)
readonly
The length of the message in octets.
-
#number ⇒ Object
readonly
The sequence number of the message on the server.
Instance Method Summary collapse
-
#delete ⇒ Object
(also: #delete!)
Marks a message for deletion on the server.
-
#deleted? ⇒ Boolean
True if the mail has been deleted.
-
#header(dest = +'')) ⇒ Object
Fetches the message header.
-
#initialize(num, len, pop, cmd) ⇒ POPMail
constructor
:nodoc:.
-
#inspect ⇒ Object
Provide human-readable stringification of class state.
-
#pop(dest = +'',, &block) ⇒ Object
(also: #all, #mail)
This method fetches the message.
-
#top(lines, dest = +'')) ⇒ Object
Fetches the message header and
lines
lines of body. -
#uid=(uid) ⇒ Object
:nodoc: internal use only.
-
#unique_id ⇒ Object
(also: #uidl)
Returns the unique-id of the message.
Constructor Details
#initialize(num, len, pop, cmd) ⇒ POPMail
:nodoc:
743 744 745 746 747 748 749 750 |
# File 'lib/net/pop.rb', line 743 def initialize(num, len, pop, cmd) #:nodoc: @number = num @length = len @pop = pop @command = cmd @deleted = false @uid = nil end |
Instance Attribute Details
#length ⇒ Object (readonly) Also known as: size
The length of the message in octets.
756 757 758 |
# File 'lib/net/pop.rb', line 756 def length @length end |
#number ⇒ Object (readonly)
The sequence number of the message on the server.
753 754 755 |
# File 'lib/net/pop.rb', line 753 def number @number end |
Instance Method Details
#delete ⇒ Object 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
858 859 860 861 |
# File 'lib/net/pop.rb', line 858 def delete @command.dele @number @deleted = true end |
#deleted? ⇒ Boolean
True if the mail has been deleted.
866 867 868 |
# File 'lib/net/pop.rb', line 866 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.
834 835 836 |
# File 'lib/net/pop.rb', line 834 def header(dest = +'') top(0, dest) end |
#inspect ⇒ Object
Provide human-readable stringification of class state.
760 761 762 |
# File 'lib/net/pop.rb', line 760 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.
802 803 804 805 806 807 808 809 810 811 812 |
# File 'lib/net/pop.rb', line 802 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.
822 823 824 825 826 827 |
# File 'lib/net/pop.rb', line 822 def top(lines, dest = +'') @command.top(@number, lines) do |chunk| dest << chunk end dest end |
#uid=(uid) ⇒ Object
:nodoc: internal use only
882 883 884 |
# File 'lib/net/pop.rb', line 882 def uid=(uid) #:nodoc: internal use only @uid = uid end |
#unique_id ⇒ Object 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.
874 875 876 877 878 |
# File 'lib/net/pop.rb', line 874 def unique_id return @uid if @uid @pop.set_all_uids @uid end |