<?
require_once("config.php");
// unique id - strange whole word w/o symbol (since gmail might delimit by symbol
$BOOT_ID = "WMCBOOTWMCBOTWMCBTWMC";
$body = isset($_REQUEST["body"])?$_REQUEST["body"]:"";
$boot = isset($_REQUEST["boot"])?$_REQUEST["boot"]:0;
$err = "";
$status = false;
$gm = new GMailer();
if (!$gm->created)
die("Failed to create GMailer.");
quick_init($gm);
header("Content-type: text/xml; charset=utf-8"); // must use text/xml for ajax/xmlhttp to work :(
header("Pragma: no-cache"); // stop caching
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
echo "<root>";
if ($gm->connect()) {
$q = "search=query&q=".urlencode($BOOT_ID)."&view=tl&start=0";
$gm->fetch($q);
$snapshot = $gm->getSnapshot(GM_STANDARD|GM_LABEL|GM_QUERY|GM_CONVERSATION);
if ($boot) {
// save
$th = $orig_df = 0;
if(count( $snapshot->box ) > 0){
$th = $orig_df = $snapshot->box[0]["id"];
}
$df = 1;
$mg = 0;
$status = $gm->send("", $BOOT_ID, $body, "", "", $mg, $th, 0, true, $orig_df, false, ""); // save draft only
if(!$status)
$err = $gm->lastActionStatus();
echo "<status>" . $status . "</status>";
echo "<error>" . $err . "</error>";
} else {
// load
$th = $snapshot->box[0]["id"];
$gm->fetchBox(GM_CONVERSATION, $th, 0);
$ss = $gm->getSnapshot(GM_CONVERSATION);
$the_draft = false;
for ($i = 0; $i < count($ss->conv) && $the_draft == false; $i++) {
if ($ss->conv[$i]["is_draft"] == true ) {
$the_draft = $ss->conv[$i];
}
}
$body = $the_draft["body"];
echo "<id>". cleanData($th) ."</id>";
echo "<body>". cleanData($body)."</body>";
}
} else {
echo "<error>You have to login first.</error>";
}
echo "</root>";
function cleanData($contents){
$contents = ereg_replace("]]>", "]]>", $contents);
return "<![CDATA[" . $contents . "]]>";
}
?>