[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How can I get the subject of mail

Jmlover

5/31/2008 7:46:00 AM

@pop = Net::POP3.new('pop.163.com')
@pop.start(@username, @password)

@pop.each_mail do |m|
# How can I get the subject of m?
# ~~~~~~~~~~~~~~~~
# By m.pop?
end

@pop.finish


By the way, can I only get the mail header? How?


Thank you!
3 Answers

Craig

5/31/2008 6:23:00 PM

0

On May 31, 1:46 am, Jmlover <Jmlo...@gmail.com> wrote:
> @pop = Net::POP3.new('pop.163.com')
> @pop.start(@username, @password)
>
> @pop.each_mail do |m|
> # How can I get the subject of m?
> # ~~~~~~~~~~~~~~~~
> # By m.pop?
> end
>
> @pop.finish
>
> By the way, can I only get the mail header? How?
>
> Thank you!

Here is one way.

puts m.pop.scan(/Subject:(.+)$/)

Cheers,

Craig

Jmlover

6/1/2008 5:51:00 AM

0

On Jun 1, 2:23 am, Craig <cwilli...@easynewsletters.net> wrote:
> On May 31, 1:46 am, Jmlover <Jmlo...@gmail.com> wrote:
>
> > @pop = Net::POP3.new('pop.163.com')
> > @pop.start(@username, @password)
>
> > @pop.each_mail do |m|
> > # How can I get the subject of m?
> > # ~~~~~~~~~~~~~~~~
> > # By m.pop?
> > end
>
> > @pop.finish
>
> > By the way, can I only get the mail header? How?
>
> > Thank you!
>
> Here is one way.
>
> puts m.pop.scan(/Subject:(.+)$/)
>
> Cheers,
>
> Craig

Thank you for your reply!

Mike Stok

6/1/2008 12:07:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jun 1, 2008, at 1:54 AM, Jmlover wrote:

> On Jun 1, 2:23 am, Craig <cwilli...@easynewsletters.net> wrote:
>> On May 31, 1:46 am, Jmlover <Jmlo...@gmail.com> wrote:
>>
>>> @pop = Net::POP3.new('pop.163.com')
>>> @pop.start(@username, @password)
>>
>>> @pop.each_mail do |m|
>>> # How can I get the subject of m?
>>> # ~~~~~~~~~~~~~~~~
>>> # By m.pop?
>>> end
>>
>>> @pop.finish
>>
>>> By the way, can I only get the mail header? How?
>>
>>> Thank you!
>>
>> Here is one way.
>>
>> puts m.pop.scan(/Subject:(.+)$/)
>>
>> Cheers,
>>
>> Craig
>
> Thank you for your reply!

You can use the header method if you are only interested in the header:

#!/usr/bin/env ruby

require 'net/pop'
pop = Net::POP.new('pop.example.com')
pop.start('user@example.com', 'password') do |pop|
pop.each_mail do |mail|
puts mail.header.scan(/^Subject: (.+)/)
end
end

http://www.ruby-doc.org/stdlib/libdoc/net/pop/rdoc/classes/Net/PO...

Mike

- --

Mike Stok <mike@stok.ca>
http://www.stok...

The "`Stok' disclaimers" apply.




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAkhCkQkACgkQnsTBwAWZE9rFAgCfdfz9a7fGAAmLNlt7Tolgj9J/
Xb4AoIe1vxT1NBZ/01iFeirSLOSChPrR
=Bqet
-----END PGP SIGNATURE-----