# Problems with gmailer

**URL:** <https://www.ruby-forum.com/t/problems-with-gmailer/89110>\
**Category:** Ruby\
**Created:** [March 17, 2007, 10:35am UTC](https://www.ruby-forum.com/t/problems-with-gmailer/89110 "2007-03-17T10:35:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![planetthoughtful](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@planetthoughtful](https://www.ruby-forum.com/u/planetthoughtful)\
**Post date:** [March 17, 2007, 10:35am UTC](https://www.ruby-forum.com/t/problems-with-gmailer/89110/1 "2007-03-17T10:35:47Z")

</div>

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\_msg {  
|ml|  
puts “Subject: " + ml.subject + " (” + ml.id.to\_s + “)”  
g.mark\_unread(ml.id)  
}  
end

Thanks in adance for any help!

Much warmth,

pt

---

<div class="post-metadata">

**Author:** ![planetthoughtful](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@planetthoughtful](https://www.ruby-forum.com/u/planetthoughtful)\
**Post date:** [March 17, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/problems-with-gmailer/89110/2 "2007-03-17T23:03:09Z")

</div>

On 3/17/07, planetthoughtful [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

> `read\_status\_line’  
> 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)

> 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)

---

<div class="post-metadata">

**Author:** ![planetthoughtful](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@planetthoughtful](https://www.ruby-forum.com/u/planetthoughtful)\
**Post date:** [March 18, 2007, 2:10am UTC](https://www.ruby-forum.com/t/problems-with-gmailer/89110/3 "2007-03-18T02:10:25Z")

</div>

On Mar 18, 8:02 am, “Jan S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 3/17/07, planetthoughtful [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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?

> 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::POP3)

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
