/** * Constructor. * * Note: you are not supposed to create a GMailSnapshot object yourself. You should * use {@link GMailer::getSnapshot()} and/or {@link GMailer::webClip()} instead. * * @return GMailWebclipSnapshot * @param array $raw */ function web_clip_snapshot($raw) { $clips = array(); foreach ($raw as $webclip) { if (count($webclip) == 10) { $ad_site = 4; $ad_date = 5; $ad_sub = 6; $ad_type = 8; $ad_cat = 9; } elseif (count($webclip) == 6) { $ad_site = 0; // not really, but will be blank $ad_date = 0; // not really, but will be blank $ad_sub = 0; // not really, but will be blank $ad_type = 4; $ad_cat = 5; } elseif (count($webclip) == 7) { $ad_site = 4; $ad_date = 0; // not really, but will be blank $ad_sub = 0; // not really, but will be blank $ad_type = 5; $ad_cat = 6; } else { Debugger::say("odd web clips: " . print_r($webclip, true)); continue; } $clip = array(); //$clip[''] = $webclip[0]; // ?? //$clip[''] = $webclip[1]; // clip id?? $clip['url'] = $webclip[2]; $clip['title'] = $webclip[3]; $clip['site'] = $ad_site != 0 ? $webclip[$ad_site] : ""; $clip['date'] = $ad_date != 0 ? $webclip[$ad_date] : ""; $clip['sub'] = $ad_sub != 0 ? $webclip[$ad_sub] : ""; //$clip[''] = (($less) ? "" : $webclip[7]); // ?? empty $clip['type'] = $webclip[$ad_type]; // web clip, advertisement, gmail tip, etc. //$clip['category'] = $webclip[$ad_cat]; // a number // 1 = Gmail Tip, 2 = News, 3 = Business, 4 = Lifestyle // 5 = Fun, 6 = Tech, 7 = Sports, 8 = custom $clips[] = $clip; } $this->web_clips = $clips; return 1; }
/** * Constructor. * * Note: you are not supposed to create a GMailSnapshot object yourself. You should * use {@link GMailer::getSnapshot()} instead. * * @return GMailSnapshot * @param constant $type * @param array $raw */ function GMailSnapshot($type, $raw, $use_session) { // input: raw packet generated by GMailer if (!is_array($raw)) { $this->created = 0; $this->snapshot_error = "libgmailer: invalid datapack -- not an array"; // Added by Neerav; 3 Aug 2005 return null; } if (count($raw) == 0) { $this->created = 0; $this->snapshot_error = "libgmailer: invalid datapack -- no entries"; // Added by Neerav; 3 Aug 2005 return null; } //Debugger::say("raw packet as snapshot input: ".print_r($raw,true)); // Gmail version if (isset($raw["v"][1])) { $this->gmail_ver = $raw["v"][1]; } //$raw["v"][2] // What is this? //$raw["v"][3] // What is this? // IdentificationKey (ik) // Added by Neerav; 6 July 2005 if ($use_session) { if (!isset($_SESSION['id_key']) or $_SESSION['id_key'] == "") { Debugger::say("Snapshot: Using Sessions, saving id_key(ik)..."); if (isset($raw["ud"][3])) { $_SESSION['id_key'] = $raw["ud"][3]; Debugger::say("Snapshot: Session id_key saved: " . $_SESSION['id_key']); } else { Debugger::say('Snapshot: Session id_key NOT saved. $raw["ud"][3] not found.'); } } } else { if (!isset($_COOKIE[GM_COOKIE_IK_KEY]) or $_COOKIE[GM_COOKIE_IK_KEY] == 0) { Debugger::say("Snapshot: Using Cookies, saving id_key(ik)..."); if (isset($raw["ud"][3])) { if (strpos($_SERVER["HTTP_HOST"], ":")) { $domain = substr($_SERVER["HTTP_HOST"], 0, strpos($_SERVER["HTTP_HOST"], ":")); } else { $domain = $_SERVER["HTTP_HOST"]; } Debugger::say("Saving id_key as cookie " . GM_COOKIE_IK_KEY . " with domain=" . $domain); header("Set-Cookie: " . GM_COOKIE_IK_KEY . "=" . base64_encode($raw["ud"][3]) . "; Domain=" . $domain . ";"); Debugger::say("Snapshot: Cookie id_key saved: " . GM_COOKIE_IK_KEY . "=" . base64_encode($raw["ud"][3])); } else { Debugger::say('Snapshot: Cookie id_key NOT saved. $raw["ud"][3] not found.'); } } } // other "UD" // Added by Neerav; 6 July 2005 if (isset($raw["ud"])) { // account email address // your app SHOULD cache this in session or cookie for use across pages // Added by Neerav; 6 May 2005 $this->gmail_email = $raw["ud"][1]; //$raw["ud"][2] // keyboard shortcuts //$raw["ud"][3] // Identification Key, set above //$raw["ud"][4] // What is this? } // su //$raw["su"][1] // What is this? //$raw["su"][2] // What is this? (?? array of text strings for invites) // Google Accounts' name // your app SHOULD cache this in session or cookie for use across pages // it's bandwidth expensive to retrieve preferences just for this // Added by Neerav; 2 July 2005 if (isset($raw["gn"][1])) { $this->google_name = $raw["gn"][1]; } // your app SHOULD cache this in session or cookie for use across pages // it's bandwidth expensive to retrieve preferences just for this // Added by Neerav; 6 July 2005 if (isset($raw["p"])) { for ($i = 0; $i < count($raw["p"]); $i++) { if ($raw["p"][$i][0] == "sx_sg") { // can be undefined ?!?! $this->signature = isset($raw["p"][$i][1]) ? $raw["p"][$i][1] : ""; break; } } } // Invites if (isset($raw["i"][1])) { $this->have_invit = $raw["i"][1]; } else { $this->have_invit = 0; } // QUota information if (isset($raw["qu"])) { // Space used as xx MB $this->quota_mb = $raw["qu"][1]; // Total space allotted as xxxx MB $this->quota_tot = $raw["qu"][2]; // Added by Neerav; 6 May 2005 // Space used as xx% $this->quota_per = $raw["qu"][3]; // Added by Neerav; 6 May 2005 // html color as #aabbcc (normally a green color, but red when nearly full) $this->quota_col = $raw["qu"][4]; // Added by Neerav; 6 July 2005 } // Footer Tips // Added by Neerav; 6 July 2005 if (isset($raw["ft"][1])) { $this->gmail_tip = $raw["ft"][1]; } // cfs; Compose from source // Added by Neerav: 30 Aug 2005; Modified: 9 Sep 2005 $this->personality = array(); $this->personality_unverify = array(); if (isset($raw["cfs"])) { if (isset($raw["cfs"][1])) { $person_verified = count($raw["cfs"][1]); for ($i = 0; $i < $person_verified; $i++) { $this->personality[] = array("name" => $raw["cfs"][1][$i][0], "email" => $raw["cfs"][1][$i][1], "default" => $raw["cfs"][1][$i][2] == 0 ? false : true, "verified" => true); } $person_unverified = count($raw["cfs"][2]); for ($i = 0; $i < $person_unverified; $i++) { $this->personality_unverify[] = array("name" => $raw["cfs"][2][$i][0], "email" => $raw["cfs"][2][$i][1], "default" => $raw["cfs"][2][$i][2] == 0 ? false : true, "verified" => false); } } } // What is this? // $raw["df"][1] // shows ?false? // What is this? // $raw["ms"] // What is this? // $raw["e"] // What is this? // $raw["pod"] if ($type & (GM_STANDARD | GM_LABEL | GM_CONVERSATION | GM_QUERY)) { //Debugger::say(print_r($raw,true)); // Added by Neerav; 6 May 2005 if (isset($raw["p"]) and !isset($this->signature)) { for ($i = 1; $i < count($raw["p"]); $i++) { if ($raw["p"][$i][0] == "sx_sg") { // can be undefined ?!?! $this->signature = isset($raw["p"][$i][1]) ? $raw["p"][$i][1] : ""; break; } } } if (!isset($this->signature)) { $this->signature = ""; } // when a conversation does not exist, neither does ds; Fix by Neerav; 1 Aug 2005 if (isset($raw["ds"])) { if (!is_array($raw["ds"])) { $this->created = 0; $this->snapshot_error = "libgmailer: invalid datapack"; return null; } $this->std_box_new = array_slice($raw["ds"], 1); } else { $this->created = 0; if (isset($raw["tf"])) { $this->snapshot_error = $raw["tf"][1]; } else { $this->snapshot_error = "libgmailer: unknown but fatal datapack error"; } return null; } $this->label_list = array(); $this->label_new = array(); // Last changed by Neerav; 12 July 2005 if (isset($raw["ct"][1]) and count($raw["ct"][1]) > 0) { foreach ($raw["ct"][1] as $v) { array_push($this->label_list, $v[0]); array_push($this->label_new, $v[1]); } } // Thread Summary if (isset($raw["ts"])) { $this->view = GM_STANDARD | GM_LABEL | GM_QUERY; $this->box_name = $raw["ts"][5]; // name of box/label/query $this->box_total = $raw["ts"][3]; // total messages found $this->box_pos = $raw["ts"][1]; // starting message number // Added by Neerav; 6 July 2005 $this->box_display = $raw["ts"][2]; // max number of messages to display on the page $this->box_query = $raw["ts"][6]; // gmail query for box $this->queried_results = $raw["ts"][4]; // was this a search query (bool) //$this->?? = $raw["ts"][7]; // what is this?? some id number? //$this->?? = $raw["ts"][8]; // what is this?? total number of messages in account? //$this->?? = $raw["ts"][9]; // what is this?? } $this->box = array(); if (isset($raw["t"])) { foreach ($raw["t"] as $t) { if ($t == "t") { continue; } // Fix for 12 OR 13 fields!!; by Neerav; 23 July 2005 $less = count($t) == 12 ? 1 : 0; // Added by Neerav; 6 July 2005 $long_date = ""; $long_time = ""; $date_time = explode("_", $t[12 - $less]); if (isset($date_time[0])) { $long_date = $date_time[0]; } if (isset($date_time[1])) { $long_time = $date_time[1]; } // Added labels for use in multiple languages; by Neerav; 7 Aug 2005 //$label_array_lang = $t[8-$less]; // Added by Neerav; 6 July 2005 // Gives an array of labels and substitutes the standard names // Changed to be language compatible; by Neerav; 8 Aug 2005 $label_array = array(); foreach ($t[8 - $less] as $label_entry) { switch ($label_entry) { //case "^i": $label_array[] = "Inbox"; break; //case "^s": $label_array[] = "Spam"; break; //case "^k": $label_array[] = "Trash"; break; case "^t": /* Starred */ break; //case "^r": $label_array[] = "Draft"; break; //case "^r": $label_array[] = "Draft"; break; default: $label_array[] = $label_entry; break; } } $b = array(); $b["id"] = $t[0]; $b["is_read"] = $t[1] == 1 ? 1 : 0; $b["is_starred"] = $t[2] == 1 ? 1 : 0; $b["date"] = strip_tags($t[3]); $b["sender"] = strip_tags($t[4], "<b>"); $b["flag"] = $t[5]; $b["subj"] = strip_tags($t[6], "<b>"); $b["snippet"] = count($t) == 12 ? "" : $t[7]; $b["msgid"] = $t[10 - $less]; // Added by Neerav; 7 Aug 2005 //$b["labels_lang"]= $label_array_lang; // for use with languages // Added/Changed by Neerav; 6 July 2005 $b["labels"] = $label_array; // gives an array even if 0 labels $b["attachment"] = strlen($t[9 - $less]) == 0 ? array() : explode(",", $t[9 - $less]); // Changed to give an array even if 0 attachments //$b["??"] = $t[11-$less]; // what is this?? $b["long_date"] = $long_date; // added $b["long_time"] = $long_time; // added array_push($this->box, $b); } } if (isset($raw["cs"])) { // Fix for 14 OR 12 fields!!; by Neerav; 25 July 2005 $less = count($raw["cs"]) == 12 ? 2 : 0; $this->view = GM_CONVERSATION; $this->conv_id = $raw["cs"][1]; $this->conv_title = $raw["cs"][2]; // $raw["cs"][3] // what is this?? escape/html version of 2? // $raw["cs"][4] // what is this?? empty // $raw["cs"][5] // (array) conversation labels, below // $raw["cs"][6] // what is this?? array // $raw["cs"][7] // what is this?? integer/bool? $this->conv_total = $raw["cs"][8]; // (count($t) == 14) $raw["cs"][9] // may be missing! what is this?? long id number? // (count($t) == 14) $raw["cs"][10] // may be missing! what is this?? empty // $raw["cs"][11-$less] // may be 9 what is this?? repeat of id 1? // $raw["cs"][12-$less] // may be 10 what is this?? array // $raw["cs"][13-$less] // may be 10 what is this?? integer/bool? $this->conv_labels = array(); $this->conv_starred = false; // Added labels for use in multiple languages; by Neerav; 7 Aug 2005 //$this->conv_labels_lang = $raw["cs"][5]; // for use with languages // Changed to give translated label names; by Neerav; 6 July 2005 // Changed back to be language compatible; by Neerav; 8 Aug 2005 //$this->conv_labels_temp = (count($raw["cs"][5])==0) ? array() : $raw["cs"][5]; $temp_array = $raw["cs"][5]; foreach ($raw["cs"][5] as $label_entry) { switch ($label_entry) { //case "^i": $this->conv_labels[] = "Inbox"; break; //case "^s": $this->conv_labels[] = "Spam"; break; //case "^k": $this->conv_labels[] = "Trash"; break; case "^t": $this->conv_starred = true; break; //case "^r": $this->conv_labels[] = "Draft"; break; //case "^r": $this->conv_labels[] = "Draft"; break; default: $this->conv_labels[] = $label_entry; break; } } $this->conv = array(); //Debugger::say(print_r($raw["mg"],true)); $mg_count = count($raw["mg"]); for ($i = 0; $i < $mg_count; $i++) { if ($raw["mg"][$i][0] == "mb" && $i > 0) { $b["body"] .= $raw["mg"][$i][1]; if ($raw["mg"][$i][2] == 0) { array_push($this->conv, $b); unset($b); } } elseif ($raw["mg"][$i][0] == "mi" or $raw["mg"][$i][0] == "di") { // Changed to merge "di" and "mi" routines; by Neerav; 11 July 2005 if (isset($b)) { array_push($this->conv, $b); unset($b); } $b = array(); // $raw["mg"][$i][0] is mi or di $b["mbox"] = $raw["mg"][$i][1]; // Added by Neerav; 11 July 2005 $b["index"] = $raw["mg"][$i][2]; $b["id"] = $raw["mg"][$i][3]; $b["is_star"] = $raw["mg"][$i][4]; if ($b["is_star"] == 1) { $this->conv_starred = true; } $b["draft_parent"] = $raw["mg"][$i][5]; // was only defined in draft, now both; Changed by Neerav; 11 July 2005 $b["sender"] = $raw["mg"][$i][6]; $b["sender_short"] = $raw["mg"][$i][7]; // Added by Neerav; 11 July 2005 $b["sender_email"] = str_replace("\"", "", $raw["mg"][$i][8]); // remove annoying d-quotes in address $b["recv"] = $raw["mg"][$i][9]; $b["recv_email"] = str_replace("\"", "", $raw["mg"][$i][11]); $b["cc_email"] = str_replace("\"", "", $raw["mg"][$i][12]); // was only defined in draft, now both; Changed by Neerav; 11 July $b["bcc_email"] = str_replace("\"", "", $raw["mg"][$i][13]); // was only defined in draft, now both; Changed by Neerav; 11 July $b["reply_email"] = str_replace("\"", "", $raw["mg"][$i][14]); $b["dt_easy"] = $raw["mg"][$i][10]; $b["dt"] = $raw["mg"][$i][15]; $b["subj"] = $raw["mg"][$i][16]; $b["snippet"] = $raw["mg"][$i][17]; //$raw["mg"][$i][19]; // 0 or 1 What is this?? $b["attachment"] = array(); if (isset($raw["mg"][$i][18])) { foreach ($raw["mg"][$i][18] as $bb) { array_push($b["attachment"], array("id" => $bb[0], "filename" => $bb[1], "type" => $bb[2], "size" => $bb[3])); } } if ($raw["mg"][$i][0] == "mi") { $b["is_draft"] = false; $b["body"] = ""; $b["quote_str"] = $raw["mg"][$i][21]; $b["quote_str_html"] = $raw["mg"][$i][22]; // $raw["mg"][$i][20]; // ?? repeated date slightly different format // Added by Neerav; 11 July 2005 } elseif ($raw["mg"][$i][0] == "di") { $b["is_draft"] = true; $b["body"] = $raw["mg"][$i][20]; // $raw["mg"][$i][21]; // ?? repeated date slightly different format // Added by Neerav; 11 July 2005 $b["quote_str"] = $raw["mg"][$i][22]; $b["quote_str_html"] = $raw["mg"][$i][23]; } } } if (isset($b)) { array_push($this->conv, $b); } } } // Changed from elseif to if; by Neerav; 5 Aug 2005 if ($type & GM_CONTACT) { //Debugger::say(print_r($raw,true)); $this->contacts = array(); // Added by Neerav; 29 June 2005 // Since gmail changes their Contacts array often, we need to see which // latest flavor (or flavour) they are using! // Some accounts use "a" for both lists and details // whereas some accounts use "cl" for lists and "cov" for details $type = ""; if (isset($raw["a"])) { $c_array = "a"; // determine is this is a list or contact detail if (count($raw["a"]) == 2 and isset($raw["a"][1][6])) { $type = "detail"; $c_id = 0; $c_name = 1; $c_email = 3; $c_notes = 5; $c_detail = 6; } else { $c_email = 3; $c_notes = 4; $type = "list"; } } elseif (isset($raw["cl"])) { // list $c_array = "cl"; $c_email = 4; $c_notes = 5; $type = "list"; } elseif (isset($raw["cov"])) { // contact detail in accounts using "cl" $c_array = "cov"; $type = "detail"; $c_id = 1; $c_name = 2; $c_email = 4; $c_notes = 7; $c_detail = 8; } else { array_push($this->contacts, array("id" => "error", "name" => "libgmailer Error", "email" => "*****@*****.**", "notes" => "libgmailer could not find the Contacts information " . "due to a change in the email service (again!). Please contact " . "the author of this program (which uses libgmailer) for a fix.")); } // Changed by Neerav; // from "a" to "cl" 15 June 2005 // from "cl" to whichever exists 29 June 2005 if ($type == "list") { // An ordinary list of contacts for ($i = 1; $i < count($raw["{$c_array}"]); $i++) { $a = $raw["{$c_array}"][$i]; $b = array("id" => $a[1], "name" => $a[2], "email" => str_replace("\"", "", $a[$c_email])); // Last Changed by Neerav; 29 June 2005 if (isset($a[$c_notes])) { $b["notes"] = $a[$c_notes]; } array_push($this->contacts, $b); } } elseif ($type == "detail") { // Added by Neerav; 1 July 2005 // Contact details (advanced contact information) // used when a contact id was supplied for retrieval $cov = array(); $cov["id"] = $raw["{$c_array}"][1][$c_id]; $cov["name"] = $raw["{$c_array}"][1][$c_name]; $cov["email"] = str_replace("\"", "", $raw["{$c_array}"][1][$c_email]); if (isset($raw["{$c_array}"][1][$c_notes][0])) { $cov["notes"] = $raw["{$c_array}"][1][$c_notes][0] == "n" ? $raw["{$c_array}"][1][$c_notes][1] : ""; } else { $cov["notes"] = ""; } $details = array(); $num_details = count($raw["{$c_array}"][1][$c_detail]); if ($num_details > 0) { for ($i = 0; $i < $num_details; $i++) { $details[$i][] = array("type" => "detail_name", "info" => $raw["{$c_array}"][1][$c_detail][$i][0]); if (isset($raw["{$c_array}"][1][$c_detail][$i][1])) { $temp = $raw["{$c_array}"][1][$c_detail][$i][1]; } else { $temp = array(); } for ($j = 0; $j < count($temp); $j += 2) { switch ($temp[$j]) { case "p": $field = "phone"; break; case "e": $field = "email"; break; case "m": $field = "mobile"; break; case "f": $field = "fax"; break; case "b": $field = "pager"; break; case "i": $field = "im"; break; case "d": $field = "company"; break; case "t": $field = "position"; break; // t = title // t = title case "o": $field = "other"; break; case "a": $field = "address"; break; default: $field = $temp[$j]; break; // default to the field type } $details[$i][] = array("type" => $field, "info" => $temp[$j + 1]); } } } $cov["details"] = $details; //Debugger::say(print_r($cov["details"],true)); array_push($this->contacts, $cov); //Debugger::say(print_r($this->contacts,true)); } $this->view = GM_CONTACT; } // Changed from elseif to if; by Neerav; 5 Aug 2005 if ($type & GM_PREFERENCE) { //Debugger::say(print_r($raw,true)); // go to Preference Panel // Added by Neerav; 6 July 2005 if (isset($raw["pp"][1])) { switch ($raw["pp"][1]) { case "g": $this->goto_pref_panel = "general"; break; case "l": $this->goto_pref_panel = "labels"; break; case "f": $this->goto_pref_panel = "filters"; break; default: $this->goto_pref_panel = $raw["pp"][1]; break; } } // SETTINGS (NON-Filters, NON-Labels) // Added by Neerav; 29 Jun 2005 $this->setting_gen = array(); $this->setting_fpop = array(); $this->setting_other = array(); //Debugger::say(print_r($raw["p"],true)); if (isset($raw["p"])) { // GENERAL SETTINGS $gen = array("expand_labels" => 1, "expand_invites" => 1, "use_cust_name" => 0, "name_google" => isset($raw["gn"][1]) ? $raw["gn"][1] : "", "name_display" => "", "use_reply_to" => 0, "reply_to" => "", "language" => "en", "page_size" => 25, "shortcuts" => 0, "p_indicator" => 0, "show_snippets" => 0, "use_signature" => 0, "signature" => ""); // FORWARDING AND POP $fpop = array("forward" => 0, "forward_to" => "", "forward_action" => "", "pop_enabled" => 0, "pop_action" => 0); // OTHER $other = array("rich_text" => 0); if (isset($raw["gn"][1])) { $gen["name_google"] = $raw["gn"][1]; } for ($i = 1; $i < count($raw["p"]); $i++) { $pref = $raw["p"][$i][0]; $value = isset($raw["p"][$i][1]) ? $raw["p"][$i][1] : ""; switch ($pref) { // SIDE BOXES case "bx_show0": $gen["expand_labels"] = $value; break; // (boolean) labels box {0 = collapsed, 1 = expanded} // (boolean) labels box {0 = collapsed, 1 = expanded} case "bx_show1": $gen["expand_invites"] = $value; break; // (boolean) invite box {0 = collapsed, 1 = expanded} // GENERAL SETTINGS // (boolean) invite box {0 = collapsed, 1 = expanded} // GENERAL SETTINGS case "sx_dn": $gen["name_display"] = $value; break; // (string) name on outgoing mail (display name) // (string) name on outgoing mail (display name) case "sx_rt": $gen["reply_to"] = $value; break; // (string) reply to email address // (string) reply to email address case "sx_dl": $gen["language"] = $value; break; // (string) display language // (string) display language case "ix_nt": $gen["page_size"] = $value; break; // (integer) msgs per page (maximum page size) // (integer) msgs per page (maximum page size) case "bx_hs": $gen["shortcuts"] = $value; break; // (boolean) keyboard shortcuts {0 = off, 1 = on} // (boolean) keyboard shortcuts {0 = off, 1 = on} case "bx_sc": $gen["p_indicator"] = $value; break; // (boolean) personal level indicators {0 = no indicators, 1 = show indicators} // (boolean) personal level indicators {0 = no indicators, 1 = show indicators} case "bx_ns": $gen["show_snippets"] = !$value; break; // (boolean) no snippets {0 = show snippets, 1 = no snippets} // we INVERSE this for convenience // (boolean) no snippets {0 = show snippets, 1 = no snippets} // we INVERSE this for convenience case "sx_sg": $gen["signature"] = $value; break; // (string) signature // FORWARDING AND POP // (string) signature // FORWARDING AND POP case "sx_em": $fpop["forward_to"] = $value; break; // (string) forward to email // (string) forward to email case "sx_at": $fpop["forward_action"] = $value; break; // (string??) forwarding action {selected (keep), archive, trash} // (string??) forwarding action {selected (keep), archive, trash} case "bx_pe": $fpop["pop_enabled"] = $value; break; // (boolean) pop enabled {0 = disabled, 1 = enabled} // (boolean) pop enabled {0 = disabled, 1 = enabled} case "ix_pd": $fpop["pop_action"] = $value; break; // (integer) action after pop access {0 = keep, 1 = archive, 2 = trash} // OTHER // not used yet or has been removed from Gmail // (integer) action after pop access {0 = keep, 1 = archive, 2 = trash} // OTHER // not used yet or has been removed from Gmail case "bx_cm": $other["rich_text"] = $value; break; // (boolean) rich text composition {0 = plain text, 1 = rich text} // (boolean) rich text composition {0 = plain text, 1 = rich text} default: $other["{$pref}"] = $value; break; } } // set useful implicit boolean settings if ($gen["name_display"] != "") { $gen["use_cust_name"] = 1; } if ($gen["reply_to"] != "") { $gen["use_reply_to"] = 1; } if ($gen["signature"] != "") { $gen["use_signature"] = 1; } if ($fpop["forward_to"] != "") { $fpop["forward"] = 1; } $this->setting_gen = $gen; $this->setting_fpop = $fpop; $this->setting_other = $other; } //Debugger::say(print_r($this->setting_gen,true)); //Debugger::say(print_r($this->setting_fpop,true)); //Debugger::say(print_r($this->setting_other,true)); //Debugger::say(print_r($this,true)); // LABELS $this->label_list = array(); $this->label_total = array(); if (isset($raw["cta"][1])) { foreach ($raw["cta"][1] as $v) { array_push($this->label_list, $v[0]); array_push($this->label_total, $v[1]); } } // FILTERS $this->filter = array(); if (isset($raw["fi"][1])) { foreach ($raw["fi"][1] as $fi) { // Changed/Added by Neerav; 23 Jun 2005 // filter rules/settings // (The "() ? :" notation is used because empty/false fields at the end of an // array are not always defined) $b = array("id" => $fi[0], "query" => isset($fi[1]) ? $fi[1] : "", "from" => isset($fi[2][0]) ? $fi[2][0] : "", "to" => isset($fi[2][1]) ? $fi[2][1] : "", "subject" => isset($fi[2][2]) ? $fi[2][2] : "", "has" => isset($fi[2][3]) ? $fi[2][3] : "", "hasnot" => isset($fi[2][4]) ? $fi[2][4] : "", "hasattach" => (isset($fi[2][5]) and ($fi[2][5] == "true" or $fi[2][5] === true)) ? true : false, "archive" => (isset($fi[2][6]) and ($fi[2][6] == "true" or $fi[2][6] === true)) ? true : false, "star" => (isset($fi[2][7]) and ($fi[2][7] == "true" or $fi[2][7] === true)) ? true : false, "label" => (isset($fi[2][8]) and ($fi[2][8] == "true" or $fi[2][8] === true)) ? true : false, "label_name" => isset($fi[2][9]) ? $fi[2][9] : "", "forward" => (isset($fi[2][10]) and ($fi[2][10] == "true" or $fi[2][10] === true)) ? true : false, "forwardto" => isset($fi[2][11]) ? $fi[2][11] : "", "trash" => (isset($fi[2][12]) and ($fi[2][12] == "true" or $fi[2][12] === true)) ? true : false); array_push($this->filter, $b); //Debugger::say(print_r($b,true)); } } $this->view = GM_PREFERENCE; } /* else { */ /* $this->created = 0; */ /* $this->snapshot_error = "libgmailer: no snapshot type specified"; // Added by Neerav; 3 Aug 2005 */ /* return null; */ /* } */ //Debugger::say(print_r($this,true)); $this->created = 1; return 1; }
/** * Constructor. * * Note: you are not supposed to create a GMailSnapshot object yourself. You should * use {@link GMailer::getSnapshot()} instead. * * @return GMailSnapshot * @param constant $type * @param array $raw */ function GMailSnapshot($type, $raw, $use_session, $raw_html) { // input: raw packet generated by GMailer // Invalid datapack checking // snapshot_error Added; by Neerav; 3 Aug 2005 // Added http errors; by Neerav; 16 Sept 2005 if (!is_array($raw) or count($raw) == 0) { $this->created = 0; if (ereg('gmail_error=([0-9]{3})', $raw_html, $matches)) { $this->snapshot_error = $matches[1]; if ($matches[1] != 500) { Debugger::say("libgmailer: Gmail http error (" . $matches[1] . "), dump RAW HTML:\n" . print_r($raw_html, true)); } /* $this->snapshot_error_no = $matches[1]; */ /* ereg('<p><font size="-1">(.*?)</font></p>',$raw_html,$matches); */ /* $this->snapshot_error = $matches[1]; */ } elseif (ereg('<title>([0-9]{3}) Server Error</title>', $raw_html, $matches)) { $this->snapshot_error = $matches[1]; if ($matches[1] != 502) { Debugger::say("libgmailer: Gmail http error (" . $matches[1] . "), dump RAW HTML:\n" . print_r($raw_html, true)); } } elseif (strpos($raw_html, '500 Internal Server Error') !== false) { $this->snapshot_error = 500; } elseif (strpos($raw_html, 'gmail_error=') !== false) { $this->snapshot_error = "Unknown gmail error"; Debugger::say("libgmailer: unknown gmail error, dump RAW HTML:\n" . print_r($raw_html, true)); } elseif (strpos($raw_html, 'top.location="https://www.google.com/accounts/ServiceLogin') !== false) { // Added error; by Neerav; 12 Oct 2005 //libgmailer: Gmail redirect to login screen $this->snapshot_error = "libg110"; } elseif ($raw_html == "") { $this->snapshot_error = "No response from Gmail"; } elseif (!is_array($raw)) { $this->snapshot_error = "Invalid response from Gmail (not an array)"; Debugger::say("libgmailer: invalid datapack -- not an array, dump RAW HTML:\n" . print_r($raw_html, true)); } elseif (count($raw) == 0) { $this->snapshot_error = "Invalid response from Gmail (empty)"; } return null; } // Gmail version if (isset($raw["v"][1])) { $this->gmail_ver = $raw["v"][1]; } //$raw["v"][2] // What is this? Another version number? //$raw["v"][3] // What is this? // IdentificationKey (ik) // Added by Neerav; 6 July 2005 if ($use_session) { if (!isset($_SESSION['id_key']) or $_SESSION['id_key'] == "") { Debugger::say("Snapshot: Using Sessions, saving id_key(ik)..."); if (isset($raw["ud"][3])) { $_SESSION['id_key'] = $raw["ud"][3]; Debugger::say("Snapshot: Session id_key saved: " . $_SESSION['id_key']); } else { Debugger::say('Snapshot: Session id_key NOT saved. $raw["ud"][3] not found.'); } } } else { if (!isset($_COOKIE[GM_COOKIE_IK_KEY]) or $_COOKIE[GM_COOKIE_IK_KEY] == 0) { Debugger::say("Snapshot: Using Cookies, saving id_key(ik)..."); if (isset($raw["ud"][3])) { if (strpos($_SERVER["HTTP_HOST"], ":")) { $domain = substr($_SERVER["HTTP_HOST"], 0, strpos($_SERVER["HTTP_HOST"], ":")); } else { $domain = $_SERVER["HTTP_HOST"]; } Debugger::say("Saving id_key as cookie " . GM_COOKIE_IK_KEY . " with domain=" . $domain); header("Set-Cookie: " . GM_COOKIE_IK_KEY . "=" . base64_encode($raw["ud"][3]) . "; Domain=" . $domain . ";"); Debugger::say("Snapshot: Cookie id_key saved: " . GM_COOKIE_IK_KEY . "=" . base64_encode($raw["ud"][3])); } else { Debugger::say('Snapshot: Cookie id_key NOT saved. $raw["ud"][3] not found.'); } } } // other "UD" // Added by Neerav; 6 July 2005 if (isset($raw["ud"])) { // account email address // your app SHOULD cache this in session or cookie for use across pages // Added by Neerav; 6 May 2005 $this->gmail_email = $raw["ud"][1]; //$raw["ud"][2] // keyboard shortcuts //$raw["ud"][3] // Identification Key, set above //$raw["ud"][4] // What is this? referrer? //$raw["ud"][5] // What is this? //$raw["ud"][6] // What is this? //$raw["ud"][7] // What is this? } // su //$raw["su"][1] // What is this? (matches $raw["v"][2]) //$raw["su"][2] // What is this? (?? array of text strings for invites) // cp //$raw["cp"][1] // What is this? (always 1) //$raw["cp"][2] // What is this? (always 0) // csm //$raw["csm"][1] // What is this? (always 1) // cld //$raw["cld"] // What is this? (empty) // COUntry // Added by Neerav; 20 Dec 2005 $this->country = isset($raw["cou"][1]) ? $raw["cou"][1] : ""; // Google Accounts' name // your app SHOULD cache this in session or cookie for use across pages // it's bandwidth expensive to retrieve preferences just for this // Added by Neerav; 2 July 2005 if (isset($raw["gn"][1])) { $this->google_name = $raw["gn"][1]; } // Signature // your app SHOULD cache this in session or cookie for use across pages // it's bandwidth expensive to retrieve preferences just for this // Added by Neerav; 6 July 2005 if (isset($raw["p"])) { for ($i = 0; $i < count($raw["p"]); $i++) { if ($raw["p"][$i][0] == "sx_sg") { // can be undefined ?!?! $this->signature = isset($raw["p"][$i][1]) ? $raw["p"][$i][1] : ""; break; } } } // Invites if (isset($raw["i"][1])) { $this->have_invit = $raw["i"][1]; } else { $this->have_invit = 0; } // QUota information if (isset($raw["qu"])) { // Space used as xx MB $this->quota_mb = $raw["qu"][1]; // Total space allotted as xxxx MB $this->quota_tot = $raw["qu"][2]; // Added by Neerav; 6 May 2005 // Space used as xx% $this->quota_per = $raw["qu"][3]; // Added by Neerav; 6 May 2005 // html color as #aabbcc (normally a green color, but red when nearly full) $this->quota_col = $raw["qu"][4]; // Added by Neerav; 6 July 2005 } // Footer Tips or Fast Tips // Added by Neerav; 6 July 2005 if (isset($raw["ft"][1])) { $this->gmail_tip = $raw["ft"][1]; } // cfs; Compose from source // Added by Neerav: 30 Aug 2005; Modified by Gan: 9 Sep 2005 $this->personality = array(); $this->personality_unverify = array(); if (isset($raw["cfs"])) { if (isset($raw["cfs"][1])) { $person_verified = count($raw["cfs"][1]); for ($i = 0; $i < $person_verified; $i++) { $this->personality[] = array("name" => $raw["cfs"][1][$i][0], "email" => $raw["cfs"][1][$i][1], "default" => $raw["cfs"][1][$i][2] == 0 ? false : true, "reply-to" => isset($raw["cfs"][1][$i][3]) ? $raw["cfs"][1][$i][3] : "", "verified" => true); } $person_unverified = count($raw["cfs"][2]); for ($i = 0; $i < $person_unverified; $i++) { $this->personality_unverify[] = array("name" => $raw["cfs"][2][$i][0], "email" => $raw["cfs"][2][$i][1], "default" => $raw["cfs"][2][$i][2] == 0 ? false : true, "reply-to" => isset($raw["cfs"][2][$i][3]) ? $raw["cfs"][2][$i][3] : "", "verified" => false); } } } // What is this? // $raw["df"][1] // shows ?false? // $raw["ms"] // $raw["e"] // $raw["pod"] // $raw["te"] // $raw["csm"][1] // $raw["ad"] // web clips and advertisements if ($type & (GM_STANDARD | GM_LABEL | GM_CONVERSATION | GM_QUERY)) { // Added by Neerav; 6 May 2005 if (isset($raw["p"]) and !isset($this->signature)) { for ($i = 1; $i < count($raw["p"]); $i++) { if ($raw["p"][$i][0] == "sx_sg") { // can be undefined ?!?! $this->signature = isset($raw["p"][$i][1]) ? $raw["p"][$i][1] : ""; break; } } } if (!isset($this->signature)) { $this->signature = ""; } // when a conversation does not exist, neither does ds; Fix by Neerav; 1 Aug 2005 if (isset($raw["ds"])) { if (!is_array($raw["ds"])) { $this->created = 0; $this->snapshot_error = "libgmailer: invalid datapack"; return null; } // Fix for change in format of unread messages in some accounts; by Neerav; 2 Feb 2006 if (is_array($raw["ds"][1])) { $this->std_box_new = array(0, 0, 0, 0, 0, 0, 0); $std_boxes = array("inbox", "starred", "sent", "drafts", "all", "spam", "trash"); foreach ($raw["ds"][1] as $std_box) { $name = $std_box[0]; $which_box = array_search($name, $std_boxes); if ($which_box !== false and $which_box !== "") { $this->std_box_new[$which_box] = $std_box[1]; } } } else { $this->std_box_new = array_slice($raw["ds"], 1); } } else { $this->created = 0; if (isset($raw["tf"])) { $this->snapshot_error = $raw["tf"][1]; } else { $this->snapshot_error = "libgmailer: unknown but fatal datapack error"; Debugger::say("ds AND tf undefined, dumping raw: " . print_r($raw, true)); } return null; } $this->label_list = array(); $this->label_new = array(); // Last changed by Neerav; 12 July 2005 if (isset($raw["ct"][1]) and count($raw["ct"][1]) > 0) { foreach ($raw["ct"][1] as $v) { array_push($this->label_list, $v[0]); array_push($this->label_new, $v[1]); } } elseif (isset($raw["ct"]) and !isset($raw["ct"][1])) { Debugger::say('ct[1] not set, raw[ct] dump: ' . print_r($raw["ct"], true)); } // Thread Summary if (isset($raw["ts"])) { $this->view = GM_STANDARD | GM_LABEL | GM_QUERY; $this->box_name = $raw["ts"][5]; // name of box/label/query $this->box_total = $raw["ts"][3]; // total messages found $this->box_pos = $raw["ts"][1]; // starting message number // Added by Neerav; 6 July 2005 $this->box_display = $raw["ts"][2]; // max number of messages to display on the page $this->box_query = $raw["ts"][6]; // gmail query for box $this->queried_results = $raw["ts"][4]; // was this a search query (bool) //$this->?? = $raw["ts"][7]; // what is this?? some id number? //$this->?? = $raw["ts"][8]; // what is this?? total number of messages in account? //$this->?? = $raw["ts"][9]; // what is this?? serial number, id number, VERY LONG! //$this->?? = $raw["ts"][10]; // what is this?? always blank } $this->box = array(); if (isset($raw["t"])) { foreach ($raw["t"] as $t) { if ($t == "t") { continue; } // Fix for 12 OR 13 fields!!; by Neerav; 23 July 2005 //$less = (count($t) == 12) ? 1 : 0 ; // Changed to 12 or 13 vs. 14 fields; by Neerav; 25 Oct 2005 // is this permanent?? did Gmail increase the size of the array?? Why? What? //$less = (count($t) == 12 or count($t) == 13) ? 1 : 0 ; // Gmail increased the length of the array on/before 25 Oct 2005 // Instead of relying on array size, we look for the labels array // Update: (15 Apr 2006) now there are upto 16 fields. if (count($t) < 12) { $less = 0; $tb["id"] = $t[0]; $tb["is_read"] = 0; $tb["is_starred"] = 0; $tb["date"] = "(error)"; $tb["sender"] = "(error)"; $tb["flag"] = ""; $tb["subj"] = "(error)"; //$tb["snippet"] = ((count($t) == 12) ? "" : $t[7] ); $tb["snippet"] = "(error)"; $tb["msgid"] = "(error)"; $tb["labels"] = array(); // gives an array even if 0 labels $tb["attachment"] = array(); //$tb["??"] = $t[10-$less]; //$tb["??"] = $t[11-$less]; $tb["long_date"] = "(error)"; $tb["long_time"] = "(error)"; $tb["is_chat"] = 0; $tb["chat_length"] = ""; //$tb["??"] = $t[15-$less]; array_push($this->box, $tb); continue; } elseif (is_array($t[8])) { // normal $less = 0; } elseif (is_array($t[7])) { // without snippet $less = 1; } elseif (is_array($t[9])) { // just here for future compatibility $less = -1; } elseif (is_array($t[6])) { // just here for future compatibility $less = 2; } else { $less = 0; } // Added by Neerav; 6 July 2005 $long_date = ""; $long_time = ""; $date_time = explode("_", $t[12 - $less]); if (isset($date_time[0])) { $long_date = $date_time[0]; } if (isset($date_time[1])) { $long_time = $date_time[1]; } // Added labels for use in multiple languages; by Neerav; 7 Aug 2005 //$label_array_lang = $t[8-$less]; // Added by Neerav; 6 July 2005 // Gives an array of labels and substitutes the standard names // Changed to be language compatible; by Neerav; 8 Aug 2005 $label_array = array(); foreach ($t[8 - $less] as $label_entry) { switch ($label_entry) { //case "^i": $label_array[] = "Inbox"; break; //case "^s": $label_array[] = "Spam"; break; //case "^k": $label_array[] = "Trash"; break; case "^t": /* Starred */ break; //case "^r": $label_array[] = "Draft"; break; //case "^r": $label_array[] = "Draft"; break; default: $label_array[] = $label_entry; break; } } $tb = array(); $tb["id"] = $t[0]; $tb["is_read"] = $t[1] == 1 ? 1 : 0; $tb["is_starred"] = $t[2] == 1 ? 1 : 0; $tb["date"] = strip_tags($t[3]); $tb["sender"] = strip_tags($t[4], "<b>"); $tb["flag"] = $t[5]; $tb["subj"] = strip_tags($t[6], "<b>"); //$tb["snippet"] = ((count($t) == 12) ? "" : $t[7] ); $tb["snippet"] = $less ? "" : $t[7]; $tb["msgid"] = $t[10 - $less]; // Added by Neerav; 7 Aug 2005 //$tb["labels_lang"]= $label_array_lang; // for use with languages // Added/Changed by Neerav; 6 July 2005 $tb["labels"] = $label_array; // gives an array even if 0 labels $tb["attachment"] = strlen($t[9 - $less]) == 0 ? array() : explode(",", $t[9 - $less]); // Changed to give an array even if 0 attachments //$tb["??"] = $t[10-$less]; // what is this?? repeat of id?? //$tb["??"] = $t[11-$less]; // what is this?? always 0 $tb["long_date"] = $long_date; // added $tb["long_time"] = $long_time; // added // some accounts have chat, some do not if (isset($t[13 - $less])) { $tb["is_chat"] = $t[13 - $less]; // Added by (Gmail) Neerav; 16 Feb 2006; $tb["chat_length"] = $t[14 - $less]; // Added by (Gmail) Neerav; 16 Feb 2006; //$tb["??"] = $t[15-$less]; // Added by (Gmail) Neerav; 16 Feb 2006; what is this?? always 0 } else { $tb["is_chat"] = 0; // Added by (Gmail) Neerav; 16 Feb 2006; $tb["chat_length"] = ""; // Added by (Gmail) Neerav; 16 Feb 2006; //$tb["??"] = $t[15-$less]; // Added by (Gmail) Neerav; 16 Feb 2006; what is this?? always 0 } array_push($this->box, $tb); } } if (isset($raw["cs"])) { //Debugger::say("cs exists: ".print_r($raw["cs"],true)); //Debugger::say("cs exists, dumping raw: ".print_r($raw,true)); // Fix for 14 OR 12 fields!!; by Neerav; 25 July 2005 $less = count($raw["cs"]) == 12 ? 2 : 0; $this->view = GM_CONVERSATION; $this->conv_id = $raw["cs"][1]; $this->conv_title = $raw["cs"][2]; // $raw["cs"][3] // what is this?? escape/html version of 2? // $raw["cs"][4] // what is this?? empty // $raw["cs"][5] // (array) conversation labels, below // $raw["cs"][6] // what is this?? array // $raw["cs"][7] // what is this?? integer/bool? $this->conv_total = $raw["cs"][8]; // (count($t) == 14) $raw["cs"][9] // may be missing! what is this?? long id number? // (count($t) == 14) $raw["cs"][10] // may be missing! what is this?? empty // $raw["cs"][11-$less] // may be 9 what is this?? repeat of id 1? // $raw["cs"][12-$less] // may be 10 what is this?? array // $raw["cs"][13-$less] // may be 11 what is this?? integer/bool? $this->conv_labels = array(); $this->conv_starred = false; // Added labels for use in multiple languages; by Neerav; 7 Aug 2005 //$this->conv_labels_lang = $raw["cs"][5]; // for use with languages // Changed to give translated label names; by Neerav; 6 July 2005 // Changed back to be language compatible; by Neerav; 8 Aug 2005 //$this->conv_labels_temp = (count($raw["cs"][5])==0) ? array() : $raw["cs"][5]; $temp_array = $raw["cs"][5]; foreach ($raw["cs"][5] as $label_entry) { switch ($label_entry) { //case "^i": $this->conv_labels[] = "Inbox"; break; //case "^s": $this->conv_labels[] = "Spam"; break; //case "^k": $this->conv_labels[] = "Trash"; break; case "^t": $this->conv_starred = true; break; //case "^r": $this->conv_labels[] = "Draft"; break; //case "^r": $this->conv_labels[] = "Draft"; break; default: $this->conv_labels[] = $label_entry; break; } } $this->conv = array(); if (!isset($raw["mg"])) { // Added error; by Neerav; 24 Sept 2005 // libg102 error: a specific message has been requested, but must actually be // taken from the thread (message may be a draft or other expanded message) $this->snapshot_error = "libg102"; $this->created = 0; return null; } else { $mg_count = count($raw["mg"]); for ($i = 0; $i < $mg_count; $i++) { if ($raw["mg"][$i][0] == "mb" && $i > 0) { if (isset($raw["mg"][$i][1])) { $b["body"] .= $raw["mg"][$i][1]; } else { // Added error; by Neerav; 9 Feb 2006 // THIS ERROR OCCURS BECAUSE ?? $this->snapshot_error = "libg101"; $this->created = 0; return null; } if (isset($raw["mg"][$i][2])) { if ($raw["mg"][$i][2] == 0) { array_push($this->conv, $b); unset($b); } } else { // Added error; by Neerav; 9 Feb 2006 // THIS ERROR OCCURS BECAUSE OF IMPROPER DATAPACK PARSING $this->snapshot_error = "libg101"; $this->created = 0; return null; } } elseif ($raw["mg"][$i][0] == "mi" or $raw["mg"][$i][0] == "di") { // to account for an added 20th index with a phishing warning // Added by Neerav; 1 Dec 2005 /* $more = (isset($raw["mg"][$i][26]) and is_array($raw["mg"][$i][26])) ? 1 : 0 ; */ // Changed by Neerav; 24 Mar 2006 $more = (isset($raw["mg"][$i][20]) and strpos($raw["mg"][$i][20], "<font color=\"#ffffff\">") !== false) ? 1 : 0; // Changed to merge "di" and "mi" routines; by Neerav; 11 July 2005 if (isset($b)) { array_push($this->conv, $b); unset($b); } $b = array(); // $raw["mg"][$i][0] is mi or di $b["mbox"] = $raw["mg"][$i][1]; // Added by Neerav; 11 July 2005 $b["is_trashed"] = (int) $raw["mg"][$i][1] & 128 ? true : false; // Added by Neerav; 23 Feb 2006 $b["is_html"] = (int) $raw["mg"][$i][1] & (16 | 32) ? true : false; // Added by Neerav; 23 Feb 2006 $b["html_images"] = (int) $raw["mg"][$i][1] & 32 ? true : false; // Added by Neerav; 23 Feb 2006 $b["index"] = $raw["mg"][$i][2]; $b["id"] = $raw["mg"][$i][3]; $b["is_star"] = $raw["mg"][$i][4]; if ($b["is_star"] == 1) { $this->conv_starred = true; } $b["draft_parent"] = $raw["mg"][$i][5]; // was only defined in draft, now both; Changed by Neerav; 11 July 2005 $b["sender"] = $raw["mg"][$i][6]; $b["sender_short"] = $raw["mg"][$i][7]; // Added by Neerav; 11 July 2005 $b["sender_email"] = str_replace("\"", "", $raw["mg"][$i][8]); // remove annoying d-quotes in address $b["recv"] = strip_tags($raw["mg"][$i][9]); $b["recv_email"] = str_replace("\"", "", $raw["mg"][$i][11]); $b["cc_email"] = str_replace("\"", "", $raw["mg"][$i][12]); // was only defined in draft, now both; Changed by Neerav; 11 July $b["dt_easy"] = $raw["mg"][$i][10]; if (isset($raw["mg"][$i][15]) and isset($raw["mg"][$i][16]) and isset($raw["mg"][$i][13]) and isset($raw["mg"][$i][14]) and isset($raw["mg"][$i][17])) { $b["bcc_email"] = str_replace("\"", "", $raw["mg"][$i][13]); // was only defined in draft, now both; Changed by Neerav; 11 July 2005 $b["reply_email"] = str_replace("\"", "", $raw["mg"][$i][14]); $b["dt"] = $raw["mg"][$i][15]; $b["subj"] = $raw["mg"][$i][16]; } else { // Added error; by Neerav; 9 Jan 2006 // THIS ERROR OCCURS BECAUSE OF IMPROPER DATAPACK PARSING $this->snapshot_error = "libg101"; $this->created = 0; return null; } $b["snippet"] = $raw["mg"][$i][17]; $b["sender_in_contact"] = $raw["mg"][$i][19]; // (0,1) sender already in the contacts list; Added by Neerav; 6 Mar 2006 $b["attachment"] = array(); if (isset($raw["mg"][$i][18])) { // attachments if (!is_array($raw["mg"][$i][18])) { // Added error; by Neerav; 24 Sept 2005 // THIS ERROR OCCURS BECAUSE OF IMPROPER DATAPACK PARSING $this->snapshot_error = "libg101"; $this->created = 0; return null; } else { foreach ($raw["mg"][$i][18] as $bb) { array_push($b["attachment"], array("id" => $bb[0], "filename" => $bb[1], "type" => str_replace("\"", "", $bb[2]), "size" => $bb[3])); if (!isset($bb[1])) { Debugger::say("undefined attachment info, dumping message: ", print_r($raw["mg"][$i], true)); Debugger::say("undefined attachment info, dumping raw: " . print_r($raw, true)); Debugger::say("undefined attachment info, dumping raw_html: " . print_r($raw_html, true)); } } } } if ($raw["mg"][$i][0] == "mi") { $b["is_draft"] = false; $b["body"] = ""; $b["warning"] = $more == 1 ? $raw["mg"][$i][20] : ""; // phishing WARNING from Gmail // Added by Neerav; 1 Dec 2005 // $raw["mg"][$i][20+$more]; // ?? repeated date in unix-like format with an _ // Added by Neerav; 11 July 2005 $b["quote_str"] = $raw["mg"][$i][21 + $more]; $b["quote_str_html"] = $raw["mg"][$i][22 + $more]; // Added the following indexes; Neerav; 1 Dec 2005 // $raw["mg"][$i][23+$more]; // What is this?? sender's domain? // $raw["mg"][$i][24+$more]; // always blank What is this?? // $raw["mg"][$i][25+$more]; // always array(,,1) What is this?? // $raw["mg"][$i][26+$more]; // always blank What is this?? // $raw["mg"][$i][27+$more]; // array(,,0) or blank What is this?? // $raw["mg"][$i][28+$more]; // always 0 What is this?? // $raw["mg"][$i][29+$more]; // header: Sender (real sender: don't need this) // 6 Mar 2006 // $raw["mg"][$i][30+$more]; // header: Message-ID (don't need this in snapshot) // 3 Mar 2006 // $raw["mg"][$i][31+$more]; // always 0 What is this?? $b["to_custom_from"] = isset($raw["mg"][$i][32 + $more]) ? $raw["mg"][$i][32 + $more] : ""; // Custom From which this message was sent to // $raw["mg"][$i][33+$more]; // always 0 What is this?? } elseif ($raw["mg"][$i][0] == "di") { $b["is_draft"] = true; $b["body"] = $raw["mg"][$i][20]; // $raw["mg"][$i][21]; // ?? repeated date slightly different format // Added by Neerav; 11 July 2005 if (isset($raw["mg"][$i][22]) and isset($raw["mg"][$i][23])) { $b["quote_str"] = $raw["mg"][$i][22]; $b["quote_str_html"] = $raw["mg"][$i][23]; } else { // Added error; by Neerav; 9 Jan 2006 // THIS ERROR OCCURS BECAUSE OF IMPROPER DATAPACK PARSING $this->snapshot_error = "libg101"; $this->created = 0; return null; } // Added to match additions to "mi"; by Neerav; 1 Dec 2005 $b["warning"] = ""; } } } } if (isset($b)) { array_push($this->conv, $b); } } } // Changed from elseif to if; by Neerav; 5 Aug 2005 if ($type & GM_CONTACT) { $this->contacts = array(); $this->contact_groups = array(); // Added by Neerav; 20 Dec 2005 $this->contacts_total = 0; // Added by Neerav; 5 Jan 2006 // general contacts information; Added by Neerav; 5 Jan 2006 if (isset($raw["cls"])) { $this->contacts_total = $raw["cls"][1]; // total number of contacts //$raw["cls"][2] // array, type of contacts //$raw["cls"][2][i][0] // Gmail code for type of contacts: p=frequent, a=all, l=group, s=search //$raw["cls"][2][i][1] // Human readable button text for the above code type $this->contacts_shown = $raw["cls"][3]; // Gmail code for type of contacts currently shown/retrieved //$this->contacts_total = $raw["cls"][4] // is 4 ?? What is this?? } // Added by Neerav; 29 June 2005 // Since gmail changes their Contacts array often, we need to see which // latest flavor (or flavour) they are using! // Some accounts use "a" for both lists and details // whereas some accounts use "cl" for lists and "cov" for details $type = ""; $c_grp_det = ""; if (isset($raw["a"])) { Debugger::say("uses 'a' for contacts: " . print_r($raw, true)); $c_array = "a"; // determine is this is a list or contact detail if (count($raw["a"]) == 2 and isset($raw["a"][1][6])) { $type = "detail"; $c_id = 0; $c_name = 1; $c_email = 3; $c_groups = 4; $c_notes = 5; $c_detail = 6; } else { $c_email = 3; $c_notes = 4; $type = "list"; //$c_addresses = 5; } } elseif (isset($raw["cl"])) { // list $c_array = "cl"; $c_email = 4; $c_notes = 5; $c_addresses = 6; $type = "list"; } elseif (isset($raw["cov"])) { // contact detail in accounts using "cl" $c_array = "cov"; $type = "detail"; $c_id = 1; $c_name = 2; $c_email = 4; $c_groups = 6; $c_notes = 7; $c_detail = 8; } elseif (isset($raw["clv"])) { // group detail in accounts using "cl" // added by Neerav; 6 Jan 2006 $c_array = "clv"; //$c_grp_det = "cle"; $type = "detail"; $c_id = 1; $c_name = 2; $c_email = 6; $c_total = 3; $c_detail = 5; $c_members = 4; $c_notes = 0; } else { array_push($this->contacts, array("id" => "error", "name" => "libgmailer Error", "email" => "*****@*****.**", "is_group" => 0, "notes" => "libgmailer could not find the Contacts information " . "due to a change in the email service (again!). Please contact " . "the author of this program (which uses libgmailer) for a fix.")); } // Changed by Neerav; // from "a" to "cl" 15 June 2005 // from "cl" to whichever exists 29 June 2005 if ($type == "list") { // An ordinary list of contacts for ($i = 1; $i < count($raw["{$c_array}"]); $i++) { $a = $raw["{$c_array}"][$i]; $b = array("id" => $a[1], "name" => isset($a[2]) ? $a[2] : "", "email" => str_replace("\"", "", $a[$c_email])); // Last Changed by Neerav; 29 June 2005 if (isset($a[$c_notes])) { // Contact groups support; 5 Jan 2006 if (is_array($a[$c_notes])) { $b["notes"] = ""; $b["is_group"] = true; // email addresses for groups are in a different location and format // "Name" <*****@*****.**>, "Name2" <*****@*****.**>, etc // and needs to be "simply" re-created for backwards compatibility $gr_count = count($a[$c_notes]); $group_addresses = array(); for ($gr_entry = 0; $gr_entry < $gr_count; $gr_entry++) { $group_addresses[] = $a[$c_notes][$gr_entry][1]; } $b["email"] = implode(", ", $group_addresses); //$b["email"] = str_replace("\"", "", $a[$c_addresses]); $b["group_names"] = $a[$c_email]; $b["group_total"] = $a[3]; $b["group_email"] = count($a[$c_notes]) > 0 ? $a[$c_addresses] : array(); } else { $b["notes"] = $a[$c_notes]; $b["is_group"] = false; $b["groups"] = $a[$c_addresses]; } } array_push($this->contacts, $b); } } elseif ($type == "detail") { //Debugger::say("raw: ".print_r($raw,true)); $details = array(); if ($c_array == "clv") { // Added by Neerav; 6 Jan 2006 // Group details $cov["is_group"] = true; // is this a group? $cov["id"] = $raw["{$c_array}"][1][$c_id]; // group id $cov["name"] = $raw["{$c_array}"][1][$c_name]; // group name $gr_count = count($raw["{$c_array}"][1][$c_detail]); $cov["group_names"] = $raw["{$c_array}"][1][$c_members]; // string of names of group members $cov["group_total"] = $raw["{$c_array}"][1][$c_total]; // string, total number of members in group $cov["group_email"] = str_replace("\"", "", $raw["{$c_array}"][1][$c_email]); // formatted list of addresses as: Name <address> $cov["notes"] = ""; // no notes for groups... yet! $group_addresses = array(); // string of flattened email addresses $group_members = array(); // array of group members for ($gr_entry = 0; $gr_entry < $gr_count; $gr_entry++) { $group_addresses[] = $raw["{$c_array}"][1][$c_detail][$gr_entry][1]; $cov["members"][] = array("id" => $raw["{$c_array}"][1][$c_detail][$gr_entry][0], "name" => isset($raw["{$c_array}"][1][$c_detail][$gr_entry][2]) ? $raw["{$c_array}"][1][$c_detail][$gr_entry][2] : "", "email" => $raw["{$c_array}"][1][$c_detail][$gr_entry][1]); } $cov["email"] = count($group_addresses) > 0 ? implode(", ", $group_addresses) : ""; } else { // Added by Neerav; 1 July 2005 // Contact details (advanced contact information) // used when a contact id was supplied for retrieval $cov = array(); $cov["is_group"] = false; $cov["id"] = $raw["{$c_array}"][1][$c_id]; $cov["name"] = $raw["{$c_array}"][1][$c_name]; $cov["email"] = str_replace("\"", "", $raw["{$c_array}"][1][$c_email]); $cov["groups"] = $raw["{$c_array}"][1][$c_groups]; if (isset($raw["{$c_array}"][1][$c_notes][0])) { $cov["notes"] = $raw["{$c_array}"][1][$c_notes][0] == "n" ? $raw["{$c_array}"][1][$c_notes][1] : ""; } else { $cov["notes"] = ""; } $num_details = count($raw["{$c_array}"][1][$c_detail]); if ($num_details > 0) { for ($i = 0; $i < $num_details; $i++) { $details[$i][] = array("type" => "detail_name", "info" => $raw["{$c_array}"][1][$c_detail][$i][0]); if (isset($raw["{$c_array}"][1][$c_detail][$i][1])) { $temp = $raw["{$c_array}"][1][$c_detail][$i][1]; } else { $temp = array(); Debugger::say('$raw[' . $c_array . '][1][' . $c_detail . '][' . $i . '][1] not defined libgmailer: 2548, dumping raw: ' . print_r($raw, true)); } for ($j = 0; $j < count($temp); $j += 2) { switch ($temp[$j]) { case "p": $field = "phone"; break; case "e": $field = "email"; break; case "m": $field = "mobile"; break; case "f": $field = "fax"; break; case "b": $field = "pager"; break; case "i": $field = "im"; break; case "d": $field = "company"; break; case "t": $field = "position"; break; // t = title // t = title case "o": $field = "other"; break; case "a": $field = "address"; break; default: $field = $temp[$j]; break; // default to the field type } $details[$i][] = array("type" => $field, "info" => $temp[$j + 1]); } } } $cov["details"] = $details; } array_push($this->contacts, $cov); } // Contact groups // Added by Neerav; 20 Dec 2005 if (isset($raw["cla"])) { for ($i = 1; $i < count($raw["cla"][1]); $i++) { $a = $raw["cla"][1][$i]; $b = array("id" => $a[0], "name" => $a[1], "addresses" => isset($a[2]) ? str_replace("\"", "", $a[2]) : ""); array_push($this->contact_groups, $b); } } $this->view = GM_CONTACT; } // Changed from elseif to if; by Neerav; 5 Aug 2005 if ($type & GM_PREFERENCE) { // go to Preference Panel // Added by Neerav; 6 July 2005 if (isset($raw["pp"][1])) { switch ($raw["pp"][1]) { case "g": $this->goto_pref_panel = "general"; break; case "l": $this->goto_pref_panel = "labels"; break; case "f": $this->goto_pref_panel = "filters"; break; default: $this->goto_pref_panel = $raw["pp"][1]; break; } } // SETTINGS (NON-Filters, NON-Labels) // Added by Neerav; 29 Jun 2005 $this->setting_gen = array(); $this->setting_fpop = array(); $this->setting_other = array(); $this->setting_mobile = array(); $this->setting_chat = array(); if (isset($raw["p"])) { // GENERAL SETTINGS $gen = array("name_google" => isset($raw["gn"][1]) ? $raw["gn"][1] : "", "language" => "en", "page_size" => 25, "shortcuts" => 0, "p_indicator" => 0, "show_snippets" => 0, "use_signature" => 0, "signature" => "", "encoding" => 0, "vacation_enabled" => 0, "vacation_subject" => "", "vacation_message" => "", "vacation_contact" => 0); // FORWARDING AND POP $fpop = array("forward" => 0, "forward_to" => "", "forward_action" => "selected", "pop_enabled" => 0, "pop_action" => 0); // MOBILE $mobile = array("display_boxes" => array("inbox", "starred", "sent", "drafts", "all", "spam", "trash")); // CHAT $chat = array("save_chat" => 0); // OTHER $other = array("google_display_name" => isset($raw["gn"][1]) ? $raw["gn"][1] : "", "google_reply_to" => "", "expand_labels" => 1, "expand_invites" => 1, "expand_talk" => 1, "reply_from_sent" => 0, "rich_text" => 0, "save_chat" => 0); if (isset($raw["gn"][1])) { $gen["name_google"] = $raw["gn"][1]; } for ($i = 1; $i < count($raw["p"]); $i++) { $pref = $raw["p"][$i][0]; $value = isset($raw["p"][$i][1]) ? $raw["p"][$i][1] : ""; switch ($pref) { // GENERAL SETTINGS //case "sx_dn": $gen["name_display"] = $value; break; // (string) name on outgoing mail (display name) //case "sx_rt": $gen["reply_to"] = $value; break; // (string) reply to email address case "sx_dl": $gen["language"] = $value; break; // (string) display language // (string) display language case "ix_nt": $gen["page_size"] = $value; break; // (integer) msgs per page (maximum page size) // (integer) msgs per page (maximum page size) case "bx_hs": $gen["shortcuts"] = $value; break; // (boolean) keyboard shortcuts {0 = off, 1 = on} // (boolean) keyboard shortcuts {0 = off, 1 = on} case "bx_sc": $gen["p_indicator"] = $value; break; // (boolean) personal level indicators {0 = no indicators, 1 = show indicators} // (boolean) personal level indicators {0 = no indicators, 1 = show indicators} case "bx_ns": $gen["show_snippets"] = !$value; break; // (boolean) no snippets {0 = show snippets, 1 = no snippets} // we INVERSE this for convenience // (boolean) no snippets {0 = show snippets, 1 = no snippets} // we INVERSE this for convenience case "sx_sg": $gen["signature"] = $value; break; // (string) signature // (string) signature case "bx_en": $gen["encoding"] = $value; break; // (boolean) outgoing message encoding {0 = default, 1 = utf-8} // added by Neerav; 20 Dec 2005 // (boolean) outgoing message encoding {0 = default, 1 = utf-8} // added by Neerav; 20 Dec 2005 case "bx_ve": $gen["vacation_enabled"] = $value; break; // (boolean) vacation message enabled {0 = OFF, 1 = ON} // (boolean) vacation message enabled {0 = OFF, 1 = ON} case "sx_vs": $gen["vacation_subject"] = $value; break; // (string) vacation message subject // (string) vacation message subject case "sx_vm": $gen["vacation_message"] = $value; break; // (string) vacation message text // (string) vacation message text case "bx_vc": $gen["vacation_contact"] = ($value == "true" or $value === true) ? true : false; break; // (string to boolean) vacation message, send only to contacts list // FORWARDING AND POP // (string to boolean) vacation message, send only to contacts list // FORWARDING AND POP case "sx_em": $fpop["forward_to"] = $value; break; // (string) forward to email // (string) forward to email case "sx_at": $fpop["forward_action"] = $value; break; // (string) forwarding action {selected (keep), archive, trash} // (string) forwarding action {selected (keep), archive, trash} case "bx_pe": $fpop["pop_enabled"] = $value; break; // (integer) pop enabled {0 = disabled, 2 = enabled from now, 3 = enable all} // (integer) pop enabled {0 = disabled, 2 = enabled from now, 3 = enable all} case "ix_pd": $fpop["pop_action"] = $value; break; // (integer) action after pop access {0 = keep, 1 = archive, 2 = trash} // SIDE BOXES // (integer) action after pop access {0 = keep, 1 = archive, 2 = trash} // SIDE BOXES case "bx_show0": $other["expand_labels"] = $value; break; // (boolean) labels box {0 = collapsed, 1 = expanded} // (boolean) labels box {0 = collapsed, 1 = expanded} case "bx_show1": $other["expand_invites"] = $value; break; // (boolean) invite box {0 = collapsed, 1 = expanded} // (boolean) invite box {0 = collapsed, 1 = expanded} case "bx_show3": $other["expand_talk"] = $value; break; // (boolean) gtalk box {0 = collapsed, 1 = expanded} // ACCOUNT // (boolean) gtalk box {0 = collapsed, 1 = expanded} // ACCOUNT case "bx_rf": $other["reply_from_sent"] = $value; break; // (boolean) use reply from [sent] {0 = use default address, 1 = use address message was sent to} // added by Neerav; 4 Mar 2006 // (boolean) use reply from [sent] {0 = use default address, 1 = use address message was sent to} // added by Neerav; 4 Mar 2006 case "sx_dn": $other["google_display_name"] = $value; break; // (string) Google accounts "from" display name // (string) Google accounts "from" display name case "sx_rt": $other["google_reply_to"] = $value; break; // (string) Google accounts "from" reply-to address // Chat // added by Neerav; 10 Feb 2006 // (string) Google accounts "from" reply-to address // Chat // added by Neerav; 10 Feb 2006 case "ix_ca": $chat["save_chat"] = $value; $other["save_chat"] = $value; break; // (boolean) save chat archive {0 = off, 1 = on} // added by Neerav; 26 Feb 2006 // (boolean) save chat archive {0 = off, 1 = on} // added by Neerav; 26 Feb 2006 case "ix_ql": $chat["ix_ql"] = $value; break; // (integer) // (integer) case "bx_aa": $chat["bx_aa"] = $value; break; // (boolean) // (boolean) case "bx_lq": $chat["bx_lq"] = $value; break; // (boolean) // MOBILE // added by Neerav; 20 Dec 2005 // (boolean) // MOBILE // added by Neerav; 20 Dec 2005 case "sx_pf": if ($value != "") { $mobile = array(); $temp_mobile = explode('#,~', $value); for ($mob = 0; $mob < count($temp_mobile); $mob++) { if ($temp_mobile[$mob] != "") { $mobile['display_boxes'][] = $temp_mobile[$mob]; } } } break; // OTHER // not used yet or has been removed from Gmail // OTHER // not used yet or has been removed from Gmail case "bx_cm": $other["rich_text"] = $value; break; // (boolean) rich text composition {0 = plain text, 1 = rich text} // added by Neerav; 20 Dec 2005 //case "bx_aa": $other["unknown"] = $value; break; // // (boolean) rich text composition {0 = plain text, 1 = rich text} // added by Neerav; 20 Dec 2005 //case "bx_aa": $other["unknown"] = $value; break; // default: $other["{$pref}"] = $value; break; } } // set useful implicit boolean settings //if ($gen["name_display"] != "") $gen["use_cust_name"] = 1; //if ($gen["reply_to"] != "") $gen["use_reply_to"] = 1; if ($gen["signature"] != "") { $gen["use_signature"] = 1; } if ($fpop["forward_to"] != "") { $fpop["forward"] = 1; } $this->setting_gen = $gen; $this->setting_fpop = $fpop; $this->setting_other = $other; $this->setting_mobile = $mobile; $this->setting_chat = $chat; } // LABELS $this->label_list = array(); $this->label_total = array(); if (isset($raw["cta"][1])) { foreach ($raw["cta"][1] as $v) { array_push($this->label_list, $v[0]); array_push($this->label_total, $v[1]); } } elseif (isset($raw["cta"])) { Debugger::say('cta[1] not set, printing cta: ' . print_r($raw["cta"], true)); } // FILTERS $this->filter = array(); if (isset($raw["fi"][1])) { foreach ($raw["fi"][1] as $fi) { // Changed/Added by Neerav; 23 Jun 2005 // filter rules/settings // (The "() ? :" notation is used because empty/false fields at the end of an // array are not always defined) $b = array("id" => $fi[0], "query" => isset($fi[1]) ? $fi[1] : "", "from" => isset($fi[2][0]) ? $fi[2][0] : "", "to" => isset($fi[2][1]) ? $fi[2][1] : "", "subject" => isset($fi[2][2]) ? $fi[2][2] : "", "has" => isset($fi[2][3]) ? $fi[2][3] : "", "hasnot" => isset($fi[2][4]) ? $fi[2][4] : "", "hasattach" => (isset($fi[2][5]) and ($fi[2][5] == "true" or $fi[2][5] === true)) ? true : false, "archive" => (isset($fi[2][6]) and ($fi[2][6] == "true" or $fi[2][6] === true)) ? true : false, "star" => (isset($fi[2][7]) and ($fi[2][7] == "true" or $fi[2][7] === true)) ? true : false, "label" => (isset($fi[2][8]) and ($fi[2][8] == "true" or $fi[2][8] === true)) ? true : false, "label_name" => isset($fi[2][9]) ? $fi[2][9] : "", "forward" => (isset($fi[2][10]) and ($fi[2][10] == "true" or $fi[2][10] === true)) ? true : false, "forwardto" => isset($fi[2][11]) ? $fi[2][11] : "", "trash" => (isset($fi[2][12]) and ($fi[2][12] == "true" or $fi[2][12] === true)) ? true : false); array_push($this->filter, $b); } } $this->view = GM_PREFERENCE; } /* else { */ /* $this->created = 0; */ /* $this->snapshot_error = "libgmailer: no snapshot type specified"; // Added by Neerav; 3 Aug 2005 */ /* return null; */ /* } */ $this->created = 1; return 1; }
/** * Constructor. * * Note: you are not supposed to create a GMailSnapshot object yourself. You should * use {@link GMailer::getSnapshot()} and/or {@link GMailer::webClip()} instead. * * @return GMailWebclipSnapshot * @param array $raw */ function web_clip_snapshot($raw, $action = "item") { $clips = array(); if ($action == 'preview') { $this->feed['id'] = $raw['fl'][2][0][0]; $this->feed['url'] = $raw['fl'][2][0][1]; $this->feed['site'] = $raw['fl'][2][0][2]; // must be last! if (isset($raw['fl'][2][0][6])) { $raw = $raw['fl'][2][0][6]; } } foreach ($raw as $webclip) { if (count($webclip) == 10) { $ad_site = 4; $ad_date = 5; $ad_sub = 6; $ad_type = 8; $ad_cat = 9; } elseif (count($webclip) == 6) { $ad_site = 0; // not really, but will be blank $ad_date = 0; // not really, but will be blank $ad_sub = 0; // not really, but will be blank $ad_type = 4; $ad_cat = 5; } elseif (count($webclip) == 7) { $ad_site = 4; $ad_date = 0; // not really, but will be blank $ad_sub = 0; // not really, but will be blank $ad_type = 5; $ad_cat = 6; } else { Debugger::say(basename(__FILE__) . ": " . __LINE__ . ": " . "odd web clips: " . print_r($webclip, true)); continue; } $clip = array(); //$clip[''] = $webclip[0]; // ?? $clip['id'] = $webclip[1]; $clip['url'] = $webclip[2]; $clip['title'] = $webclip[3]; $clip['site'] = $ad_site != 0 ? $webclip[$ad_site] : ""; $clip['date'] = $ad_date != 0 ? $webclip[$ad_date] : ""; $clip['sub'] = $ad_sub != 0 ? $webclip[$ad_sub] : ""; //$clip[''] = (($less) ? "" : $webclip[7]); // ?? empty $clip['type'] = $webclip[$ad_type]; // web clip, advertisement, gmail tip, etc. $clip['category'] = $webclip[$ad_cat]; // a number // 1 = Gmail Tip, 2 = News, 3 = Business, 4 = Lifestyle // 5 = Fun, 6 = Tech, 7 = Sports, 8 = custom $clips[] = $clip; } if ($action == 'preview') { $this->feed['web_clips'] = $clips; } else { $this->web_clips = $clips; } return 1; }