Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Problems with gmailer

Reply
Thread Tools

Problems with gmailer

 
 
planetthoughtful
Guest
Posts: n/a
 
      03-17-2007
Hi,

I'm a newcomer to Ruby in general and to the Gmailer (version 0.1.5)
class in particular, and I wanted to ask a couple of questions about
using it, if that's okay?

In particular, I'm using it across a dialup connection and while I am
successfully connecting to and retrieving message content from gmail
using the gmailer class, it's very slow and it often times out on my
end. Why I don't simply blame this on my connection speed is that
using a browser to access gmail is still slow, but is also generally
faster than the gmailer class via Ruby.

Is that to be expected? The error message I'm getting is below:

c:/ruby/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired
(Timeout::Error)
from c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
from c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from c:/ruby/lib/ruby/1.8/net/http.rb:2017:in
`read_status_line'
from c:/ruby/lib/ruby/1.8/net/http.rb:2006:in `read_new'
from c:/ruby/lib/ruby/1.8/net/http.rb:1047:in `request'
... 8 levels...
from c:/ruby/lib/ruby/gems/1.8/gems/gmailer-0.1.5/gmailer.rb:
1570:in `each_msg'
from gmail.rb:15
from c:/ruby/lib/ruby/gems/1.8/gems/gmailer-0.1.5/gmailer.rb:
1784:in `connect'
from gmail.rb:10

I've tried looking for a timeout setting for the gmailer class, but
nothing leaps out at me from the associated readme file.

Second, is there a way of using the each_msg method to, for example,
retrieve all of the unread messages in my account's inbox without
marking those messages as read?

I ask because I have a couple of gmail accounts that I don't access
regularly, but it would be nice to write a script in Ruby using
gmailer that logs in and pulls down a summary of the unread messages
sitting in the inboxes of those accounts. I'd like to leave those
messages with a status of being unread, though, so that this still
stands out when I do log into the accounts using my browser.

For some reason, when I use the each_msg method to iterate through
unread messages, the messages get marked as read. So as it stands
right now, I'm explicitly setting the messages back to being unread
(which is probably adding to the execution time of the script), but
I'm wondering if there's a way to iterate through all the unread
messages in your inbox and retrieve, for example, the sender's email
address and the subject line without marking the message as having
been read?

This is the code I'm using:

require 'gmailer'

GMailer.connect('mygmailaccount', 'mypassword') do
|g|
g.messages(:standard=>'Inbox',:read=>false) {|ml|
puts "Total # of unread messages = " + ml.total.to_s
}
g.messages(:standard=>'Inbox',:read=>false).each_m sg {
|ml|
puts "Subject: " + ml.subject + " (" + ml.id.to_s + ")"
g.mark_unread(ml.id)
}
end

Thanks in adance for any help!

Much warmth,

pt

 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      03-17-2007
On 3/17/07, planetthoughtful <(E-Mail Removed)> wrote:
> Hi,
>
> I'm a newcomer to Ruby in general and to the Gmailer (version 0.1.5)
> class in particular, and I wanted to ask a couple of questions about
> using it, if that's okay?


sure

> In particular, I'm using it across a dialup connection and while I am
> successfully connecting to and retrieving message content from gmail
> using the gmailer class, it's very slow and it often times out on my
> end. Why I don't simply blame this on my connection speed is that
> using a browser to access gmail is still slow, but is also generally
> faster than the gmailer class via Ruby.


I can't say anything about this as I haven't played with it. It should
not be much slower than a real browser -- but that may depend on he
speed of your computer, as parsing in ruby is generally slower than
parsing in C based browser.

> Is that to be expected? The error message I'm getting is below:
>
> c:/ruby/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired
> (Timeout::Error)
> from c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
> from c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
> from c:/ruby/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
> from c:/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
> from c:/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
> from c:/ruby/lib/ruby/1.8/net/http.rb:2017:in
> `read_status_line'
> from c:/ruby/lib/ruby/1.8/net/http.rb:2006:in `read_new'
> from c:/ruby/lib/ruby/1.8/net/http.rb:1047:in `request'
> ... 8 levels...
> from c:/ruby/lib/ruby/gems/1.8/gems/gmailer-0.1.5/gmailer.rb:
> 1570:in `each_msg'
> from gmail.rb:15
> from c:/ruby/lib/ruby/gems/1.8/gems/gmailer-0.1.5/gmailer.rb:
> 1784:in `connect'
> from gmail.rb:10
>
> I've tried looking for a timeout setting for the gmailer class, but
> nothing leaps out at me from the associated readme file.


This message is from Net::HTTP class, and IIRC it's a hardcoded
timeout. (But you may check that somewhere near line 132 in
C:/ruby/lib/ruby/1.8/net/protocol.rb in method `rbuf_fill', as the
error message says (skip the timeout lines, you want to see who called
the timeout)

> Second, is there a way of using the each_msg method to, for example,
> retrieve all of the unread messages in my account's inbox without
> marking those messages as read?
>
> I ask because I have a couple of gmail accounts that I don't access
> regularly, but it would be nice to write a script in Ruby using
> gmailer that logs in and pulls down a summary of the unread messages
> sitting in the inboxes of those accounts. I'd like to leave those
> messages with a status of being unread, though, so that this still
> stands out when I do log into the accounts using my browser.
>
> For some reason, when I use the each_msg method to iterate through
> unread messages, the messages get marked as read. So as it stands
> right now, I'm explicitly setting the messages back to being unread
> (which is probably adding to the execution time of the script), but


to check how much time the 'unreading' really adds, you can use the
benchmark library - run once with unreading and once without and
compare.

to see where the most of the time is spent, use ruby-prof (search the
archive and/or web for a 3 part article how to use it)

> I'm wondering if there's a way to iterate through all the unread
> messages in your inbox and retrieve, for example, the sender's email
> address and the subject line without marking the message as having
> been read?


This I don't know.

I'm wondering if POP3 access would not be faster, as it skips the html
parsing completely, and for your needs it should be sufficient (see
net/pop3, aka Net:OP3)

 
Reply With Quote
 
 
 
 
planetthoughtful
Guest
Posts: n/a
 
      03-18-2007
On Mar 18, 8:02 am, "Jan Svitok" <(E-Mail Removed)> wrote:
> On 3/17/07, planetthoughtful <(E-Mail Removed)> wrote:
>
> > I've tried looking for a timeout setting for the gmailer class, but
> > nothing leaps out at me from the associated readme file.

>
> This message is from Net::HTTP class, and IIRC it's a hardcoded
> timeout. (But you may check that somewhere near line 132 in
> C:/ruby/lib/ruby/1.8/net/protocol.rb in method `rbuf_fill', as the
> error message says (skip the timeout lines, you want to see who called
> the timeout)


Okay, looking at protocol.rb, on line 52 appears the following
"@read_timeout = 60", which is later referenced on line 132
"timeout(@read_timeout) {". So, can I just change this value on line
52 to a larger value?

> > For some reason, when I use the each_msg method to iterate through
> > unread messages, the messages get marked as read. So as it stands
> > right now, I'm explicitly setting the messages back to being unread
> > (which is probably adding to the execution time of the script), but

>
> to check how much time the 'unreading' really adds, you can use the
> benchmark library - run once with unreading and once without and
> compare.
>
> to see where the most of the time is spent, use ruby-prof (search the
> archive and/or web for a 3 part article how to use it)


Thanks for the suggestion - I'll check it out!

> > I'm wondering if there's a way to iterate through all the unread
> > messages in your inbox and retrieve, for example, the sender's email
> > address and the subject line without marking the message as having
> > been read?

>
> This I don't know.
>
> I'm wondering if POP3 access would not be faster, as it skips the html
> parsing completely, and for your needs it should be sufficient (see
> net/pop3, aka Net:OP3)


On one level POP3 might have been a good idea, but the helpful thing
about the gmailer class is that I can use it to just access, for
example, the email messages that are unread and also in my inbox. This
is, in fact, what I'm trying to build - a script that tells me if an
account needs some attention in its inbox.

Whereas, with the POP3 method, I'd have to get every message, and at
least one of these accounts has hundreds, if not thousands of messages
in it.

Thank you for your help and suggestions!

Much warmth,

pt

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gmailer problems. Junkone Ruby 2 08-11-2008 02:31 PM
[ANN] gmailer-0.0.5 Park Heesob Ruby 0 08-28-2005 06:27 AM
[ANN] gmailer 0.0.3 Park Heesob Ruby 3 08-25-2005 02:32 PM
[ANN] gmailer-0.0.2 Park Heesob Ruby 2 08-24-2005 12:45 AM
[ANN] gmailer 0.0.1 (plain text) Park Heesob Ruby 5 08-19-2005 02:53 AM



Advertisments