Problems with gmailer

P

planetthoughtful

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
 
J

Jan Svitok

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

planetthoughtful

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?
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!
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top