<?
// $Header: /cvsroot/jwapmail/Jwapmail/html/index.php,v 1.6 2003/10/13 21:30:54 mrbadi Exp $
/**********************************************************************
*
* main program
*
* Copyright (C) 2002 3WSI <http://3wsi.com)
*
* Author : Nasir Simbolon <hide@address.com>
*
* This program is open source; 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 of the License, 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 <http://www.opensource.org/licenses/gpl-license.html>
* for a complete version of the license
*
**********************************************************************/
session_start ();
include ('jwap.conf.php');
include ('ini.lib.php');
include ('jwap.lib.php');
include ('imap.lib.php');
include ('mbox.lib.php');
include ('wml.lib.php');
// Create session or check for an existing session
include ('header.wml.php');
wmlBegin ();
// If no username means new session
jIsloggedin ();
// Register all variables
registerVariables ();
$fp = imapOpen ();
if (! imapLogin ($fp))
wmlLoginfailed ();
// If authentication OK, do action
$_GET['mbox'] = urldecode ($_GET['mbox']);
if(! isset ($_GET['page']) || empty ($_GET['page'])) {
imapSelect ($fp, 'INBOX');
filterMsg ($fp);
$mailbox = listMbox ($fp);
$totmbox = count ($mailbox);
for($i = $totmbox - 1; $i > 0; $i--) {
$totmsg[$mailbox[$i]] = mboxNummsg ($fp, $mailbox[$i], 'EXIST');
$newmsg[$mailbox[$i]] = mboxNummsg ($fp, $mailbox[$i], 'RECENT');
}
wmlNewcard ('card0', date ("d.m.Y H:i:s", time ()), 1200);
wmlListmbox ($mailbox, $totmsg, $newmsg);
wmlIndexCard ();
wmlMenu1 ();
wmlEndcard ();
}
else if ($_GET['page'] == 'headers') {
if(! isset ($offset))
$offset = 0;
$totmsg = mboxNummsg ($fp, $_GET['mbox'], 'EXISTS');
$listmsg = listMsgheaders ($fp, $_GET['mbox'], $offset + 1, $totmsg,
'Date From Subject');
wmlNewcard ('card0', 'List messages');
wmlListmsg ($listmsg, $offset);
$url = $_SERVER['PHP_SELF'] . '?page=headers&mbox=' .
urlencode ($_GET['mbox']) . '&' . session_name () . '=' .
session_id ();
$wmlout .= wmlPaging ($nummsglist, $totmsg, $url, $offset);
wmlPrevcard ();
wmlEndcard ();
}
else if ($_GET['page'] == 'body') {
wmlNewcard ('card0', 'Message');
if(! $offset) {
$offset = 0;
$msg = getBody ($fp, $_GET['mbox'], $_GET['msgno']);
$message = jSplitmsg ($msg, 1000);
$totmsg = mboxNummsg ($fp, $_GET['mbox'], 'EXISTS');
$headermsg = listMsgheaders ($fp, $_GET['mbox'], $_GET['msgno'],
$totmsg, 'From Date Subject');
$from = $headermsg[0]['From'];
$date = $headermsg[0]['Date'];
$subject = $headermsg[0]['Subject'];
$wmlout .= wmlHeadermsg ($from, $date, $subject);
}
$totalwraped = count ($message);
wmlMessage ($message[$offset]);
$url = $_SERVER['PHP_SELF'] . '?page=body&mbox=' . $_GET['mbox'] .
'&msgno=' . $_GET['msgno'] . '&' . session_name () . '=' .
session_id ();
$wmlout .= wmlPaging (1, $_GET['totalwraped'], $url, $offset);
wmlSwitchcard ('card1');
wmlPrevcard ();
wmlEndcard ();
wmlNewcard ('card1', 'Message');
wmlMsgmenu ($_GET['mbox'], $_GET['msgno']);
wmlPrevcard ();
wmlEndcard ();
}
else if ($_GET['page'] == 'compose') {
if ($_GET['send'] == 1) {
$header = messageRFC822 ($_SESSION['username']);
$header .= 'Cc: ' . $_GET['cc'] . "\r\n";
$_GET['to'] = stripslashes ($_GET['to']);
sendMail ($_GET['to'], $_GET['subject'], $_GET['body'], $header);
wmlNewcard ('card1a', 'Email sent');
$wmlout .= '<p>E-mail has been sent</p>';
wmlIndexCard ();
}
else {
$totmsg = mboxNummsg ($fp, $_GET['mbox'], 'EXISTS');
$headermsg = listMsgheaders ($fp, $_GET['mbox'], $_GET['msgno'], $totmsg,
'From To Cc Reply-To');
switch ($_GET['action']) {
case 'reply':
$_GET['to'] = $headermsg[0]['Reply-To'];
if (empty ($_GET['to']))
$_GET['to'] = $headermsg[0]['From'];
$_GET['subject'] = 'RE:' . $headermsg[0]['Subject'];
wmlNewcard ('card0a', 'Reply');
break;
case 'replyall':
$_GET['to'] = $headermsg[0]['Reply-To'];
if (empty ($_GET['to']))
$_GET['to'] = $headermsg[0]['From'];
$_GET['cc'] = $headermsg[0]['Cc'] . ',' . $headermsg[0]['To'];
$_GET['subject'] = 'RE: ' . $headermsg[0]['Subject'];
wmlNewcard ('card0a', 'Reply to All');
break;
case 'forward':
$_GET['subject'] = 'Fwd: ' . $headermsg[0]['Subject'];
wmlNewcard ('card0a', 'Forward');
break;
default:
wmlNewcard ('card0a','Compose');
break;
}
wmlCompose ($_GET['to'], $_GET['cc'], $_GET['subject']);
wmlPrevcard ();
}
wmlEndcard ();
}
else if ($_GET['page'] == 'manage') {
switch ($_GET['action']) {
case 'delete':
// :TODO: Implement functionality
deleteMsg ($fp, $_GET['mbox'],$_GET['msgno']);
wmlNewcard ('card01' , 'Delete');
wmlPrevcard ();
$wmlout .= "Message ".$_GET['msgno']." from ".$_GET['mbox']." deleted.";
wmlEndcard ();
break;
case 'move':
// :TODO: Implement functionality
wmlNewcard ('card01' , ':TODO: Move');
wmlPrevcard ();
wmlEndcard ();
break;
}
}
else if ($_GET['page'] == 'folders') {
// :TODO: Implement functionality
wmlNewcard ('card01' , ':TODO: Folders');
wmlPrevcard ();
wmlEndcard ();
}
else if ($_GET['page'] == 'logout') {
wmlNewcard ('card1' , 'Logout');
wmlLogout ();
wmlIndexCard ();
wmlEndcard ();
session_unset ();
session_destroy ();
}
else {
// :TODO: Error handling
}
wmlEnd ();
echo $wmlout;
?>