<?
/*
* Hail is a PHP-Hotmail gateway. It will allow you to
* check your hotmail account via any webserver with PHP.
*
* Created by: Craig Marshall <hide@address.com> and
* Justin Carlson <hide@address.com>, 30-May-2003
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
// wmc lib
require_once("../wmcLib/clean.php");
require_once("../wmcLib/mime.php");
// hail lib
require_once("MailFolderItem.class.php");
require_once("MailFolder.class.php");
require_once("HTTPMail.class.php");
// pear mimeDecode
require_once 'Mail/mimeDecode.php';
// http://www.randomchaos.com/documents/?source=php_and_unicode
function utf8_to_unicode( $str ) {
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen( $str ); $i++ ) {
$thisValue = ord( $str[ $i ] );
if ( $thisValue < 128 ) $unicode[] = $thisValue;
else {
if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
$values[] = $thisValue;
if ( count( $values ) == $lookingFor ) {
$number = ( $lookingFor == 3 ) ?
( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
$unicode[] = $number;
$values = array();
$lookingFor = 1;
} // if
} // if
} // for
return $unicode;
} // utf8_to_unicode
// http://www.randomchaos.com/documents/?source=php_and_unicode
function unicode_to_entities( $unicode ) {
$entities = '';
foreach( $unicode as $value ) $entities .= '&#' . $value . ';';
return $entities;
} // unicode_to_entities
/*
{ "players" : [
{ "firstName" : "Ryan", "lastName" : "Campbell", "position" : "S" },
{ "firstName" : "Chris", "lastName" : "Campbell", "position" : "QB" },
{ "firstName" : "Kevin", "lastName" : "Hale", "position" : "DT" }
]}
*/
function print_folder_items($hm, $folder)
{
echo "{ 'JSON:ROOT' : [ \n";
# laikwan 3/5/2006: fix space in folder url
$folder = ereg_replace(" ", "%20", $folder);
$emails = array();
foreach(array_reverse( $hm->get_folder_items($folder) ) as $i)
{
$this_email = '';
$this_email .= "'url':'" . ($i->url) . "',";
$sender = ($folder=='sentitems' ? "To: " . $i->to : $i->from) ;
$subj = $i->subject ;
$size = $i->size ;
$date = $i->date ;
/*if($i->new){
$sender = '<b>' . $sender . '</b>';
$subj = '<b>' . '</b>';//unicode_to_entities(utf8_to_unicode( $subj )) .
$date = '<b>' . $date . '</b>';
$size = '<b>' . $size . '</b>';
}*/
// $this_email .= "'sender':'" . unicode_to_entities(utf8_to_unicode( $sender )) . "',";
// $this_email .= "'sender':'" . $sender . "',";
$this_email .= "'subj':'" . $subj . "',";
$this_email .= "'subjuuu':'" . unicode_to_entities(utf8_to_unicode( $subj )) . "',";
/* if($folder!='msnpromo' && $folder!='sentitems'){
$this_email .= "'date':'" . $date . "',";
}
$this_email .= "'size':'" . $size . "',";
$this_email .= "'attachment':'" . ($i->hasattachment) . "' "; // no comma at end
*/
$emails[] = "{" . $this_email . "}";
}
echo implode(",\n", $emails) . "]} \n" ;
}
header("Content-type: text/html; charset=utf-8");
header("Pragma: no-cache"); // stop caching
/*
//header("Content-type: text/xml; charset=utf-8"); // must use text/xml for ajax/xmlhttp to work :(
header("Content-type: text/html; charset=utf-8"); // must use text/xml for ajax/xmlhttp to work :(
header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
*/
@ini_set("session.use_cookies", 0);
@ini_set("session.use_trans_sid", 1);
session_start();
/*
echo "<?xml version=\"1.0\" ?>\n\n";
//echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
flush();
*/
if (isset($_SESSION['hail']['hm'])) {
if (array_key_exists('folder_url',$_GET)){
// print emails
print_folder_items($_SESSION['hail']['hm'], $_GET['folder_url']);
/* }elseif (array_key_exists('mail_url',$_GET)){
// print conv
$_SESSION['hail']['hm']->update_read($_GET['mail_url'], 1);
print_email($_SESSION['hail']['hm'], $_GET['mail_url']);
}elseif (array_key_exists('print_folders',$_GET)){
// print folders on demand
print_folders($_SESSION['hail']['hm']);
}else{
$success = 0;
if (array_key_exists('mark_read',$_GET)){
$_SESSION['hail']['hm']->update_read($_GET['url'], 1);
$success = true;
}elseif (array_key_exists('mark_unread',$_GET)){
$_SESSION['hail']['hm']->update_read($_GET['url'], 0);
$success = true;
}elseif (array_key_exists('delete_mail',$_GET)) {
$_SESSION['hail']['hm']->delete_mail($_GET['url']);
$success = true;
}
echo "<root><status>success</status></root>";*/
}
} else { // not logged in
$_SESSION['hail']['sess_user'] = "";
$_SESSION['hail']['sess_pass'] = "";
echo "<root><status>Your login expired</status></root>";
}
?>