<?php
/****************************************************************
Copyright (c) 2004 GAN Ying Hung <[email protected]>, Rudi Pittman <[email protected]>, Gaston Annebicque <[email protected]>
Licensed under the GNU GPL. For full terms see the file COPYING.
gmail-mobile is a program to allow any wap enabled phone to read, compose
and reply to email using the free email service provided by Google
called GMAIL (http://gmail.google.com)
******************************************************************/
function uniord($c) {
$ud = 0;
if (ord($c{0})>=0 && ord($c{0})<=127)
$ud = ord($c{0});
if (ord($c{0})>=192 && ord($c{0})<=223)
$ud = (ord($c{0})-192)*64 + (ord($c{1})-128);
if (ord($c{0})>=224 && ord($c{0})<=239)
$ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
if (ord($c{0})>=240 && ord($c{0})<=247)
$ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
if (ord($c{0})>=248 && ord($c{0})<=251)
$ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
if (ord($c{0})>=252 && ord($c{0})<=253)
$ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
if (ord($c{0})>=254 && ord($c{0})<=255) //error
$ud = 0;
return $ud;
}
function wml_safe($str) {
$str = str_replace(array("<br>","<Br>","<bR>","<BR>"),"[GM br]", $str);
$str = html_entity_decode($str);
$nstr = "";
for ($i = 0; $i < strlen($str); $i++) {
$nstr .= "&#".uniord($str{$i}.$str{$i+1}).";";
}
$nstr = str_replace("[GM br]", "<br/>", $nstr);
return $nstr;
}
require_once("libgmailer.php");
require_once("config.php");
$login = (isset($_REQUEST["login"]))? $_REQUEST["login"]: 0;
$pass = (isset($_REQUEST["pass"]))? $_REQUEST["pass"]: 0;
$tz = (isset($_REQUEST["tz"]))? 0+$_REQUEST["tz"] : 8; // default is +8:00 for HK
$gm = new GMailer();
if (!$gm->created) {
die("fail to create gmailer");
}
$gm->setSessionMethod($config_session);
$gm->setLoginInfo($login, $pass, $tz);
if (!$gm->connect()) {
header("Location: index.php?err=10");
exit;
}
$th = (isset($_REQUEST["th"]))? $_REQUEST["th"] : 0;
$mg = (isset($_REQUEST["mg"]))? $_REQUEST["mg"] : 0;
$std = (isset($_REQUEST["std"]))? $_REQUEST["std"] : 0;
$label = (isset($_REQUEST["label"]))? $_REQUEST["label"] : 0;
$query = stripslashes((isset($_REQUEST["query"]))? $_REQUEST["query"] : 0);
$sum = (isset($_REQUEST["sum"]))? $_REQUEST["sum"] : 0;
$unread = (isset($_REQUEST["unread"]))? $_REQUEST["unread"] : 0;
$pos = (isset($_REQUEST["pos"]))? $_REQUEST["pos"] : 0;
$orig = (isset($_REQUEST["orig"]))? $_REQUEST["orig"] : 0;
// perform action?
$act = isset($_REQUEST["act"])? $_REQUEST["act"] : 0;
$lbl = isset($_REQUEST["lbl"])? $_REQUEST["lbl"] : 0;
$back = isset($_REQUEST["back"])? $_REQUEST["back"] : 0;
$t = isset($_REQUEST["t"])? $_REQUEST["t"] : array();
if ($act && count($t) > 0 && $back) {
$gm->performAction($act, $t, $lbl);
header("Location: ".$back);
exit(); // redirect right away
}
if ($sum) {
$q = "search=cat&cat=dummyjusttoretrievesummary&view=tl&start=0&init=1";
$tit = "summary";
} elseif ($orig && $mg) {
$q = "view=om&th=".$mg;
// dump the whole page... with some escaping
header("Content-type: text/plain; charset=big5");
echo $gm->dump($q);
exit();
} else {
if ($unread) {
$q = "search=query&q=is%3Aunread&view=tl&start=".$pos;
$tit = "unread";
} else {
if ($th) {
$tit = "conversation";
if ($mg)
$q = "search=inbox&view=cv&th=".$th."&msgs=".$mg;
else
$q = "search=inbox&view=cv&th=".$th;
} else {
if ($query) {
$q = "search=query&q=".urlencode($query)."&view=tl&start=".$pos;
$tit = "search";
} elseif ($label) {
$q = "search=cat&cat=".$label."&view=tl&start=".$pos;
$tit = $label;
} else {
if ($std)
$q = "search=".$std."&view=tl&start=".$pos;
else {
$q = "search=inbox&view=tl&start=0&init=1";
$std = "inbox";
}
$tit = $std;
}
}
}
}
$gm->fetch($q);
$snapshot = $gm->getSnapshot(GM_STANDARD|GM_LABEL|GM_QUERY|GM_CONVERSATION);
$stdbox = GMailer::getStandardBox();
@header("Content-type: text/vnd.wap.wml; charset=utf-8");
echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<template><do type="prev" label="BACK"><prev/></do></template>
<?
if (!$sum) {
if(!$th) {
/*** mailbox view ***/
echo "<card title='".$tit."'>";
echo "<p align='left'>";
for ($i = 0; $i < count($snapshot->box) && $i<5; $i++) {
if ($snapshot->box[$i]["is_starred"] == 1)
echo "<img src='star.gif' alt='*'/> ";
echo "<a href='main.php?th=".$snapshot->box[$i]["id"]."'>";
$mycontent=str_replace(array("<b>","</b>"),array("*",""),$snapshot->box[$i]["subj"]); //remove the <b> that gmail put on new mail
echo $mycontent."</a>";
echo "<br/>";
}
echo "</p><p>";
if ($pos >= 5) {
$p = $pos-5;
echo "<a href='main.php?query=".urlencode($query)."&std=".$std."&label=".$label."&unread=".$unread."&pos=".$p."'>Prv</a> | ";
}
if ($pos < $snapshot->box_total-5) {
$p = $pos+5;
echo "<a href='main.php?query=".urlencode($query)."&std=$std&label=$label&unread=$unread&pos=".$p."'>Nxt</a>";
}
echo "</p>";
echo "<p align='right'>";
echo "<a href='compose.php'>Compose</a><br/>";
echo "<a href='main.php?sum=1'>Summary</a><br/>";
echo "<a href='logout.php'>Logout</a>";
echo "</p>";
echo "</card>";
} else {
/*** conversation mode ***/
echo "<card title='conversation'>";
echo "<p align='left'>Subj: ".htmlspecialchars($snapshot->conv_title)."</p>";
$mycontent = "";
foreach ($snapshot->conv as $mg) {
if (strlen($mg["body"]) == 0) {
// if the body equals 0, we are on a snippet of a previous mail of the conversation, it will be displayed on a dedicated card
$mycontent = "<p>- <a href='main.php?th=".$snapshot->conv_id."&mg=".$mg["id"]."'>".htmlspecialchars(strip_tags($mg["snippet"]))."</a></p>".$mycontent; // the last message is in first place
} else {
echo "<p align='left'>From: ".htmlspecialchars($mg["sender"]."(".str_replace(array("¼","½","¾"),array("-1/4","-1/2","-3/4"),$mg["dt_easy"])).")</p>";//we convert the special characters that google uses to display the time
echo "<p>--------------------</p>";
$body = str_replace(array("<br>"," ","- Show quoted text -"),array("<br/>"," ",""),strip_tags($mg["body"],"<br>"));
if (strlen($body) > 2500) {
echo "<p>".substr($body,0,2500)."(tuncated by gmail-mobile)</p>"; // tuncated to compatible with some WAP phones
} else {
echo "<p>".$body."</p>";
}
echo "<p align='right'><a href='compose.php?th=".$snapshot->conv_id."&mg=".$mg["id"]."&back=".urlencode($_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'])."'>reply</a>";
if (strlen($mycontent) != 0)
echo "<br/><a href='#conv'>old msg</a>";//we display the link to the next card only if there are anything to link to
echo "</p>";
}
}
echo "</card>";
if ($mycontent != "") {//we create the additional card only if there is any other information
echo "<card title='old message' id='conv'>";
echo $mycontent;
echo "</card>";
}
}
} else {
echo "<card title='".$tit."' id='std'>";
echo "<p align='center'>";
for ($i = 0; $i < count($stdbox); $i++) {
echo "<a href='main.php?std=".strtolower($stdbox[$i])."'>".$stdbox[$i]." (".$snapshot->std_box_new[$i].")</a>";
echo "<br />";
}
echo "</p>";
echo "<p align='right'>";
echo "<a href='compose.php'>Compose</a><br/>";
echo "<a href='#label'>Labels</a><br/>";
echo "<a href='logout.php'>Logout</a>";
echo "</p></card>";
echo "<card title='".$tit."' id='label'>";
echo "<p align='center'>";
for ($i = 0; $i < count($snapshot->label_list); $i++) {
echo "<a href='main.php?label=".$snapshot->label_list[$i]."'>".$snapshot->label_list[$i]." (".$snapshot->label_new[$i].")</a>";
echo "<br />";
}
echo "</p>";
echo "<p align='right'>";
echo "<a href='compose.php'>Compose</a><br/>";
echo "<a href='#std'>Standard</a><br/>";
echo "<a href='logout.php'>Logout</a>";
echo "</p></card>";
}
?>
</wml>