Guest User

Untitled

a guest
Feb 11th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.64 KB | None | 0 0
  1.     #if ($atom =~ m/while\(1\);/) {
  2.     ### Dataformat changed 2012-02-08
  3.     if ($atom =~ s/LABEL=.*\n\)]}'//) {
  4.         # datapack shortcircuit
  5.         # we use this to grab the full text of messages ...
  6.         #
  7.         ## uncomment below to see the datapack structure
  8.         #print "atom:\n$atom\n\n" unless $silent;
  9.         #
  10.         ## as of 2/11/10, we can no longer use the old ui=1 datapack
  11.         ## Unfortunately, the new ui=2 datapack is quite a bit less pleasant
  12.         ## to use, with no nice "mb" cues ...
  13.         #
  14.         #my ($mb, $ma);
  15.         #
  16.         ## if ($atom =~ m/\["ms",.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,\[.*?"\].*?\[.*?\[.*?,.*?,.*?,.*?,.*?,"(.*?)",\[/s) {#.*?,.*?,.*?,\[,.*?,.*?,.*?,.*?,.*?,"(.*?)",\[/g);
  17.             ## print "\n\n-----\nYYYYY!\n$1\n";
  18.         ## } else {
  19.             ## print "\n\n-----\nNOPE!\n\n";
  20.         ## }
  21.         #
  22.         ## See what you've made me do, Google??  Just look at this fugly regex ...
  23.         ##while ($atom =~ m/\["ms",.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,\[.*?"\].*?\[.*?\[.*?,.*?,.*?,.*?,.*?,"(.*?)",\[/sg) {
  24.         #while ($atom =~ m/\["ms",.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,\[.*?"\].*?\[.*?\[.*?,.*?,.*?,.*?,.*?,".*?","(.*?)",\[/sg) {
  25.             #$mb .= "$1";
  26.         #}
  27.         #      
  28.         ## ma is the attachment, if any
  29.         ## (I suspect this doesn't work anymore with the new datapack ...)
  30.         #while ($atom =~ m/\["ma",\[(.*?)\]/g) {
  31.             #my $att = $1;
  32.             #$ma = "/mail/images/paperclip.gif"; # default attachment
  33.             ## print "attachment =\n$att\n\n";
  34.             #if ($att =~ m/src\\u003d\\\"(.*?)\\\"/g) {
  35.                 #$ma = $1;
  36.             #}
  37.         #}
  38.         #
  39.         #$mb = clean_text_body($mb);
  40.         #print "cleaned text is\n$mb\n\n" unless $silent;
  41.         #              
  42.         ## cs is the message id
  43.         #my ($cs) = ($atom =~ m/.*\["ms","(.*?)"/s);
  44.  
  45.  
  46.  
  47.         ### JSON parsing instead of above regexps.
  48.  
  49.         ### FULL TEXT ###
  50.         my $mb;
  51.  
  52.         ### Google does not return valid JSON. They use completely
  53.         #empty syntax as in "value1",,"value3" to denote null, when
  54.         #"value1","","value3" is mandated. This regexp fixes that.
  55.         (my $json_raw = $atom ) =~ s/(?<=,),/"",/g;
  56.         ### Google does not return valid JSON. They use ' to delimit
  57.         #the last value of the response, when " is mandated.
  58.         $json_raw =~ s/,'(\w*)'\]$/,"$1"\]/;
  59.  
  60.         use JSON -support_by_pp;
  61.         my $json_parser = new JSON;
  62.         my @json_array = $json_parser->decode($json_raw);
  63.         ### Some magic array indices below
  64.  
  65.         ### Number of messages in the conversation.
  66.         my $numconv = $json_array[0]->[0]->[2]->[3];
  67.         ### Fulltext of last message.
  68.         $mb = clean_text_body($json_array[0]->[0]->[$numconv+2]->[13]->[6]);
  69.  
  70.         ### ATTACHMENTS ###
  71.         my $ma;
  72.  
  73.         ### Checkgmail does not seem to handle multiple attachments in
  74.         #general, only showing a single icon. See later loop for how
  75.         #one can iterate over attachments. Would be nice to get an icon
  76.         #for every attachment along with a direct link to open/download
  77.         #it.
  78.         if($json_array[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[0]){
  79.             $ma = $json_array[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[0]->[6];
  80.         }
  81.  
  82.         #for(my $i=0; $json_array[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[$i]; $i++){
  83.             #print '---ATTACHMENT '.$i."\n";
  84.             #print '   Name: '.$json_text[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[$i]->[1]."\n";
  85.             #print '   Type: '.$json_text[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[$i]->[2]."\n";
  86.             #print '   Size: '.$json_text[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[$i]->[3]."\n";
  87.             #print '   Icon: '.$json_text[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[$i]->[6]."\n";
  88.             #print '   Link: '.$json_text[0]->[0]->[$numconv+2]->[13]->[7]->[0]->[$i]->[9]."\n";
  89.         #}
  90.  
  91.         ### Last message ID.
  92.         my $cs = $json_array[0]->[0]->[$numconv+2]->[1];
  93.  
  94.         $messages_ext{$cs}->{text} = $mb;
  95.         $messages_ext{$cs}->{shown} = 1;
  96.         $messages_ext{$cs}->{attachment} = $ma;
  97.  
  98.         notify();
  99.         return 1;
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment