[ANN] gmailer 0.0.3

GMailer is a class for interface to Google's webmail service.

It can fetch mails, save attachements, get cotact lists, invite someone
or send message with file attachments. You can make GMail as an online
backup system or as a virtual filesystem with this library.

Now usage is very simple and compact like this:

GMailer.connect(name,pwd) do |g|
  #fetch
  g.fetch(:label=>"my_label") {|snapshot|
        puts "Total # of conversations of my_label = " +
snapshot.box_total.to_s
  }

  #get contact
  g.fetch(:contact=>"freq").each do |item|
    puts "Name: #{item['name']} Email: #{item['email']}"
  end

  #send
  g.send(
      :to => "whoo@foo.bar",
      :subj => "Hello There!",
      :body => "Hi...\n\nBlah blah blah~...",
      :files => ["./test.txt"]
   )

  # get labels
  labels = g.get_labels

  # get messages
  g.get_messages(:label=>labels[0]).each {|m|
     puts "Subject: #{m['subj']} / Snippet: #{m['snippet']}" if m['new?']
  }
end

Now you can connect with proxy server like this

GMailer.connect(:username=>name,:password=>pwd,
                        :proxy_host=>proxy,:proxy_port=>8080,
                        :proxy_user=>user,:proxy_pass=>pass) { |g|
    ...
}

But proxy connection needs some tests.

Project:: http://rubyforge.org/projects/gmailutils/
Bugs:: http://rubyforge.org/tracker/?group_id=869

Regards,

Park Heesob

Park Heesob wrote:

GMailer is a class for interface to Google's webmail service.

It can fetch mails, save attachements, get cotact lists, invite someone
or send message with file attachments. You can make GMail as an online
backup system or as a virtual filesystem with this library.

Thanks, very nice.

Do you plan on releasing this as a gem?

James

···

--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys

Park Heesob wrote:

GMailer is a class for interface to Google's webmail service.

It can fetch mails, save attachements, get cotact lists, invite someone
or send message with file attachments. You can make GMail as an online
backup system or as a virtual filesystem with this library.

...
I was just trying out a variation of your example, and got an error at line 305 of gmailer.rb.

   q = "search=cat&cat=" + box + "&view=tl&start=" + pos.to_s

'box', it seems, might be nil. So I added a call to to_s

  q = "search=cat&cat=" + box.to_s + "&view=tl&start=" + pos.to_s

Also, two suggestions for a very cool library (and thanks for writing it):

Remove the camelCase names and break code early before people start building dependencies. (I'm not convinced that simply aliasing these names is a good solution.)

Replace the cryptic parameters ( e.g. :mid, :tid, :orig_df ) with something readable. Even :subj should be :subject.

Thanks again for your efforts!

James

···

--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys

Hi Park,

<snip>

Now you can connect with proxy server like this

GMailer.connect(:username=>name,:password=>pwd,
                        :proxy_host=>proxy,:proxy_port=>8080,
                        :proxy_user=>user,:proxy_pass=>pass) { |g|
    ...
}

But proxy connection needs some tests.

I tested it with both with and without proxy. On Win 2K Pro and
ruby 1.8.2 (2004-12-25) [i386-mswin32] it error'd on the following
code, in both cases (different errors):

···

--- Park Heesob <phasis@bcline.com> wrote:

#-------------------------

require "gmailer"

name = "stdate"
pwd = gets
proxy = "firewall.corp.proxy.com"

GMailer.connect(name,pwd) do |g|

# Now you can connect with proxy server like this
# GMailer.connect(:username=>name,:password=>pwd,
# :proxy_host=>proxy,:proxy_port=>80) do |g|
#:proxy_user=>user,:proxy_pass=>pass)
                        
  puts "------ fetch"
  g.fetch(:label=>"my_label") {|snapshot|
        puts "Total # of conversations of my_label = " + snapshot.box_total.to_s
  }

  puts "------ get contact"
  g.fetch(:contact=>"freq").each do |item|
    puts "Name: #{item['name']} \nEmail: #{item['email']}"
  end

  puts "------ send"
  g.send(
      :to => "shanko_date@yahoo.com",
      :subj => "Hello There!",
      :body => "Hi...\n\nBlah blah blah~...",
      :files => ["./junk.jpeg"]
   )

  puts "------ get labels"
  labels = g.get_labels
  p labels

  puts "------ get messages"
  g.get_messages(:label=>labels[0]).each {|m|
     puts "Subject: #{m['subj']} / Snippet: #{m['snippet']}" if m['new?']
  }
end

__END__

#--------------------------------------------------------------------------

===================================
Here is the transcript with Proxy:

C:\atest>ruby tst_gmailer3.rb
my password here :slight_smile:
c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in `initialize': getaddrinfo: servname not supported for
ai_socktype. (SocketError)
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in `new'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in `connect'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:82:in `timeout'
        from c:/ruby/lib/ruby/1.8/timeout.rb:55:in `timeout'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:82:in `connect'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:64:in `initialize'
        from c:/ruby/lib/ruby/site_ruby/1.8/net/protocols.rb:37:in `initialize'
        from c:/ruby/lib/ruby/1.8/net/http.rb:430:in `open'
        from c:/ruby/lib/ruby/1.8/net/http.rb:430:in `do_start'
        from c:/ruby/lib/ruby/1.8/net/http.rb:419:in `start'
        from c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:148:in `connectNoCookie'
        from c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:217:in `connect'
        from tst_gmailer3.rb:10

===================================
And here without proxy:

C:\atest>ruby tst_gmailer3.rb
my password here :slight_smile:
------ fetch
Total # of conversations of my_label = 0
------ get contact
Name: shanko_date
Email: shanko_date@yahoo.com
Name: shashank
Email: shashank@juno.com
------ send
------ get labels

------ get messages
c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:305:in `+': cannot convert nil into String (TypeError)
        from c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:305:in `fetchBox'
        from c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:379:in `fetch'
        from c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:502:in `get_messages'
        from tst_gmailer3.rb:37
        from tst_gmailer3.rb:7:in `connect'
        from tst_gmailer3.rb:7

C:\atest>

===================================
HTH,
-- shanko

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

Hi,

<snip>

===================================
And here without proxy:

C:\atest>ruby tst_gmailer3.rb
my password here :slight_smile:
------ fetch
Total # of conversations of my_label = 0
------ get contact
Name: shanko_date
Email: shanko_date@yahoo.com
Name: shashank
Email: shashank@juno.com
------ send
------ get labels

------ get messages
c:/ruby/lib/ruby/site_ruby/1.8/gmailer.rb:305:in `+': cannot convert nil into String (TypeError)

I think I found a _workaround_ for this problem:

Add the following line before line 379:

    box = "inbox" unless box

This is in the method fetch method just before
the call to fetchBox(type,box,pos)

HTH,
-- shanko

···

--- Shashank Date <shanko_date@yahoo.com> wrote:

____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs