The Pop3 retriever allows to get the last, first or all emails from a POP3 server. Each email retrieved (RFC2822) is given as an instance of Message.
While being retrieved, emails can be yielded if a block is given.
Mail.defaults do retriever_method :pop3, { :address => "pop.gmail.com", :port => 995, :user_name => '<username>', :password => '<password>', :enable_ssl => true } end Mail.all #=> Returns an array of all emails Mail.first #=> Returns the first unread email Mail.last #=> Returns the first unread email
You can also pass options into Mail.find to locate an email in your pop mailbox with the following options:
what: last or first emails. The default is :first. order: order of emails returned. Possible values are :asc or :desc. Default value is :asc. count: number of emails to retrieve. The default value is 10. A value of 1 returns an instance of Message, not an array of Message instances. Mail.find(:what => :first, :count => 10, :order => :asc) #=> Returns the first 10 emails in ascending order
Get all emails.
Possible options:
order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
# File lib/mail/network/retriever_methods/pop3.rb, line 78 def all(options = {}, &block) options ||= {} options[:count] = :all find(options, &block) end
Find emails in a POP3 mailbox. Without any options, the 5 last received emails are returned.
Possible options:
what: last or first emails. The default is :first. order: order of emails returned. Possible values are :asc or :desc. Default value is :asc. count: number of emails to retrieve. The default value is 10. A value of 1 returns an instance of Message, not an array of Message instances.
# File lib/mail/network/retriever_methods/pop3.rb, line 92 def find(options = {}, &block) options = validate_options(options) start do |pop3| mails = pop3.mails mails.sort! { |m1, m2| m2.number <=> m1.number } if options[:what] == :last mails = mails.first(options[:count]) if options[:count].is_a? Integer if options[:what].to_sym == :last && options[:order].to_sym == :desc || options[:what].to_sym == :first && options[:order].to_sym == :asc || mails.reverse! end if block_given? mails.each do |mail| yield Mail.new(mail.pop) end else emails = [] mails.each do |mail| emails << Mail.new(mail.pop) end emails.size == 1 && options[:count] == 1 ? emails.first : emails end end end
Get the oldest received email(s)
Possible options:
count: number of emails to retrieve. The default value is 1. order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
# File lib/mail/network/retriever_methods/pop3.rb, line 53 def first(options = {}, &block) options ||= {} options[:what] = :first options[:count] ||= 1 find(options, &block) end
Get the most recent received email(s)
Possible options:
count: number of emails to retrieve. The default value is 1. order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
# File lib/mail/network/retriever_methods/pop3.rb, line 66 def last(options = {}, &block) options ||= {} options[:what] = :last options[:count] ||= 1 find(options, &block) end
Generated with the Darkfish Rdoc Generator 2.