On 3/17/07, planetthoughtful <planetthoughtful / gmail.com> 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::POP3)