summarylogtreecommitdiffstats
path: root/svn-47.patch
blob: d572cff5be3e170bf807668058920e5b33dcc1b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
diff -aur checkgmail-1.13/ChangeLog checkgmail-svn/ChangeLog
--- checkgmail-1.13/ChangeLog	2008-01-18 18:36:45.000000000 -0500
+++ checkgmail-svn/ChangeLog	2011-12-25 15:32:53.000000000 -0500
@@ -1,3 +1,9 @@
+(Version 1.14 - SVN, not yet released)
+- New Feature: Show the number of unread messages beside the tray icon with the -numbers switch.  It's pretty basic and ugly right now, but it works ok.  I may think about modifying the display to an iPhone-style numbers thing at some time in the future ... (This will require re-writing the tray icon code, but it's possible in theory).
+- Changed: Tray icon transparency should now work (I think!)  It's a kludgy hack, but it works for Ubuntu's default theme for Lucid Lynx (10.04), and seems to work for most other GTK themes.  Setting the tray icon background doesn't work anymore, and should be deprecated soon.
+- Changed: -no_login is now default behaviour (since we can no longer log into Gmail directly)
+- Lots of other bugfixes, compatibility fixes and changes
+
 (Version 1.13 - 19/1/08)
 - New Feature: -update command-line switch will download the latest version of the program from SVN and show the user a diff between the two versions, before asking the user if they want to upgrade.  This feature will hopefully be improved in newer versions (at the moment there is no version tracking or checking routinely for updates).
 - New Feature: Restart command in right-click menu (makes it easy to restart the program if it hangs on "Checking Gmail ...")
diff -aur checkgmail-1.13/checkgmail checkgmail-svn/checkgmail
--- checkgmail-1.13/checkgmail	2008-01-17 01:30:23.000000000 -0500
+++ checkgmail-svn/checkgmail	2011-12-25 15:32:53.000000000 -0500
@@ -5,8 +5,8 @@
 # system tray; optionally saves password in encrypted form using
 # machine-unique passphrase
 
-# version 1.12.1svn (25/6/2007)
-# Copyright © 2005-7 Owen Marshall
+# version 1.14pre2-svn (4/11/2010)
+# Copyright © 2005-10 Owen Marshall
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -31,12 +31,16 @@
 # Command-line processing
 #
 
-my ($version, $silent, $nocrypt, $update, $notsexy, $profile, $disable_monitors_check, $private, $cookies, $popup_size, $hosted_tmp, $show_popup_delay, $popup_persistence, $usekwallet, $libsexy);
+# global variables (can't be set global in the BEGIN block)
+my ($version, $silent, $nocrypt, $update, $notsexy, $profile, $disable_monitors_check, 
+		$private, $cookies, $popup_size, $hosted_tmp, $show_popup_delay, 
+		$popup_persistence, $usekwallet, $libsexy, $nologin, $mailno, $debug);
 BEGIN {
-	$version = "1.12.1svn";
+	$version = "1.14pre2-svn";
 	$silent = 1;
 	$profile = "";
 	$cookies = 1;
+	$nologin = 1;
 	$show_popup_delay = 250;
 	$popup_persistence = 100;
 	
@@ -64,6 +68,10 @@
 				$notsexy = 1;
 				last };
 				
+			/no-login/ && do {
+				$nologin = 1;
+				last };
+				
 			/cookie_login/ && do {
 				$cookies = 1;
 				last };
@@ -105,8 +113,20 @@
 				$update = 1;
 				last };
 				
-			print "CheckGmail v$version\nCopyright © 2005-7 Owen Marshall\n\n";
-			print "usage: checkgmail [-profile=profile_name] [-popup_delay=millisecs] [-hosted=hosted_domain] [-no_cookies] [-popup_persistence=millisecs] [-private] [-v | -verbose] [-nocrypt] [-no-libsexy] [-disable-monitors-check] [-update] [-h]\n\n";
+				
+			/numbers/ && do {
+				$mailno = 1;
+				last };
+				
+			/debug/ && do {
+				$debug = 1;
+				$silent = 0;
+				last };
+				
+				
+				
+			print "CheckGmail v$version\nCopyright © 2005-10 Owen Marshall\n\n";
+			print "usage: checkgmail [-profile=profile_name] [-popup_delay=millisecs] [-hosted=hosted_domain] [-no_cookies] [-popup_persistence=millisecs] [-private] [-v | -verbose] [-nocrypt] [-no-libsexy] [-disable-monitors-check] [-numbers] [-update] [-h]\n\n";
 			exit 1;
 			
 		}	
@@ -158,6 +178,7 @@
 	my $failed_packages;
 		
 	my $eval_sub = sub {
+		print "$_\n" if $debug;
 		eval $_;
 		if ($@) {
 			return unless m/(use|require)\s*([\w:-]+).*?\;/;
@@ -176,9 +197,12 @@
 	use Thread::Queue;
 	use Thread::Semaphore;
 	use threads::shared;
+	use Encode;
 	use XML::Simple;
 	use FileHandle;
 	use LWP::UserAgent;
+	# use LWP::Debug qw(+);
+	use HTTP::Request::Common;
 	use Crypt::SSLeay;
 	")) {&$eval_sub($_)};
 	if ($failed_packages) {
@@ -332,6 +356,7 @@
 my $HOME : shared;
 my $icons_dir : shared;
 my $gmail_at : shared;
+my $gmail_ik : shared;
 my $gmail_hid : shared;
 my $gmail_sid : shared;
 my $gmail_gausr : shared;
@@ -355,14 +380,17 @@
 my $fat_lady = new Thread::Semaphore(0);
 my $child_exit : shared = 0; # to signal exit to child
 
+print "About to start new thread ...\n" if $debug;
 # Start http checking thread ...
 my $http_check = new threads(\&http_check);
+print "Parent: Process now continues ...\n" if $debug;
 
 
 #######################
 # Prefs and Variables
 #
 
+print "Parent: Setting up global variables ...\n" if $debug;
 # Prefs hash
 my %pref_variables = (
 	user => \$user,
@@ -409,27 +437,33 @@
 $gmail_address = gen_prefix_url()."/feed/atom";
 # $gmail_address = $hosted ? "mail.google.com/a/$hosted/feed/atom" : "mail.google.com/mail/feed/atom";
 
+# for every gmail action ...
 my %gmail_act = (
 	archive => 'rc_%5Ei',
 	read => 'rd',
 	spam => 'sp',
 	delete => 'tr',
+	star => 'st',
+	unstar => 'xst',
 );
 
+# ... there's a gmail re-action :)
 my %gmail_undo = (
 	archive => 'ib',
 	read => 'ur',
 	spam => 'us',
 	delete => 'ib:trash',
+	star => 'xst',
 );
 
 my @undo_buffer;
-my $ua;
+my ($ua, $cookie_jar);
 my ($menu_x, $menu_y);
 my @popup_status;
 my $status_label;
 # my $message_flag;
 
+print "Parent: Checking the existence of ~/.checkgmail ...\n" if $debug;
 # Create the default .checkgmail directory and migrate prefs from users of older versions
 unless (-d $prefs_dir) {
 	if (-e "$prefs_dir") {
@@ -452,22 +486,26 @@
 # Icons
 #
 
+print "Parent: Loading icon data ...\n" if $debug;
 # we load the pixmaps as uuencoded data
-my ($error_data, $no_mail_data, $mail_data, $compose_mail_data);
+my ($error_data, $no_mail_data, $mail_data, $compose_mail_data, $star_on_data, $star_off_data);
 load_icon_data();
 
-my ($no_mail_pixbuf, $mail_pixbuf, $error_pixbuf);
+my ($no_mail_pixbuf, $mail_pixbuf, $error_pixbuf, $star_pixbuf, $nostar_pixbuf);
 my ($custom_no_mail_pixbuf, $custom_mail_pixbuf, $custom_error_pixbuf);
 set_icons();
 
 my $image = Gtk2::Image->new_from_pixbuf($no_mail_pixbuf);
 
+
 ##############
 # Setup tray
 #
 
+print "Parent: Setting up system tray ...\n" if $debug;
 my $tray = Gtk2::TrayIcon->new("gmail");
 my $eventbox = Gtk2::EventBox->new;
+my $ebox2 = Gtk2::EventBox->new;
 my $tray_hbox = Gtk2::HBox->new(0,0);
 $tray_hbox->set_border_width(2);
 
@@ -485,17 +523,29 @@
 my %issued_h;
 my @labels;
 
-$eventbox->add($tray_hbox);
+$eventbox->add($ebox2);
+$ebox2->add($tray_hbox);
 $tray_hbox->pack_start($image,0,0,0);
 
+# number of new mail messages (use -numbers)
+my $number_label;
+if ($mailno) {
+	$number_label = Gtk2::Label->new;
+	$number_label->hide;
+	$number_label->set_markup("0");
+	$tray_hbox->pack_start($number_label,0,0,2);
+}
+
 
 ########################
 # Read prefs and login
 #
 
+print "Parent: Reading translations ...\n" if $debug;
 # Read translations if they exist ...
 read_translations();
 
+print "Parent: Reading prefs ...\n" if $debug;
 # First time configuration ...
 unless (read_prefs()) {
 	show_prefs();
@@ -532,7 +582,7 @@
 
 $tray->add($eventbox);
 $tray->show_all;
-
+print "Parent: System tray now complete ...\n" if $debug;
 
 ############################
 # enter/leave notification
@@ -603,6 +653,7 @@
 # All set? Let's login ...
 #
 
+print "Parent: Sending semaphore to child process ...\n" if $debug;
 # She's singing ...
 $fat_lady->up;
 
@@ -675,6 +726,7 @@
 
 sub http_check {
 	# Threaded process for sending HTTP requests ...
+	print "Child: Checking thread now starting ... waiting for semaphore to continue\n" if $debug;
 	
 	# Variable initialisation isn't over until the fat lady sings ...
 	$fat_lady->down;
@@ -682,6 +734,8 @@
 		
 	# set up the useragent ....
 	$ua = LWP::UserAgent->new();
+	$ua->requests_redirectable (['GET', 'HEAD', 'POST']);
+	# push @{ $ua->requests_redirectable }, 'POST';
 	
 	# set time-out - defaults to 90 seconds or $delay, whichever is shorter
 	$ua->timeout($delay/1000<90 ? $delay/1000 : 90);	
@@ -689,7 +743,7 @@
 	# Get the cookie if requested
 	if ($cookies) {		
 		use HTTP::Cookies;
-		my $cookie_jar = HTTP::Cookies->new();
+		$cookie_jar = HTTP::Cookies->new();
 		
 		$ua->cookie_jar($cookie_jar);
 		
@@ -715,15 +769,22 @@
 			# deciphering the login form! :)
 			unless ($hosted) {
 				# Normal Gmail login action ...
-				$error = http_get("https://www.google.com/accounts/ServiceLoginAuth?ltmpl=yj_wsad&ltmplcache=2&continue=https%3A%2F%2Fmail.google.com%2Fmail%3F&service=mail&rm=false&ltmpl=yj_wsad&Email=$URI_user&Passwd=$URI_passwd&rmShown=1&null=Sign+in", "LOGIN");
+				$error = http_get("Email=$URI_user&Passwd=$URI_passwd", "LOGIN");
+
 				# $cookie_jar->scan(\&scan_at);
+				# unless ($error || !$gmail_sid || !$gmail_gausr) {
+					# $error = http_get("https://mail.google.com/mail/?pli=1&auth=$gmail_sid&gausr=$gmail_gausr", 'LOGIN');
+				# }
+
 				# $error = http_get("https://mail.google.com/mail?nsr=0&auth=$gmail_sid&gausr=$gmail_gausr", "LOGIN");
 	
 			} else {
 				# hosted domains work differently ...
 				# First we POST a login
-				$error = http_get("https://www.google.com/a/$hosted/LoginAction|at=null&continue=http%3A%2F%2Fmail.google.com%2Fa%2F$hosted&service=mail&userName=$URI_user&password=$URI_passwd", "POST");
-				
+				# $error = http_get("https://www.google.com/a/$hosted/LoginAction|at=null&continue=http%3A%2F%2Fmail.google.com%2Fa%2F$hosted&service=mail&userName=$URI_user&password=$URI_passwd", "POST");
+				# thanks to Olinto Neto for this fix for hosted domains:
+				$error = http_get("https://www.google.com/a/$hosted/LoginAction2|at=null&continue=http%3A%2F%2Fmail.google.com%2Fa%2F$hosted&service=mail&Email=$URI_user&Passwd=$URI_passwd", "POST");
+
 				# Then we grab the HID ("Hosted ID"?) cookie
 				$cookie_jar->scan(\&scan_at);
 				
@@ -821,42 +882,115 @@
 		$ua->request($req);
 		return;
 		
+	} elsif ($method eq 'POST_MB') {
+		# quick hack to grab the message text ...
+		my ($add1, $add2) = ($address =~ m/(.*)\|(.*)/);
+		# print "($add1, $add2)\n" unless $silent;
+		
+		my $req = HTTP::Request->new('POST' => $add1);
+  		$req->content_type('application/x-www-form-urlencoded');
+  		$req->content($add2);
+		
+		my $response = $ua->request($req);
+		
+		my $http = $response->content;
+		$label =~ s/\///g;
+		return "LABEL=$label\n$http";
+		
 	} elsif ($method eq 'LOGIN') {
-		# a further hack to streamline the cookie login process
-		my $req = HTTP::Request->new('GET' => "$address");
-
+		# New LOGIN method written by Gerben van der Lubbe on Oct 6, 2009.
+		# (based in turn on vially's (https://sourceforge.net/users/vially/) PHP code.
+		
+		# Well, we did get a URL here, but it doesn't make any sense to send both LOGIN and the URL to this function.
+		# So, this URL is just the username and password addition.
+		my $req = HTTP::Request->new('GET' => "https://www.google.com/accounts/ServiceLogin?service=mail");
 		my $response = $ua->request($req);
-		if ($response->is_error) {
+		if($response->is_error) {
 			my $code = $response->code;
 			my $message = $response->message;
 			$error = "Error: $code $message";
 			$http_status->enqueue($error);
+			return $error;
 		}
 		my $http = $response->content;
-		# print "\n--------\n$http\n";
-		
-		# New google accounts use a strange javascript/meta-refresh redirect ...
-		# ... but we catch them with this! :)
-		if ($http =~ m/location\.replace\("(.*)"\)/) {
-			my $new_addr = $1;
-			$new_addr =~ s/\\u003d/=/g;
-			$new_addr =~ s/\\075/=/g;
-			$new_addr =~ s/\\46/&/g;
-			$new_addr =~ s/\\75/=/g;
-			return unless $new_addr =~ m/^http/i;
-			
- 			print "\nNew login method: manually following redirect address $new_addr ...\n\n" unless $silent;
-			
-			my $req2 = HTTP::Request->new('GET' => "$new_addr");
-			my $response2 = $ua->request($req2);
-			if ($response2->is_error) {
-				my $code = $response2->code;
-				my $message = $response2->message;
+
+		# Find the value of the GALX input field
+		my ($post_galx) = ($http =~ m/"GALX".*?value="(.*?)"/ismg);
+		unless ($post_galx) {
+			print "Error: No GALX input field found\n";
+			return "Error: No GALX input field found";
+		}
+		$post_galx = URI_escape(URI_unescape($1));
+		
+		# Find the data to post
+		my $post_data;
+		$post_data = "ltmpl=default&ltmplcache=2&continue=http://mail.google.com/mail/?ui%3Dhtml&service=mail&rm=false&scc=1&GALX=$post_galx&$address&PersistentCookie=yes&rmShown=1&signIn=Sign+in&asts=";
+		
+		# Hide personal data from verbose display
+		my $post_display = $post_data;
+		$post_display =~ s/Email=(.*?)&/Email=******/;
+		$post_display =~ s/Passwd=(.*?)&/Passwd=******/;
+		print "Logging in with post data $post_display\n" unless $silent;
+
+		# Send the post data to the login URL
+		my $post_req = HTTP::Request->new('POST' => "https://www.google.com/accounts/ServiceLoginAuth?service=mail");
+		$post_req->content_type('application/x-www-form-urlencoded');
+		$post_req->content($post_data);
+		my $post_response = $ua->request($post_req);
+		if ($post_response->is_error) {
+			my $code = $response->code;
+			my $message = $response->message;
+			$error = "Error: $code $message";
+			$http_status->enqueue($error);
+			return $error;
+		}
+		my $post_http = $post_response->content;
+
+		# Find the location we're directed to, if any
+		if ($post_http =~ m/location\.replace\("(.*)"\)/) {
+			# Rewrite the redirect URI.
+			# This URI uses \xXX. Replace those, and just to be sure \\. \" we don't handle, though.
+			my $redirect_address = $1;
+			$redirect_address =~ s/\\\\/\\/g;
+			$redirect_address =~ s/\\x([0-9a-zA-Z]{2})/chr(hex($1))/eg;
+			print "Redirecting to ".$redirect_address."\n" unless $silent;
+
+			# And request the actual URL
+			my $req = HTTP::Request->new('GET' => $redirect_address);
+			my $response = $ua->request($req);
+			if($response->is_error) {
+				my $code = $response->code;
+				my $message = $response->message;
 				$error = "Error: $code $message";
 				$http_status->enqueue($error);
+				return $error;
 			}
-			# my $http = $response2->content;
+		} else {
+			print "No location.replace found in HTML\n" unless $silent;
 		}
+		
+		# Last part of the login process, in order to get Gmail's globar variables
+		# (including the all-important ik parameter)
+		$req = HTTP::Request->new('GET' => "https://mail.google.com/mail/?shva=1");
+		$response = $ua->request($req);
+		if($response->is_error) {
+			my $code = $response->code;
+			my $message = $response->message;
+			$error = "Error: $code $message";
+			$http_status->enqueue($error);
+			return $error;
+		}
+		$http = $response->content;
+		
+		# The globals.  Lots of goodies here, which we don't need right now 
+		# but which might come in handy later ... 
+		if ($http =~ m/var GLOBALS=\[,.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,"(.*?)"/) {
+			$gmail_ik = $1;
+		} else {
+			print "Unable to find gmail_ik ... full message text won't work :(\n\n";
+		}
+
+		
 		return $error;
 		
 	} elsif ($method eq 'LOGOUT') {
@@ -961,13 +1095,25 @@
 		# uncomment below to see the datapack structure
 		print "atom:\n$atom\n\n" unless $silent;
 		
-		# mb is the message body ... and there's often more than one block!
+		# as of 2/11/10, we can no longer use the old ui=1 datapack
+		# Unfortunately, the new ui=2 datapack is quite a bit less pleasant
+		# to use, with no nice "mb" cues ...
+		
 		my ($mb, $ma); 
-		while ($atom =~ m/\["mb","(.*?)",\d\]/g) {
+		
+		# if ($atom =~ m/\["ms",.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,\[.*?"\].*?\[.*?\[.*?,.*?,.*?,.*?,.*?,"(.*?)",\[/s) {#.*?,.*?,.*?,\[,.*?,.*?,.*?,.*?,.*?,"(.*?)",\[/g);
+			# print "\n\n-----\nYYYYY!\n$1\n";
+		# } else {
+			# print "\n\n-----\nNOPE!\n\n";
+		# }
+		
+		# See what you've made me do, Google??  Just look at this fugly regex ...
+		while ($atom =~ m/\["ms",.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,\[.*?"\].*?\[.*?\[.*?,.*?,.*?,.*?,.*?,"(.*?)",\[/sg) {
 			$mb .= "$1";
 		}
-		
+				
 		# ma is the attachment, if any
+		# (I suspect this doesn't work anymore with the new datapack ...)
 		while ($atom =~ m/\["ma",\[(.*?)\]/g) {
 			my $att = $1;
 			$ma = "/mail/images/paperclip.gif"; # default attachment
@@ -981,7 +1127,7 @@
 		print "cleaned text is\n$mb\n\n" unless $silent;
 						
 		# cs is the message id
-		my ($cs) = ($atom =~ m/\["cs","(.*?)"/);
+		my ($cs) = ($atom =~ m/.*\["ms","(.*?)"/s);
 		$messages_ext{$cs}->{text} = $mb;
 		$messages_ext{$cs}->{shown} = 1;
 		$messages_ext{$cs}->{attachment} = $ma;
@@ -1045,9 +1191,9 @@
 			my $author = $author_name || $author_mail;
 						
 			# clean text for Pango compatible display ...
-			$title = clean_text($title);
-			$author = clean_text($author);
-			$summary = clean_text($summary);
+			$title = clean_text_and_decode($title);
+			$author = clean_text_and_decode($author);
+			$summary = clean_text_and_decode($summary);
 			
 			my ($year, $month, $day, $hour, $min, $sec) = ($issued =~ m/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/);
 			my $time_abs = $sec+$min*60+$hour*3600+$day*86400+$month*2678400+$year*32140800;
@@ -1089,7 +1235,7 @@
 		# Create popup text
 		if ($popup_authors) {
 			$popup_authors =~ s/, ([\w\s-]+)$/ $trans{notify_and} $1/; # replace final comma with "and"
-			$popup_authors = clean_text($popup_authors);
+			$popup_authors = clean_text_and_decode($popup_authors);
 			$popup_text = "<span foreground=\"#000000\"><small>$trans{notify_new_mail}$popup_authors ...</small></span>";
 		}
 		
@@ -1111,6 +1257,32 @@
 	return 1;
 }
 
+# Note -- for some reason (?? why ??) the title does not need decoding; all other data apparently does.  Very strange ...
+sub clean_text_and_decode {
+	($_) = @_;
+	# some basic replacements so that the text is readable ...
+	# (these aren't used by pango markup, unlike other HTML escapes)
+	s/&hellip;/\.\.\./g;
+	s/&\s/\&amp; /g;
+	s/\\u003c/</g;
+	# s/\\n//g;
+	s/<br\s*\/*\\*>/\n/g;
+	s/</\&lt;/g;
+	s/>/\&gt;/g;
+	s/&(?>([\w\d\,\.]+))(?!;)/\&amp;$1/g; #not a great fix, but at least it's simple (heavy irony ... :)
+	s/&nbsp;/ /g;
+	# s/\\n/\n/g;
+	# Encode::from_to($body, 'utf-8', 'iso-8859-15');
+	# eval { decode("utf8", $_, Encode::FB_CROAK); };
+	# my $body_decode = $@ ? $_ : decode("utf8", $_);
+	#my $body_decode= decode("utf-8", $_);
+	
+	# I have no idea why this works ...
+	my $body_encode = encode("utf8", $_);
+	my $body_decode = decode("utf8", $body_encode);
+	
+	return $body_decode;
+}
 
 sub clean_text {
 	($_) = @_;
@@ -1129,6 +1301,7 @@
 	return $_;
 }
 
+
 sub clean_text_body {
 	($_) = @_;
 	# some basic replacements so that the text is readable ...
@@ -1164,9 +1337,13 @@
 	# s/&(?>([\w\d\,\.]+))(?!;)/\&amp;$1/g; #not a great fix, but at least it's simple (heavy irony ... :)
 	s/&nbsp;/ /g;
 	# s/\\n/\n/g;
-	use Encode;
 	# Encode::from_to($body, 'utf-8', 'iso-8859-15');
-	my $body_decode= decode("utf-8", $_);
+	# eval { decode("utf8", $_, Encode::FB_CROAK); };
+	# my $body_decode = $@ ? $_ : decode("utf8", $_);
+	# my $body_encode = encode("utf8", $_);
+	
+	# I have no idea why this works either ...
+	my $body_decode = decode("utf8", $_);
 
 	return $body_decode;
 }
@@ -1335,6 +1512,14 @@
 	my ($status, $text) = @_;	
 	my $new_mail = @messages;
 	
+	# display number of messages
+	if ($mailno) {
+		# print "setting \"$new_mail\"\n";
+		$number_label->set_markup("$new_mail");
+		$new_mail ? $number_label->show : $number_label->hide;
+		# $new_mail ? $number_label->set_markup("$new_mail") : $number_label->set_markup(" ")
+	}
+	
 	my @sorted_messages = sort {$b->{time} <=> $a->{time}} @messages;
 	@messages = @sorted_messages;
 	
@@ -1482,23 +1667,35 @@
 		my $hbox_t = Gtk2::HBox->new(0,0);
 		$notify_vbox->pack_start($hbox_t,0,0,0);
 		
+		my $vbox_t = Gtk2::VBox->new(0,0);
+		$hbox_t->pack_start($vbox_t,0,0,0);	
+		
+		my $hbox_tt = Gtk2::HBox->new(0,0);
+		$vbox_t->pack_start($hbox_tt,0,0,0);
+			
+				
+		
 		my $title_l = Gtk2::Label->new;
-		$title_l->set_markup("<span foreground=\"#000000\"><b><u>$title</u></b></span><small> <span foreground=\"#006633\">$label</span></small>\n<b>$trans{notify_from}</b> $author");
+		$title_l->set_markup("<span foreground=\"#000000\"><b><u>$title</u></b></span><small> <span foreground=\"#006633\">$label</span></small>");
 		$title_l->set_line_wrap(1);
 		
 		my $title_l_ebox = Gtk2::EventBox->new();
 		$title_l_ebox->modify_bg('normal', Gtk2::Gdk::Color->new (65000, 65000, 65000));
-		my $s1 = $title_l_ebox->signal_connect(enter_notify_event=>sub{$title_l->set_markup("<span foreground=\"#000000\"><b><u><i>$title</i></u></b></span><small> <span foreground=\"#006633\">$label</span></small>\n<b>$trans{notify_from}</b> $author")});
-		my $s2 = $title_l_ebox->signal_connect(leave_notify_event=>sub{$title_l->set_markup("<span foreground=\"#000000\"><b><u>$title</u></b></span><small> <span foreground=\"#006633\">$label</span></small>\n<b>$trans{notify_from}</b> $author")});
+		my $s1 = $title_l_ebox->signal_connect(enter_notify_event=>sub{$title_l->set_markup("<span foreground=\"#000000\"><b><u><i>$title</i></u></b></span><small> <span foreground=\"#006633\">$label</span></small>")});
+		my $s2 = $title_l_ebox->signal_connect(leave_notify_event=>sub{$title_l->set_markup("<span foreground=\"#000000\"><b><u>$title</u></b></span><small> <span foreground=\"#006633\">$label</span></small>")});
 		$title_l_ebox->signal_connect(button_press_event=>sub{
-			# grabbing the full text of a message!
+			# grabbing the full text of a message
 			return unless $cookies;
 			$title_l_ebox->signal_handler_disconnect($s1);
 			$title_l_ebox->signal_handler_disconnect($s2);
 			unless ($mb) {
+				# print "Message ID = $id\n";
 				# yep, here's the magic code.  This accesses the datapack, which we read with a little hack in the check routine ...
-				$request->enqueue("GET:".gen_prefix_url()."/?ui=1&view=cv&search=all&th=$id&ww=1173&qt=&prf=1&pft=undefined&rq=xm&at=$gmail_at");
-				# $request->enqueue("GET:".gen_prefix_url()."/?ui=2&ik=b8bb7ca6af&view=cv&search=all&th=$id&rt=j&prf=1");
+				#$request->enqueue("GET:".gen_prefix_url()."/?ui=1&view=cv&search=all&th=$id&qt=&prf=1&pft=undefined&rq=xm&at=$gmail_at");
+				
+				# As of 3/11/10, Gmail has removed access to the old ui=1 version of Gmail
+				# ui=2 requires a POST command to get the datapack (which has also changed formats slightly)
+				$request->enqueue("POST_MB:".gen_prefix_url()."/?ui=2&ik=$gmail_ik&rid=&view=cv&prf=1&_reqid=&nsc=1|&mb=0&rt=j&cat=all&search=cat&th=$id&at=$gmail_at");
 			} else {
 				# this allows the message text to be toggled ...
 				# oh yes, we're all about usability here, folks! :)
@@ -1508,8 +1705,69 @@
 		});
 		
 		$title_l_ebox->add($title_l);		
-		$hbox_t->pack_start($title_l_ebox,0,0,0);
+		$hbox_tt->pack_start($title_l_ebox,0,0,0);
+		
+		# short spacer
+		my $title_spacer = Gtk2::HBox->new(0,0);
+		$title_spacer->set_border_width(1);
+		$vbox_t->pack_start($title_spacer,0,0,0);
+		
+		# my god, gtk2 has the most stupid packing routines imaginable!!!
+		my $hbox_from = Gtk2::HBox->new(0,0);
+		$vbox_t->pack_start($hbox_from,0,0,0);
+		
+		
+		# --- Starring messages ---
+		# Note: there's no way to check the star-status of a message from the atom feed
+		# of course, we're gradually getting to the stage where it'd be much easier to
+		# poll the server via http requests now, than to retrieve messages via the feed.
+		# (I'm thinking about it!  Definitely thinking about it ... :)
+		#
+		# In the meantime, the icon adds a quick way to star messages that you'd like
+		# to come back to later, but ignore for the present.
+		
+		# Star icons are taken from Mozilla Firefox 3 (http://getfirefox.com), licensed under
+		# the Creative Commons license
+		
+		my $star_i = Gtk2::Image->new();
+		if ($messages_ext{$id}->{star}) {
+			$star_i->set_from_pixbuf($star_pixbuf);
+		} else {
+			$messages_ext{$id}->{star}=0;
+			$star_i->set_from_pixbuf($nostar_pixbuf);
+		}
+		
+		my $star_ebox = Gtk2::EventBox->new();
+		$star_ebox->modify_bg('normal', Gtk2::Gdk::Color->new (65000, 65000, 65000));
+		$star_ebox->signal_connect(button_press_event=>sub{
+			# setting the star
+			return unless $cookies;
+			$messages_ext{$id}->{star} = 1-$messages_ext{$id}->{star};
+			if ($messages_ext{$id}->{star}) {
+				$star_i->set_from_pixbuf($star_pixbuf);
+				$request->enqueue(gen_action_url($gmail_act{star},$id));
+			} else {
+				$star_i->set_from_pixbuf($nostar_pixbuf);
+				$request->enqueue(gen_action_url($gmail_act{unstar},$id));
+			}				
+		});	
+		
+		$star_ebox->add($star_i);		
+		
+		my $star_space = Gtk2::HBox->new(0,0);
+		$star_space->set_border_width(3);	
+		
+		# From: line (with star)
+		my $from_l = Gtk2::Label->new;
+		$from_l->set_markup("<b>$trans{notify_from}</b> $author");
+		$from_l->set_line_wrap(1);
 		
+		$hbox_from->pack_start($from_l,0,0,0);
+		$hbox_from->pack_start($star_space,0,0,0);	
+		$hbox_from->pack_start($star_ebox,0,0,0);	
+		
+		
+		# --- Attachment icon ---
 		if ($messages_ext{$id}->{attachment}) {
 			$att = $messages_ext{$id}->{attachment};
 			my ($image_name) = ($att =~ m/.*\/(.*)$/);		
@@ -1684,6 +1942,7 @@
 		show_notify($win_notify_temp);
 	} else {
 		$win_notify->destroy if $win_notify;
+		$win_notify="";
 		$win_notify = $win_notify_temp;
 	}
 }
@@ -1742,6 +2001,11 @@
 sub get_login_href {
 	# Login directly to gmail ...
 	$_ = shift;
+	
+	# The following is for people who like to stay permanently logged in ...
+	# (enable with -no-login on the command-line for now ...)
+	return $_ if $nologin;
+	
 	my ($options) = m/.*?\?(.*)/;
 	my $options_uri = $options ? "?&$options" : "";
 	
@@ -1775,7 +2039,9 @@
 	# Now that we can grab the full text of messages, we'd better clear the cache while we're here ...
 	# NB - I realise this won't remove all cached text, in the rare event someone looks at the full message text,
 	# and then opens it manually in the webbrowser - but it's the simplest solution for now ...
-	$messages_ext{$id}=undef;
+	unless ($act =~ m/st/) {
+		$messages_ext{$id}=undef;
+	}
 	
 	# Undeleting items from trash needs to have the search variable as "trash"
 	# - this is a quick hack to get around it!
@@ -1902,15 +2168,22 @@
 	
 	# move the window
 	$new_win->move($move_x,$move_y) if ($move_x || $move_y);
-	$new_win->show_all unless ($new_win->visible);
+	Gtk2->main_iteration while (Gtk2->events_pending);
 	
-	# $scrolled->set_vadjustment($vadj) if $vadj;
+	# $new_win->show_all unless ($new_win->visible);
+	# Gtk2->main_iteration while (Gtk2->events_pending);
 
+	# $scrolled->set_vadjustment($vadj) if $vadj;
+	
+	# a small sleep to make compiz work better
+	# select(undef, undef, undef, 0.150);
 	if ($win_notify_temp) {
 		$win_notify->destroy;
+		$win_notify="";
 		$win_notify=$new_win;
 	}
-	
+	# Gtk2->main_iteration while (Gtk2->events_pending);
+
 	
 	($old_x, $old_y) = ($move_x,$move_y);
 	
@@ -2847,6 +3120,8 @@
 	$mail_pixbuf = load_pixbuf($mail_data);
 	$no_mail_pixbuf = load_pixbuf($no_mail_data);
 	$error_pixbuf = load_pixbuf($error_data);
+	$star_pixbuf = load_pixbuf($star_on_data);
+	$nostar_pixbuf = load_pixbuf($star_off_data);
 	
 	# load custom icons if defined
 	$custom_mail_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($mail_icon) if $mail_icon;
@@ -2975,6 +3250,41 @@
 M-G7[%EY9PC1-%`)-W-4:.9N%A:><.\'FZ"36L.A<O3;"XM(1A"`>]Q2";R7`H
 MG:9>-;$;#:Q:%0F)AM5@YX[M%-<_=VY!UW42R3T_+F2?@^@!%%6CMR^&KNMM
 B#2;O3$]=_HN/.,G_J.\25[KK%,1Y@@````!)14Y$KD)@@@``');
+
+	$star_on_data = unpack("u",
+'MB5!.1PT*&@H````-24A$4@```!`````0"`8````?\_]A````!\'-"250("`@(
+M?`ADB`````EP2%ES```-UP``#=<!0BB;>````!ET15AT4V]F=\'=A<F4`=W=W
+M+FEN:W-C87!E+F]R9YON/!H```)\241!5#B-G5-=2U11%%W[W\'-GQID[V1A^
+MI2/-1&9?.D%*,>)3/?10T4-%)4R1^!1!1(\1%/4#`B\'ZH!DMD`KRH;>@\'IIK
+M0F$@E*$&HYD.(I0?,Z-S[SV[A]`<\'%_:<&"S66NOM0[G$#.C6)D)JA="O`-1
+M3CG.L6B,AXOA1%$V`")Q,]AXN7);Y\'I("\'%G(QR8>=U)QE\'1W^.V\'&N6E3W\'
+M\'YX9=C*.ZF+8C1QT5NUH9U(_`?LKMNZZQ``ZBSI-QN$"<`5`2`BMAHBJ&=38
+M<BKE$3P,J%]P1#,^OMRY3\'"&F\'E:*6<2P#B`>V1VBQ?EX=,G:O=>TZ6[$IHT
+M0)H/1*Y_,FH!2EFP<Q/(YU+(9Z=X:OBA-3\[]$:P4JD2?UB4E!Z`[@E"R$`A
+M&0"$%\33D\'(*/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0+[?[S\6D8<S!+:/CHYV@(VK
+M]]?7Z)=*I07@2]BT(B*K8>UKL5A<(-C`+UP/1RR3R9C`1$2>>IZ7\#Q/1,0!
+M7J52*1,PYDUPLU:KQ555C0([AX>\'MFF:)Z9IGO1ZO7/@B:JJ>JO52@#160):
+M-!J=CD:CD659QY5*Y9UMVZ>>YYU6J]6WEF4=V[9]KBC*)4\'H@-^=5`C<58$1
+C0>JNPB#XF5/@#!#^!WX"JHNT6FM(-L<`````245.1*Y"8((`');
 	
 }
 
@@ -2986,7 +3296,14 @@
 sub URI_escape {
 	# Turn text into HTML escape codes
 	($_) = @_;
-	s/(.)/$escapes{$1}/g;
+	s/([^a-zA-Z0-9])/$escapes{$1}/g;
+	return $_;
+}
+
+sub URI_unescape {
+	# Turn HTML escape code into text
+	($_) = @_;
+	s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
 	return $_;
 }
 
diff -aur checkgmail-1.13/man/checkgmail.1.gz checkgmail-svn/man/checkgmail.1.gz
--- checkgmail-1.13/man/checkgmail.1.gz	2007-05-08 09:26:24.000000000 -0400
+++ checkgmail-svn/man/checkgmail.1.gz	2011-12-25 15:32:53.000000000 -0500
@@ -1,6 +1,10 @@
-Echeckgmail.1}Wao6_AS2jaPm;ۊ4hHJRv{wl9$K/.J=~^$IWbziދ/cw>Z'wB6MVdFH,	N2\|E{n8[J݋qiqBN۴C*Gc2kc#r+U\]8}<r/gaBirFQ]St>j>a].l(':|*E)#U:K[ѵ
-o:h)>[`kQ(4Iоa[g@i
B	?d=)hWXF(80+Y+?":lCg$B\+X[=G5mM"WzJ1(%IŅ5^.n+f/^|VJx]C|#*H97v\QT<Sw{EŮv}4(Uf~k].|hSJ[B7͂a4!ɚh`T"\i2Pm

jXQ1OnX^;5F%0;ۺC%R]1Zf@I^	*4$yES:TKQ5R8Hƹ jUGPlWy_"H`>u1U
b[)2[()J*c%Oa5H jK
-QȪX2 "pvʠ]/M!QZC {lGG95
!Q&AU@@lꪊu>0")] 0j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