gmailer 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGES +5 -0
  2. data/README +7 -0
  3. data/gmailer.gempsec +1 -1
  4. data/gmailer.rb +48 -11
  5. metadata +2 -3
  6. data/gmailer-0.1.5.gem +0 -0
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1.7 - 11-Jul-2007
2
+ - some source code refactoring
3
+ - fix connection problem with spaces in label and '=' in credentials.
4
+ - fix incorrect conversation length bug
5
+
1
6
  == 0.1.6 - 16-May-2007
2
7
  - some source code refactoring
3
8
  - add edit_concact, add_contact, delete_contact, add_sender_to_contact method
data/README CHANGED
@@ -23,6 +23,13 @@
23
23
  :body => "Hi...\n\nBlah blah blah~...",
24
24
  :files => ["./my_pic.jpg", "./my_cv.txt"])
25
25
 
26
+ # Send html email
27
+ g.send(
28
+ :to => "who@what.com, my_friend@his_company.com, god@heaven.org",
29
+ :subject => "Hello There!",
30
+ :ishtml => 1,
31
+ :body => "<font color=blue>Hi...\n\nBlah blah blah~...</font>")
32
+
26
33
  # multiple verified email addresses and choose one 'From:' email address
27
34
  g.send(
28
35
  :from => "verified@email.com",
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
4
  gem.name = "gmailer"
5
- gem.version = "0.1.6"
5
+ gem.version = "0.1.7"
6
6
  gem.author = "Park Heesob"
7
7
  gem.email = "phasis_AT_gmail.com"
8
8
  gem.homepage = "http://rubyforge.org/projects/gmailutils"
data/gmailer.rb CHANGED
@@ -52,7 +52,7 @@ GM_ACT_DELSPAM = 20 # delete spam, forever
52
52
  GM_ACT_DELTRASH = 21 # delete trash message, forever
53
53
 
54
54
  module GMailer
55
- VERSION = "0.1.6"
55
+ VERSION = "0.1.7"
56
56
  attr_accessor :connection
57
57
 
58
58
  # the main class.
@@ -143,13 +143,14 @@ module GMailer
143
143
  @timezone = (my_tz*-60).to_i.to_s
144
144
  end
145
145
 
146
+
146
147
  #
147
148
  # return bool
148
149
  # desc Connect to GMail without setting any session/cookie.
149
150
  #
150
151
  def connect_no_cookie()
151
152
 
152
- postdata = "service=mail&Email=" + URI.escape(@login) + "&Passwd=" + URI.escape(@pwd) + "&null=Sign%20in&continue=" +
153
+ postdata = "service=mail&Email=" + URI.escape(@login).gsub('=','%3D') + "&Passwd=" + URI.escape(@pwd).gsub('=','%3D') + "&null=Sign%20in&continue=" +
153
154
  URI.escape('https://mail.google.com/mail/?ui=html&amp;zy=l') + "&rm=false&PersistentCookie=yes"
154
155
 
155
156
  np = Net::HTTP::Proxy(@proxy_host,@proxy_port,@proxy_user,@proxy_pass).new("www.google.com", 443)
@@ -279,6 +280,7 @@ module GMailer
279
280
  matches = inbox.scan(/D\((.*)\)/).flatten
280
281
  packets = {}
281
282
  matches.each do |x|
283
+ x = unescapeHTML(x)
282
284
  tmp = eval(x.gsub(",,",",'',").gsub(",,",",'',").gsub(",]",",'']").gsub('#{','#\{'))
283
285
  if (packets[tmp[0]] || (tmp[0]=="mi"||tmp[0]=="mb"||tmp[0]=="di"))
284
286
  if (tmp[0]=="t"||tmp[0]=="ts"||tmp[0]=="a"||tmp[0]=="cl")
@@ -333,6 +335,7 @@ module GMailer
333
335
  matches = inbox.scan(/D\((.*)\)/).flatten
334
336
  packets = {}
335
337
  matches.each do |x|
338
+ x = unescapeHTML(x)
336
339
  tmp = eval(x.gsub(",,",",'',").gsub(",,",",'',").gsub(",]",",'']").gsub('#{','#\{'))
337
340
  if (packets[tmp[0]] || (tmp[0]=="mi"||tmp[0]=="mb"||tmp[0]=="di"))
338
341
  if (tmp[0]=="t"||tmp[0]=="ts"||tmp[0]=="a"||tmp[0]=="cl")
@@ -358,6 +361,33 @@ module GMailer
358
361
  @raw = packets
359
362
  end
360
363
 
364
+ #
365
+ # return String
366
+ # param string string
367
+ # desc Unescapes properly Unicode escape characters
368
+ #
369
+ def unescapeHTML(str)
370
+ s = str.gsub(/(\\u(.{4}))/n) {
371
+ match = $1.dup
372
+ match = match[1..match.length]
373
+ res=0
374
+ for i in 0 .. match.reverse!.length-1
375
+ res+= (match[i..i].hex)* 16**i
376
+ end
377
+ res.chr
378
+ }.gsub(/&(.*?);/n) {
379
+ match = $1.dup
380
+ case match
381
+ when /\Aamp\z/ni then '&'
382
+ when /\Aquot\z/ni then '\"'
383
+ when /\Agt\z/ni then '>'
384
+ when /\Alt\z/ni then '<'
385
+ when /\A#(\d+)\z/n then Integer($1).chr
386
+ when /\A#x([0-9a-f]+)\z/ni then $1.hex.chr
387
+ end
388
+ }
389
+ end
390
+
361
391
  #
362
392
  # return bool
363
393
  # param constant type
@@ -366,21 +396,21 @@ module GMailer
366
396
  # desc Fetch contents from GMail by type.
367
397
  #
368
398
  def fetch_box(type, box, pos)
369
- @type = type
399
+ @type = type
370
400
  if connected?
371
401
  case type
372
402
  when GM_STANDARD
373
- q = "search=" + box.downcase + "&view=tl&start=" + pos.to_s
403
+ q = "search=" + URI.escape(box.downcase).gsub('=','%3D') + "&view=tl&start=" + pos.to_s
374
404
 
375
405
  when GM_LABEL
376
- q = "search=cat&cat=" + box.to_s + "&view=tl&start=" + pos.to_s
406
+ q = "search=cat&cat=" + URI.escape(box.to_s).gsub('=','%3D') + "&view=tl&start=" + pos.to_s
377
407
 
378
408
  when GM_CONVERSATION
379
409
  pos = "inbox" if (pos.to_s=='' || pos.to_i == 0)
380
410
  if gmail_reserved_names.include?(pos.downcase)
381
- q = "search="+URI.escape(pos)+"&ser=1&view=cv"
411
+ q = "search="+URI.escape(pos).gsub('=','%3D')+"&ser=1&view=cv"
382
412
  else
383
- q = "search=cat&cat="+URI.escape(pos)+"&ser=1&view=cv"
413
+ q = "search=cat&cat="+URI.escape(pos).gsub('=','%3D')+"&ser=1&view=cv"
384
414
  end
385
415
  if (box.is_a?(Array))
386
416
  q += "&th=" + box[0].to_s
@@ -417,7 +447,7 @@ module GMailer
417
447
  q = "view=om&th=" + box.to_s
418
448
 
419
449
  when GM_QUERY
420
- q = "search=query&q=" + URI.escape(box.to_s) + "&view=tl&start=" + pos.to_s
450
+ q = "search=query&q=" + URI.escape(box.to_s).gsub('=','%3D') + "&view=tl&start=" + pos.to_s
421
451
 
422
452
  when GM_PREFERENCE
423
453
  q = "view=pr&pnl=g"
@@ -426,11 +456,11 @@ module GMailer
426
456
  if box.downcase == "all"
427
457
  q = "view=cl&search=contacts&pnl=a"
428
458
  elsif box.downcase == "search"
429
- q = "view=cl&search=contacts&pnl=s&q=" + URI.escape(pos.to_s)
459
+ q = "view=cl&search=contacts&pnl=s&q=" + URI.escape(pos.to_s).gsub('=','%3D')
430
460
  elsif box.downcase == "detail"
431
- q = "search=contacts&ct_id=" + URI.escape(pos.to_s) + "&cvm=2&view=ct"
461
+ q = "search=contacts&ct_id=" + URI.escape(pos.to_s).gsub('=','%3D') + "&cvm=2&view=ct"
432
462
  elsif box.downcase == "group_detail"
433
- q = "search=contacts&ct_id=" + URI.escape(pos.to_s) + "&cvm=1&view=ctl"
463
+ q = "search=contacts&ct_id=" + URI.escape(pos.to_s).gsub('=','%3D') + "&cvm=1&view=ctl"
434
464
  elsif box.downcase == "group"
435
465
  q = "view=cl&search=contacts&pnl=l"
436
466
  else # frequently mailed
@@ -1605,11 +1635,18 @@ module GMailer
1605
1635
  @conv = []
1606
1636
  b = Conversation.new
1607
1637
  raw["mg"].each do |r|
1638
+ puts "KKKKKKKKKKK"
1639
+ puts r[0]
1640
+ puts "================"
1608
1641
  if (r[0] == "mb")
1609
1642
  b.body = '' if b.body.nil?
1610
1643
  b.body += r[1]
1644
+ puts b.body
1645
+ puts "###################"
1611
1646
  if (r[2] == 0)
1612
1647
  b.body = decode(b.body)
1648
+ puts b.body
1649
+ puts "******************"
1613
1650
  @conv.push(b)
1614
1651
  b = Conversation.new
1615
1652
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: gmailer
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.6
7
- date: 2007-05-16 00:00:00 +09:00
6
+ version: 0.1.7
7
+ date: 2007-07-11 00:00:00 +09:00
8
8
  summary: An class interface of the Google's webmail service
9
9
  require_paths:
10
10
  - ""
@@ -31,7 +31,6 @@ authors:
31
31
  files:
32
32
  - CHANGES
33
33
  - CVS
34
- - gmailer-0.1.5.gem
35
34
  - gmailer.gempsec
36
35
  - gmailer.rb
37
36
  - install.rb
Binary file