Размер файла: 6.99Kb
<?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)
*************************************************************/
require_once("libgmailer.php");
require_once("config.php");
$ALLOW_ATTACHMENT = 0;
$gm = new GMailer();
if (!$gm->created) {
die("fail to create gmailer");
}
$gm->setSessionMethod($config_session);
if (!$gm->connect()) {
header("Location: index.php?err=10");
exit;
}
$to = isset($_REQUEST["to"])?$_REQUEST["to"]:"";
$subj = isset($_REQUEST["subj"])?$_REQUEST["subj"]:"";
$mailcc = isset($_REQUEST["mailcc"])?$_REQUEST["mailcc"]:"";
$bcc = isset($_REQUEST["bcc"])?$_REQUEST["bcc"]:"";
$body = isset($_REQUEST["body"])?$_REQUEST["body"]:"";
$back = isset($_REQUEST["back"])?$_REQUEST["back"]:"";
$th = isset($_REQUEST["th"])?$_REQUEST["th"]:"";
$mg = isset($_REQUEST["mg"])?$_REQUEST["mg"]:"";
// address book related
$list = isset($_REQUEST["list"])?$_REQUEST["list"]:array();
$list_to = isset($_REQUEST["list_to"])?$_REQUEST["list_to"]:"";
$discard = isset($_REQUEST["discard"])?$_REQUEST["discard"]:"";
// attachment uploaded
$filename = isset($_FILES['attach']['name'])? $_FILES['attach']['name'] : 0;
$filesize = isset($_FILES['attach']['size'])? $_FILES['attach']['size'] : -1;
$filetype = isset($_FILES['attach']['type'])? $_FILES['attach']['type'] : 0;
$filetmp = isset($_FILES['attach']['tmp_name'])? $_FILES['attach']['tmp_name'] : 0;
if ($discard == "discard") {
header("Location: ".$back);
exit;
}
if ($list_to) {
switch ($list_to) {
case "to":
$to = array_merge($to, $list);
break;
case "cc":
$cc = array_merge($cc, $list);
break;
case "bcc":
$bcc = array_merge($bcc, $list);
break;
default:
}
if ($list_to == "contacts(all)" || $list_to == "contacts(freq)") {
$gm->fetchContact();
$ss = $gm->getSnapshot(GM_CONTACT);
$list_html = "<br><select name='list[]' size='5' multiple>";
if ($list_to == "contacts(freq)") {
foreach ($ss->contacts_freq as $v) {
$list_html .= "<option value='".$v["email"]."'>".$v["name"]." (".$v["email"].")</option>";
}
$list_html .= "</select><br>";
$list_html .= "<input type='submit' name='list_to' value='to'> <input type='submit' name='list_to' value='cc'> <input type='submit' name='list_to' value='bcc'> ";
$list_html .= "<input type='submit' name='list_to' value='contacts(all)'>";
} else {
foreach ($ss->contacts as $v) {
$list_html .= "<option value='".$v["email"]."'>".$v["name"]." (".$v["email"].")</option>";
}
$list_html .= "</select><br>";
$list_html .= "<input type='submit' name='list_to' value='to'> <input type='submit' name='list_to' value='cc'> <input type='submit' name='list_to' value='bcc'> ";
$list_html .= "<input type='submit' name='list_to' value='contacts(freq)'>";
}
} else {
$list_html = "<input type='submit' name='list_to' value='contacts(freq)'> <input type='submit' name='list_to' value='contacts(all)'>";
}
} else {
$list_html = "<input type='submit' name='list_to' value='contacts(freq)'> <input type='submit' name='list_to' value='contacts(all)'>";
if (strlen($to) > 0) {
// enough to send mail
// file attachment
if ($filename && $filetmp && $filesize > 0 && $filesize < 5000000 && $ALLOW_ATTACHMENT) {
if (move_uploaded_file($filetmp, realpath("./tmp")."/".$filename)) {
$fname = array("./tmp/".$filename);
} else {
$fname = 0;
}
} else {
$fname = 0;
}
$gm->send($to, $subj, $body, $cc, $bcc, $mg, $th, $fname);
if ($fname)
unlink($fname[0]);
header("Location: main.php?sum=1");
} elseif ($th || $mg) {
// replying mail
$gm->fetchBox(GM_CONVERSATION, array($th,$mg), 0);
$ss = $gm->getSnapshot(GM_CONVERSATION);
$tos = strlen($ss->conv[0]["reply_email"])==0?$ss->conv[0]["sender_email"]:$ss->conv[0]["reply_email"];
$to = htmlspecialchars($tos);
$mailcc = htmlspecialchars($ss->conv[0]["recv_email"]);
$subj = (strpos($ss->conv[0]["subj"],"Re:")==false) ? "Re: ".$ss->conv[0]["subj"] : $ss->conv[0]["subj"]; // to avoid "Re: Re:" in mail subject
$subj = htmlspecialchars($subj);
//$body = "\r\n\r\n\r\n>".strip_tags(str_replace("<br>", "\r\n>", $ss->conv[0]["body"]));
} else {
$err = "You have to provide, at least, receiver's address.";
}
}
@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>
<card id="c1" title="compose">
<p>
<do type="options" label="CANCL"><go href="#d2" /></do>
To:<input name="to" value="<? echo $to ?>" format="*m" emptyok="true"/><br/>
Cc:<input name="mailcc" value="<? echo $mailcc ?>" format="*m" emptyok="true"/><br/>
Subj:<input name="subj" value="<? echo $subj ?>" format="*m" emptyok="true"/><br/>
Msg:<input name="body" value="<? echo $body ?>" format="*m" emptyok="true"/>
<br/>
<anchor title="Send">
<go href="compose.php" method="post">
<postfield name="subj" value="$(subj)" />
<postfield name="body" value="$(body)" />
<postfield name="to" value="$(to)" />
<postfield name="mailcc" value="$(mailcc)" />
<postfield name="back" value="main.php"/>
<postfield name="th" value="<? echo $th ?>"/>
<postfield name="mg" value="<? echo $mg ?>"/>
</go>
Send
</anchor>
<br/>
<a href="#d2">Cancel</a><br/>
</p>
</card>
<card id="d2" title="gmail-mobile">
<do type="accept" label="No"><go href="#c1" /></do>
<p>Are you sure you want to cancel this message?</p>
<p align="center"><a href="#c1">No</a> ||| <a href='main.php'>Yes</a></p>
</card>
</wml>