gmailer 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +4 -0
- data/README +11 -1
- data/gmailer.rb +56 -37
- metadata +2 -2
data/CHANGES
CHANGED
data/README
CHANGED
@@ -50,12 +50,22 @@ Or even
|
|
50
50
|
Or shorter
|
51
51
|
|
52
52
|
GMailer.connect(name, pwd) do |g|
|
53
|
+
# 'From' default gmail.com account
|
53
54
|
g.send(
|
54
55
|
:to => "who@what.com, my_friend@his_company.com, god@heaven.org"
|
55
56
|
:cc => "foo@bar.com"
|
56
57
|
:subject => "Hello There!",
|
57
58
|
:body => "Hi...\n\nBlah blah blah~...",
|
58
59
|
:files => ["./my_pic.jpg", "./my_cv.txt"])
|
60
|
+
|
61
|
+
# multiple verified email addresses and choose one 'From:' email address
|
62
|
+
g.send(
|
63
|
+
:from => "verified@email.com",
|
64
|
+
:to => "who@what.com, my_friend@his_company.com, god@heaven.org"
|
65
|
+
:cc => "foo@bar.com"
|
66
|
+
:subject => "Hello There!",
|
67
|
+
:body => "Hi...\n\nBlah blah blah~...",
|
68
|
+
:files => ["./my_pic.jpg", "./my_cv.txt"])
|
59
69
|
end
|
60
70
|
|
61
71
|
|
@@ -210,7 +220,7 @@ connect(connet hash)
|
|
210
220
|
e.g. connect(:username=>'user',:password=>'pass',:proxy_host=>'proxy-host',
|
211
221
|
:proxy_port=>8080,:proxy_user=>'proxy_user',:proxy_pass=>'proxy_pass')
|
212
222
|
|
213
|
-
|
223
|
+
connected?
|
214
224
|
To check if connected.
|
215
225
|
|
216
226
|
fetch(action hash)
|
data/gmailer.rb
CHANGED
@@ -50,7 +50,7 @@ GM_ACT_DELTRASH = 21 # delete trash message, forever
|
|
50
50
|
|
51
51
|
class GMailer
|
52
52
|
|
53
|
-
VERSION = "0.0.
|
53
|
+
VERSION = "0.0.8"
|
54
54
|
|
55
55
|
@cookie_str
|
56
56
|
@login
|
@@ -231,7 +231,7 @@ class GMailer
|
|
231
231
|
# return bool
|
232
232
|
# desc See if it is connected to GMail.
|
233
233
|
#
|
234
|
-
def
|
234
|
+
def connected?
|
235
235
|
!@cookie_str.empty?
|
236
236
|
end
|
237
237
|
|
@@ -241,11 +241,11 @@ class GMailer
|
|
241
241
|
# desc Fetch contents by URL query.
|
242
242
|
#
|
243
243
|
def __fetch(query)
|
244
|
-
if
|
244
|
+
if connected?
|
245
245
|
Debugger::say("Start fetching query: " + query)
|
246
246
|
query += "&zv=" + (rand(2000)*2147483.648).to_i.to_s
|
247
247
|
np = Net::HTTP::Proxy(@proxy_host,@proxy_port,@proxy_user,@proxy_pass).new(GM_LNK_HOST, 80)
|
248
|
-
#
|
248
|
+
# np.set_debug_output($stderr)
|
249
249
|
inbox = ''
|
250
250
|
np.start { |http|
|
251
251
|
response = http.get(GM_LNK_GMAIL + "?" + query,{'Cookie' => @cookie_str,'User-agent' => GM_USER_AGENT })
|
@@ -299,7 +299,7 @@ class GMailer
|
|
299
299
|
#
|
300
300
|
def fetch_box(type, box, pos)
|
301
301
|
|
302
|
-
if
|
302
|
+
if connected?
|
303
303
|
case type
|
304
304
|
when GM_STANDARD
|
305
305
|
q = "search=" + box.downcase + "&view=tl&start=" + pos.to_s
|
@@ -398,7 +398,7 @@ class GMailer
|
|
398
398
|
#
|
399
399
|
def attachments_of(convs, path)
|
400
400
|
|
401
|
-
if
|
401
|
+
if connected?
|
402
402
|
if (convs.class != Array)
|
403
403
|
convs = [convs] # array wrapper
|
404
404
|
end
|
@@ -428,7 +428,7 @@ class GMailer
|
|
428
428
|
#
|
429
429
|
def zip_attachments_of(convs, path)
|
430
430
|
|
431
|
-
if
|
431
|
+
if connected?
|
432
432
|
if (convs.class != Array)
|
433
433
|
convs = [convs] # array wrapper
|
434
434
|
end
|
@@ -457,7 +457,7 @@ class GMailer
|
|
457
457
|
#
|
458
458
|
def attachment(attid, msgid, filename, zipped=false)
|
459
459
|
|
460
|
-
if
|
460
|
+
if connected?
|
461
461
|
Debugger::say("Start getting attachment...")
|
462
462
|
|
463
463
|
if !zipped
|
@@ -486,7 +486,7 @@ class GMailer
|
|
486
486
|
# desc get label lists
|
487
487
|
#
|
488
488
|
def labels()
|
489
|
-
if
|
489
|
+
if connected?
|
490
490
|
fetch(:standard=>"inbox") {|s| s.label_list }
|
491
491
|
else
|
492
492
|
nil
|
@@ -518,7 +518,7 @@ class GMailer
|
|
518
518
|
# desc create label
|
519
519
|
#
|
520
520
|
def create_label(label)
|
521
|
-
if
|
521
|
+
if connected?
|
522
522
|
perform_action(GM_ACT_CREATELABEL, '', validate_label(label))
|
523
523
|
else
|
524
524
|
false
|
@@ -531,7 +531,7 @@ class GMailer
|
|
531
531
|
# desc create label
|
532
532
|
#
|
533
533
|
def delete_label(label)
|
534
|
-
if
|
534
|
+
if connected?
|
535
535
|
perform_action(GM_ACT_DELETELABEL, '', validate_label(label))
|
536
536
|
else
|
537
537
|
false
|
@@ -545,7 +545,7 @@ class GMailer
|
|
545
545
|
# desc create label
|
546
546
|
#
|
547
547
|
def rename_label(old_label,new_label)
|
548
|
-
if
|
548
|
+
if connected?
|
549
549
|
perform_action(GM_ACT_RENAMELABEL, '',
|
550
550
|
validate_label(old_label) +'^' + validate_label(new_label))
|
551
551
|
else
|
@@ -560,7 +560,7 @@ class GMailer
|
|
560
560
|
# desc apply label to message
|
561
561
|
#
|
562
562
|
def apply_label(id,label)
|
563
|
-
if
|
563
|
+
if connected?
|
564
564
|
perform_action(GM_ACT_APPLYLABEL, id, validate_label(label))
|
565
565
|
else
|
566
566
|
false
|
@@ -574,7 +574,7 @@ class GMailer
|
|
574
574
|
# desc remove label from message
|
575
575
|
#
|
576
576
|
def remove_label(id,label)
|
577
|
-
if
|
577
|
+
if connected?
|
578
578
|
perform_action(GM_ACT_REMOVELABEL, id, validate_label(label))
|
579
579
|
else
|
580
580
|
false
|
@@ -587,7 +587,7 @@ class GMailer
|
|
587
587
|
# desc remove label from message
|
588
588
|
#
|
589
589
|
def update_preference(hash_param)
|
590
|
-
if
|
590
|
+
if connected?
|
591
591
|
args = {}
|
592
592
|
hash_param.keys.each do |k|
|
593
593
|
case k
|
@@ -622,7 +622,7 @@ class GMailer
|
|
622
622
|
# desc apply star to a message
|
623
623
|
#
|
624
624
|
def apply_star(msgid)
|
625
|
-
if
|
625
|
+
if connected?
|
626
626
|
perform_action(GM_ACT_STAR,msgid, '')
|
627
627
|
else
|
628
628
|
false
|
@@ -635,7 +635,7 @@ class GMailer
|
|
635
635
|
# desc remove star from a message
|
636
636
|
#
|
637
637
|
def remove_star(msgid)
|
638
|
-
if
|
638
|
+
if connected?
|
639
639
|
perform_action(GM_ACT_UNSTAR,msgid, '')
|
640
640
|
else
|
641
641
|
false
|
@@ -648,7 +648,7 @@ class GMailer
|
|
648
648
|
# desc report a message as spam
|
649
649
|
#
|
650
650
|
def report_spam(msgid)
|
651
|
-
if
|
651
|
+
if connected?
|
652
652
|
perform_action(GM_ACT_SPAM,msgid, '')
|
653
653
|
else
|
654
654
|
false
|
@@ -661,7 +661,7 @@ class GMailer
|
|
661
661
|
# desc report a message as not spam
|
662
662
|
#
|
663
663
|
def not_spam(msgid)
|
664
|
-
if
|
664
|
+
if connected?
|
665
665
|
perform_action(GM_ACT_UNSPAM,msgid, '')
|
666
666
|
else
|
667
667
|
false
|
@@ -674,7 +674,7 @@ class GMailer
|
|
674
674
|
# desc delete a spam message forever
|
675
675
|
#
|
676
676
|
def delete_spam(msgid)
|
677
|
-
if
|
677
|
+
if connected?
|
678
678
|
perform_action(GM_ACT_DELSPAM,msgid, '')
|
679
679
|
else
|
680
680
|
false
|
@@ -687,7 +687,7 @@ class GMailer
|
|
687
687
|
# desc mark a message as read
|
688
688
|
#
|
689
689
|
def mark_read(msgid)
|
690
|
-
if
|
690
|
+
if connected?
|
691
691
|
perform_action(GM_ACT_READ,msgid, '')
|
692
692
|
else
|
693
693
|
false
|
@@ -700,7 +700,7 @@ class GMailer
|
|
700
700
|
# desc mark a message as unread
|
701
701
|
#
|
702
702
|
def mark_unread(msgid)
|
703
|
-
if
|
703
|
+
if connected?
|
704
704
|
perform_action(GM_ACT_UNREAD,msgid, '')
|
705
705
|
else
|
706
706
|
false
|
@@ -713,7 +713,7 @@ class GMailer
|
|
713
713
|
# desc move a message to trash
|
714
714
|
#
|
715
715
|
def trash_in(msgid)
|
716
|
-
if
|
716
|
+
if connected?
|
717
717
|
perform_action(GM_ACT_TRASH,msgid, '')
|
718
718
|
else
|
719
719
|
false
|
@@ -726,7 +726,7 @@ class GMailer
|
|
726
726
|
# desc move a message from trash to inbox
|
727
727
|
#
|
728
728
|
def trash_out(msgid)
|
729
|
-
if
|
729
|
+
if connected?
|
730
730
|
perform_action(GM_ACT_UNTRASH,msgid, '')
|
731
731
|
else
|
732
732
|
false
|
@@ -739,7 +739,7 @@ class GMailer
|
|
739
739
|
# desc delete a trash message forever
|
740
740
|
#
|
741
741
|
def delete_trash(msgid)
|
742
|
-
if
|
742
|
+
if connected?
|
743
743
|
perform_action(GM_ACT_DELTRASH,msgid, '')
|
744
744
|
else
|
745
745
|
false
|
@@ -752,7 +752,7 @@ class GMailer
|
|
752
752
|
# desc delete a message forever
|
753
753
|
#
|
754
754
|
def delete_message(msgid)
|
755
|
-
if
|
755
|
+
if connected?
|
756
756
|
perform_action(GM_ACT_DELFOREVER,msgid, '')
|
757
757
|
else
|
758
758
|
false
|
@@ -765,7 +765,7 @@ class GMailer
|
|
765
765
|
# desc archive a message
|
766
766
|
#
|
767
767
|
def archive(msgid)
|
768
|
-
if
|
768
|
+
if connected?
|
769
769
|
perform_action(GM_ACT_ARCHIVE,msgid, '')
|
770
770
|
else
|
771
771
|
false
|
@@ -778,7 +778,7 @@ class GMailer
|
|
778
778
|
# desc archive a message
|
779
779
|
#
|
780
780
|
def unarchive(msgid)
|
781
|
-
if
|
781
|
+
if connected?
|
782
782
|
perform_action(GM_ACT_INBOX,msgid, '')
|
783
783
|
else
|
784
784
|
false
|
@@ -790,7 +790,7 @@ class GMailer
|
|
790
790
|
# desc get preferences
|
791
791
|
#
|
792
792
|
def preference()
|
793
|
-
if
|
793
|
+
if connected?
|
794
794
|
fetch(:preference=>"all").preference
|
795
795
|
else
|
796
796
|
nil
|
@@ -802,7 +802,7 @@ class GMailer
|
|
802
802
|
# desc get message lists
|
803
803
|
#
|
804
804
|
def messages(hash_param)
|
805
|
-
if
|
805
|
+
if connected?
|
806
806
|
fetch(hash_param) {|s| s.box }
|
807
807
|
else
|
808
808
|
nil
|
@@ -816,7 +816,7 @@ class GMailer
|
|
816
816
|
#
|
817
817
|
def dump(query)
|
818
818
|
page = ''
|
819
|
-
if
|
819
|
+
if connected?
|
820
820
|
Debugger::say("Dumping...")
|
821
821
|
query += "&zv=" + (rand(2000)*2147483.648).to_i.to_s
|
822
822
|
np = Net::HTTP::Proxy(@proxy_host,@proxy_port,@proxy_user,@proxy_pass).new(GM_LNK_HOST, 80)
|
@@ -852,6 +852,7 @@ class GMailer
|
|
852
852
|
def send(*param)
|
853
853
|
if param.length==1 && param[0].class==Hash
|
854
854
|
param = param[0]
|
855
|
+
from = param[:from] || ''
|
855
856
|
to = param[:to] || ''
|
856
857
|
subject = param[:subject] || ''
|
857
858
|
body = param[:body] || ''
|
@@ -864,12 +865,23 @@ class GMailer
|
|
864
865
|
draft_id = param[:draft_id] || ''
|
865
866
|
elsif param.length==10
|
866
867
|
to, subject, body, cc, bcc, msg_id, thread_id, files, draft, draft_id = param
|
868
|
+
elsif param.length==11
|
869
|
+
from, to, subject, body, cc, bcc, msg_id, thread_id, files, draft, draft_id = param
|
867
870
|
else
|
868
871
|
raise ArgumentError, 'Invalid argument'
|
869
872
|
end
|
870
873
|
|
871
|
-
if
|
874
|
+
if connected?
|
872
875
|
Debugger::say("Starting to send mail...")
|
876
|
+
other_emails = fetch(:preference=>"all").other_emails
|
877
|
+
if other_emails.length>0
|
878
|
+
other_emails.each {|v|
|
879
|
+
from = v['email'] if from=='' && v['default']
|
880
|
+
}
|
881
|
+
from = @login + 'gmail.com' if from==''
|
882
|
+
else
|
883
|
+
from = nil
|
884
|
+
end
|
873
885
|
|
874
886
|
postdata = {}
|
875
887
|
if draft
|
@@ -884,6 +896,7 @@ class GMailer
|
|
884
896
|
postdata["th"] = thread_id
|
885
897
|
end
|
886
898
|
postdata["msgbody"] = stripslashes(body)
|
899
|
+
postdata["from"] = stripslashes(from) if from
|
887
900
|
postdata["to"] = stripslashes(to)
|
888
901
|
postdata["subject"] = stripslashes(subject)
|
889
902
|
postdata["cc"] = stripslashes(cc)
|
@@ -920,7 +933,7 @@ class GMailer
|
|
920
933
|
|
921
934
|
np = Net::HTTP::Proxy(@proxy_host,@proxy_port,@proxy_user,@proxy_pass).new(GM_LNK_HOST, 80)
|
922
935
|
response = nil
|
923
|
-
#
|
936
|
+
# np.set_debug_output($stderr)
|
924
937
|
np.start { |http|
|
925
938
|
response = http.post(GM_LNK_GMAIL, postdata,{'Cookie' => @cookie_str,'User-agent' => GM_USER_AGENT,'Content-type' => 'multipart/form-data; boundary=' + boundary } )
|
926
939
|
}
|
@@ -942,7 +955,7 @@ class GMailer
|
|
942
955
|
#
|
943
956
|
def perform_action(act, id, para)
|
944
957
|
|
945
|
-
if
|
958
|
+
if connected?
|
946
959
|
Debugger::say("Start performing action...")
|
947
960
|
|
948
961
|
if (act == GM_ACT_DELFOREVER)
|
@@ -987,7 +1000,7 @@ class GMailer
|
|
987
1000
|
end
|
988
1001
|
|
989
1002
|
np = Net::HTTP::Proxy(@proxy_host,@proxy_port,@proxy_user,@proxy_pass).new(GM_LNK_HOST, 80)
|
990
|
-
#
|
1003
|
+
# np.set_debug_output($stderr)
|
991
1004
|
np.start { |http|
|
992
1005
|
response = http.post(link, postdata,{'Cookie' => @cookie_str,'User-agent' => GM_USER_AGENT} )
|
993
1006
|
result = response.body
|
@@ -1068,7 +1081,7 @@ class GMailer
|
|
1068
1081
|
#
|
1069
1082
|
def invite(email)
|
1070
1083
|
|
1071
|
-
if
|
1084
|
+
if connected?
|
1072
1085
|
Debugger::say("Start sending invite...")
|
1073
1086
|
|
1074
1087
|
postdata = "act=ii&em=" + URI.escape(email)
|
@@ -1170,7 +1183,7 @@ class GMailSnapshot
|
|
1170
1183
|
attr_reader :std_box_new, :have_invit, :label_list, :label_new
|
1171
1184
|
attr_reader :box_name, :box_total, :box_pos, :box
|
1172
1185
|
attr_reader :conv_title, :conv_total, :conv_id, :conv_labels, :conv_starred, :conv
|
1173
|
-
attr_reader :contacts
|
1186
|
+
attr_reader :contacts, :other_emails
|
1174
1187
|
|
1175
1188
|
def initialize(type, raw, charset='UTF-8')
|
1176
1189
|
|
@@ -1389,6 +1402,12 @@ class GMailSnapshot
|
|
1389
1402
|
@label_list.push(v[0])
|
1390
1403
|
@label_total.push(v[1])
|
1391
1404
|
}
|
1405
|
+
@other_emails = []
|
1406
|
+
if raw["cfs"]
|
1407
|
+
raw["cfs"][1].each {|v|
|
1408
|
+
@other_emails.push({"name"=>decode(v[0]),"email"=>v[1],"default"=>(v[2]==1)})
|
1409
|
+
}
|
1410
|
+
end
|
1392
1411
|
@filter = []
|
1393
1412
|
@filter_rules = []
|
1394
1413
|
raw["fi"][1].each { |fi|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: gmailer
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.0.8
|
7
|
+
date: 2005-09-03
|
8
8
|
summary: "An class interface of the Google's webmail service"
|
9
9
|
require_paths:
|
10
10
|
- ''
|