require_once("config.html");
$JS_Status = get_js_status();
$RTF_Edit = get_rte_status();
$is_html = $RTF_Edit; // added by Neerav; 25 April 2006 - Modified by PENorwood; 16 May 2006
$mailbox_name = isset($_REQUEST["mbox"]) ? $_REQUEST["mbox"] : ""; // added by Neerav; 27 Mar 2006
$from = isset($_REQUEST["from"]) ? $_REQUEST["from"] : "";
$to = isset($_REQUEST["to"]) ? $_REQUEST["to"] : array();
$subj = isset($_REQUEST["subj"]) ? $_REQUEST["subj"] : "";
$cc = isset($_REQUEST["cc"]) ? $_REQUEST["cc"] : array();
$bcc = isset($_REQUEST["bcc"]) ? $_REQUEST["bcc"] : array();
$body = isset($_REQUEST["body"]) ? $_REQUEST["body"] : "";
$back = (isset($_REQUEST["back"]))? preg_replace("/(%26|%26amp%3B|&|&)status.*/","",$_REQUEST["back"]) : 0;
$th = isset($_REQUEST["th"]) ? $_REQUEST["th"] : "";
$mg = isset($_REQUEST["mg"]) ? $_REQUEST["mg"] : "";
$df = isset($_REQUEST["df"]) ? $_REQUEST["df"] : 0;
$orig_df = isset($_REQUEST["orig_df"]) ? $_REQUEST["orig_df"] : "";
/* $draft_attach = isset($_REQUEST["draft_attach"]) ? $_REQUEST["draft_attach"] : ""; */
$reply_all = isset($_REQUEST["reall"]) ? $_REQUEST["reall"] : 0; // added by Neerav; 4 May 2006
$attachments = isset($_REQUEST["attach"]) ? $_REQUEST["attach"] : array(); // added by Neerav; 25 April 2006
$forward = isset($_REQUEST["forward"]) ? $_REQUEST["forward"] : 0; // added by Neerav; 25 April 2006
$all_attach = isset($_REQUEST["all_attach"]) ? $_REQUEST["all_attach"] : "YTowOnt9"; // added by Neerav; 27 April 2006
// "YTowOnt9" is a serialized, base64 encoded empty array
$status = isset($_REQUEST["status"]) ? $_REQUEST["status"] : ""; // added by Neerav; 29 April 2006
// address book related
$list = isset($_REQUEST["list"]) ? $_REQUEST["list"] : array();
$list_to = isset($_REQUEST["list_to"]) ? $_REQUEST["list_to"] : "";
// action to be done
$send = isset($_REQUEST["send"]) ? $_REQUEST["send"] : "";
$discard = isset($_REQUEST["discard"]) ? $_REQUEST["discard"] : "";
$save = isset($_REQUEST["save"]) ? $_REQUEST["save"] : "";
// 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;
$err = "";
// use mailto links to preadress a new message; Added by Neerav; 25 Aug 2006
if (isset($_REQUEST["mailto"]) and trim($_REQUEST["mailto"]) !== "") $to = array($_REQUEST["mailto"]);
if ($discard == "discard change") {
header("Location: ".urldecode($back));
exit;
}
$gm = new GMailer();
if (!$gm->created)
die("Failed to create GMailer.");
quick_init($gm);
// support for hosted domains; Added by Neerav; 9 June 2006
$domain = get_domain();
if ($domain !== "") $gm->setDomain($domain);
if (!$gm->connect()) {
$err = "You are not signed in. Copy your message from below and signin again.";
} else {
// ADDRESS BOOK / ADD TO RECIPIENT FIELDS
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)") {
if ($list_to == "contacts(all)")
$gm->fetchBox(GM_CONTACT, "all", 0);
else
$gm->fetchBox(GM_CONTACT, "freq", 0);
$ss = $gm->getSnapshot(GM_CONTACT);
$list_html = " "; $list_html .= " "; if ($list_to == "contacts(all)") $list_html .= ""; else $list_html .= ""; } else { $list_html = " "; } } else { $list_html = " "; /* print_r($_REQUEST); */ if ($send == "send" or $save == "save") { // enough to send mail $tos = (is_array($to)) ? implode(", ", $to) : $to; $ccs = (is_array($cc)) ? implode(", ", $cc) : $cc; $bccs = (is_array($bcc)) ? implode(", ", $bcc) : $bcc; if ($from == -1) { if (($session_method & GM_USE_PHPSESSION) and isset($_SESSION['gmail_address'])) { $from = $_SESSION['gmail_address']; } elseif (isset($_COOKIE['gmail-lite_email'])) { $from = base64_decode($_COOKIE['gmail-lite_email']); } else { $from = ""; } } // file attachment, uploaded if (C_ATTACHMENT && $filename && $filetmp && $filesize > 0 && $filesize < (C_ATTACHMENT_LIMIT*1024)) { if (move_uploaded_file($filetmp, realpath("./tmp")."/".$filename)) { $fname = array("./tmp/".$filename); } else { $fname = 0; } } else { $fname = 0; } $exist_attach = array(); // file attachment, existing if ($all_attach != "YTowOnt9") { $all_attach_unser = unserialize(base64_decode($all_attach)); $count_attach = count($all_attach_unser); for ($i = 0 ; $i < $count_attach; $i++) { if ((is_array($attachments) and in_array($i,$attachments)) or $i == $attachments) { $exist_attach[] = "0_".$mg."_".$all_attach_unser[$i]['id']; } } } if ($save == "save") { // save draft $save_draft = true; } else { // send message $save_draft = false; } // preparation for html messages and forwards; Neerav; 25 April 2006 $status = $gm->send($tos, $subj, $body, $ccs, $bccs, $mg, $th, $fname, $save_draft, $orig_df, $is_html, $from, $exist_attach); $status_message = $gm->lastActionStatus('message'); $threadid = $gm->lastActionStatus('thread_id'); /* $num_recipients = $gm->lastActionStatus('sent_num'); */ // delete uploaded attachment if ($fname) @unlink($fname[0]); // Display status information; by Neerav; 29 April 2006 if ($status) { header("Location: main.php?th=".$threadid."&status=".rawurlencode($status_message)); exit(); } else { $status = $status_message; } } elseif ($th || $mg) { // replying/forwarding mail if ($df == 0) { // reply or new message (not resuming a draft) $gm->fetchBox(GM_CONVERSATION, array($th,$mg), "$mailbox_name"); $ss = $gm->getSnapshot(GM_CONVERSATION); //debug_print("dumping message: ".print_r($ss,true)); // remove fwd:'s and re:'s from subject; Neerav; 27 Mar 2006 $subj = trim(preg_replace('/^\s*((fwd:|fw:|re:)\s*)+/is', '', $ss->conv[0]["subj"])); if ($forward) { $err = "Forwarding text and attachments WORKING. Forwarding html DOES NOT WORK yet."; $to = array(); $cc = array(); $bcc = array(); // now add Fwd:; Neerav; 25 April 2006 $subj = "Fwd: ".$subj; // include the original message; from gmail-mobile code; Neerav; 25 April 2006 $newline = "\r\n"; $orig_text = ""; //$orig_text .= $newline.$newline; $orig_text .= "---------- Forwarded message ----------".$newline; // from $orig_text .= "From: ".$ss->conv[0]['sender']." <".$ss->conv[0]['sender_email'].">".$newline; // date $orig_text .= "Date: ".$ss->conv[0]['dt'].$newline; // subject $orig_text .= "Subject: ".$ss->conv[0]['subj'].$newline; // to if (count($ss->conv[0]['recv_email']) > 0) { if (count($ss->conv[0]['recv_email']) == 1) { $orig_text .= "To: ".$ss->conv[0]['recv_email'][0].$newline; } else { // more than one recipient, flatten the array $temp_to = ""; $count_recv_email = count($ss->conv[0]['recv_email']); for ($i=0; $i < $count_recv_email; $i++) { $temp_to .= ($temp_to == "") ? $ss->conv[0]['recv_email'][$i] : ", ".$ss->conv[0]['recv_email'][$i] ; } $orig_text .= "To: ".$temp_to.$newline; } } else { $orig_text .= "unnamed recipients ".$newline; } $orig_text .= $newline; // now add the actual text if ($RTF_Edit) { /* $body = $ss->conv[0]["body"]; */ $body = str_replace("$newline"," ",$orig_text) .preg_replace( array( // remove "show quoted text" "/]*>-\s*Show\s*quoted\s*text\s*-<\/span>/im" ,"/ /im" ), array( '' ,' ' ), $ss->conv[0]["body"] ); } else { $body = $newline.$newline.$orig_text .strip_tags( str_replace( /* array(" \n"," "," ","- Show quoted text -"), */ /* array("\r\n","\r\n","\r\n","\r\n","\r\n","\r\n","\r\n",""), */ array(" "," \n",/* " "," "," ","- Show quoted text -"), array("\r\n","\r\n",/* "\r\n","\r\n","\r\n","\r\n", */"\r\n","\r\n","\r\n",""), $ss->conv[0]["body"] ) ," " ); } $all_attachments = $ss->conv[0]["attachment"]; $all_attach = base64_encode(serialize($all_attachments)); $count_attach = count($all_attachments); for ($i = 0; $i < $count_attach; $i++) { $attachments[] = $i; } } else { $to = (count($ss->conv[0]["reply_email"])==0) ? array($ss->conv[0]["sender_email"]) : $ss->conv[0]["reply_email"] ; if ($reply_all) { $count_to = count($ss->conv[0]["recv_email"]); $count_cc = count($ss->conv[0]["cc_email"]); $total_received = $count_to + $count_cc; // remove the user's address from the cc ; Added by Neerav; April 2006 if ($total_received > 0 and $ss->conv[0]["to_custom_from"] != "") { for ($cf = 0; $cf < $count_to; $cf++) { if (strpos($ss->conv[0]["recv_email"][$cf],$ss->conv[0]["to_custom_from"]) === false) { $cc[] = $ss->conv[0]["recv_email"][$cf]; } } // Include the cc field in "reply to all"; Added by Neerav; 5 May 2006 for ($cf = 0; $cf < $count_cc; $cf++) { if (strpos($ss->conv[0]["cc_email"][$cf],$ss->conv[0]["to_custom_from"]) === false) { $cc[] = $ss->conv[0]["cc_email"][$cf]; } } } else { $cc = array_merge($ss->conv[0]["recv_email"], $ss->conv[0]["cc_email"]); } } else { $cc = array(); } // now add Re:; Neerav;Neerav; 27 Mar 2006 $subj = "Re: ".$subj; //fixed by PENorwood 12 May 2005 //changed $body to $ss->conv[0]["body"] // clean up the body text; by Neerav; 17 May 2006 if ($RTF_Edit) { /* $body = $ss->conv[0]["body"]; */ $body = preg_replace( array( // remove "show quoted text" "/]*>-\s*Show\s*quoted\s*text\s*-<\/span>/im" // removes Gmail's linking //,"/]*?".">/im" //,'/ (.*?) /im' ), array( '' // replace with simple link //,'' //,' \\1' ), $ss->conv[0]["body"] ); } else { /* debug_print("compose message body: ".print_r($ss->conv[0]["body"],true)); */ // replace div with > to display text better; by Neerav; 5 May 2006 $body = str_replace(" "," > ",$ss->conv[0]["body"]);
$body = strip_tags(str_replace(
array(" "," \n",/* " "," "," ","- Show quoted text -"), array("\r\n> ","\r\n> ",/* "\r\n> ","\r\n> ","\r\n> ","\r\n> ", */"\r\n> ","\r\n> ","\r\n> ",""), $body )," " ); } if ($RTF_Edit == 1) { /* $body = " ".$ss->conv[0]["quote_str"]." ".$body.""; */ $body = " ".$ss->conv[0]["quote_str"]." ".$body.""; } else { /* $body = $ss->conv[0]["quote_str"]."\r\n\r\n> ".$body; */ $body = $ss->conv[0]["quote_str"]."\r\n".$body; } $all_attachments = array(); $all_attach = base64_encode(serialize($all_attachments)); $attachments = array(); } // Add signature on top or bottom; Neerav 18 April 2006 if (($session_method & GM_USE_PHPSESSION) and isset($_SESSION['signature'])) { $signature = $_SESSION['signature']; } elseif (isset($_COOKIE['gmail-lite_sign'])) { $signature = base64_decode($_COOKIE['gmail-lite_sign']); } else { $signature = ""; } if ($RTF_Edit) $rtf_signature = str_replace("\r\n"," ",$signature); if (C_SIGNATURE_ON_TOP) { if ($forward) { if ($RTF_Edit == 1) { $body = " ".$rtf_signature." ".$body; } else { $body = $signature ."\r\n".$body; } } else { if ($RTF_Edit == 1) { $body = "".$rtf_signature." ".$body; } else { $body = $signature ."\r\n\r\n\r\n".$body; } } } else { if ($RTF_Edit == 1) { $body .= "".$rtf_signature." "; } else { $body .= $signature ; } } } else { // resuming a draft $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 && $ss->conv[$i]["id"] == $mg) { $the_draft = $ss->conv[$i]; } } $to = $the_draft["recv_email"]; $cc = $the_draft["cc_email"]; $bcc = $the_draft["bcc_email"]; $subj = $the_draft["subj"]; $body = $the_draft["body"]; $orig_df = $the_draft["id"]; $all_attachments = $the_draft["attachment"]; $all_attach = base64_encode(serialize($all_attachments)); $count_attach = count($all_attachments); for ($i = 0; $i < $count_attach; $i++) { $attachments[] = $i; } } } else { /* $err = "You have to provide, at least, receiver's address."; */ } if ($body == "") { if (($session_method & GM_USE_PHPSESSION) and isset($_SESSION['signature'])) { $body = $_SESSION['signature']; } elseif (isset($_COOKIE['gmail-lite_sign'])) { $body = base64_decode($_COOKIE['gmail-lite_sign']); } if ($RTF_Edit) $body = str_replace("\r\n"," ",$body)." "; } } if (!isset($ss->personality)) { $gm->fetchBox(GM_QUERY, "whateverjusttofetchsendmailpersonality", 0); $ss = $gm->getSnapshot(GM_QUERY); } /* debug_print(print_r($gm,true)); */ /* print_r($ss); */ $from_list = ""; $custom_from = false; if (isset($ss->conv[0]["to_custom_from"]) and $ss->conv[0]["to_custom_from"] != "") { $person_count = count($ss->personality); for ($ii = 0; $ii < $person_count; $ii++) { $from_list .= ""; } } else { if (isset($ss->personality)) { $person_count = count($ss->personality); for ($ii = 0; $ii < $person_count; $ii++) { $from_list .= ""; } } } $from_list = "".$from_list; } // from_list would be undefined in case of session time out; Added by Neerav; 29 April 2006 if (!isset($from_list) or $from_list == "") { $from_list = ""; } print_headers(); ?>
|