<?php
require_once("config.php");
$login = (isset($_REQUEST["login"]))? $_REQUEST["login"]: "";
$pass = (isset($_REQUEST["pass"]))? $_REQUEST["pass"]: "";
$tz = (isset($_REQUEST["tz"]))? 0+$_REQUEST["tz"] : 8;
$tz2 = (isset($_REQUEST["tz2"]))? 0+$_REQUEST["tz2"] : 0;
if (!(strlen($login) == 0 || strlen($pass) == 0)) {
setcookie("TZ", $tz);
setcookie("TZ2",$tz2);
}
$gm = new GMailer();
if (!$gm->created) {
die("fail to create gmailer");
}
quick_init($gm);
$tz = $tz + $tz2;
$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;
$html = (isset($_REQUEST["html"]))? $_REQUEST["html"] : 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 (!$std)
$std = "inbox";
if ($mg)
$q = "search=".$std."&view=cv&th=".$th."&msgs=".$mg;
else
$q = "search=".$std."&view=cv&th=".$th;
if ($html)
$q .= "&ser=1";
} else {
if ($query) {
$q = "search=query&q=".urlencode($query)."&view=tl&start=".$pos;
$tit = "search";
} elseif ($label) {
$q = "search=cat&cat=".urlencode($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);
if ($snapshot->created == 0) {
header("Location: main.php?std=".$std."&label=".$label."&".SID);
exit;
}
$stdbox = GMailer::getStandardBox();
header("Content-type: text/xml; charset=utf-8"); // must use text/xml for ajax/xmlhttp to work :(
header("Pragma: no-cache"); // stop caching
?>
<body>
<msgType>conv</msgType>
<?
// conversation view
// if ($snapshot->conv_starred)
// echo "<img src='star.gif' border='0' align='middle'>";
echo "<title>".cleanData($snapshot->conv_title)."</title>\n";
echo "<thread>".cleanData($th)."</thread>\n";
foreach ($snapshot->conv as $mg) {
echo "<msg>\n";
echo "<id>".cleanData($mg["id"])."</id>\n";
echo "<starred>".($mg["is_star"]==1?1:0)."</starred>\n";
echo "<date_easy>".cleanData($mg["dt_easy"])."</date_easy>\n";
echo "<sender>".cleanData($mg["sender"])."</sender>\n";
echo "<sender_email>".cleanData($mg["sender_email"])."</sender_email>\n";
//echo "<recv>".cleanData(join(",",$mg["recv"]))."</recv>\n";
echo "<recv_email>".cleanData(join(",",$mg["recv_email"]))."</recv_email>\n";
echo "<cc_email>".cleanData(join(",",$mg["cc_email"]))."</cc_email>\n";
echo "<reply_url>".cleanData("compose.php?th=".$snapshot->conv_id."&mg=".$mg["id"])."</reply_url>\n";
echo "<raw_url>".cleanData("main.php?orig=1&mg=".$mg["id"])."</raw_url>\n";
echo "<trash_url>".cleanData("main.php?act=15&t=".$mg["id"])."</trash_url>\n";
if (strlen($mg["body"]) == 0) {
// when not last msg, u get snippet instead of body from gmail
echo "<snippet>".cleanData($mg["snippet"])."</snippet>\n";
echo "<snippet_more_url>".cleanData("loadConv.php?th=".$snapshot->conv_id."&mg=".$mg["id"])."</snippet_more_url>\n";
echo "<attachment_count>".count($mg["attachment"])."</attachment_count>\n";
} else {
echo "<html_url>".cleanData("loadConv.php?th=".$snapshot->conv_id."&mg=".$mg["id"]."&html=1")."</html_url>\n";
$body = $mg["body"];
$body = cleanData( $body );
echo "<html_as_is>" . $body . "</html_as_is>\n";
for ($i = 0; $i < count($mg["attachment"]); $i++) {
echo "<attachment>" .
"<url>". cleanData("dl.php?a=".$mg["attachment"][$i]["id"]."&m=".$mg["id"]."&f=".urlencode($mg["attachment"][$i]["filename"]))."</url>".
"<filename>". cleanData($mg["attachment"][$i]["filename"]) . "</filename>".
"</attachment>\n";
}
if (count($mg["attachment"]) > 1) {
echo "<attachment_all_url>". cleanData("dl.php?a=dummy&m=".$mg["id"]."&f=dummy&z=1") . "</attachment_all_url>\n";
}
}// end of last msg
echo "</msg>\n";
}// end foreach
/* if ($mg["is_draft"] == true) {
echo "<td align='right'>[<a href='compose.php?df=1&th=".$snapshot->conv_id."&mg=".$mg["draft_parent"]."&back=".urlencode($_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'])."'>resume</a>";
echo "]</td></tr>";
echo "<tr><td colspan='2'><b>*** DRAFT ***</b><br>".nl2br($mg["body"])."</td></tr>";
} else {
*/
function cleanData($contents){
//$contents = strip_tags($contents);
$contents = ereg_replace("u003d", "=", $contents);
$contents = preg_replace_callback("/src=\"\/mail\/\?(.+?)\"/i", 'replcall_escape_img', $contents);
$contents = ereg_replace("]]>", "]]>", $contents);
return "<![CDATA[" . $contents . "]]>";
}
function replcall_escape_img($matches) {
return "src=\"gmlite/loadUrl.php?PHPSESSID=<phpsession>&url=" . urlencode( $matches[1] ) . "\"";
}
?>
</body>