<?
/* Copyright (C) 2004 Marco Avidano
*
* This program has been modified by Craigweb, All modifications Copyright (C) Craigweb 2004-2005
*
* 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 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 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
*
* See http://www.gnu.org/licenses/gpl.html for the complete text of the license.
*/
header("Pragma: no-cache");
header("Cache-Control: no-cache, must-revalidate");
@set_time_limit(0);
@error_reporting (E_ALL ^ E_NOTICE);
session_start();
//***************************************//
//*** CONFIGURE Craigweb WebMail HERE *** START ***//
$EMAILDOMAIN="craigweb.net"; //Set the domain all e-mails are to say they were sent from.
$DEFAULT_COLORSET="Craigweb"; //Set the Default Color here. GREY,VIOLET,GREEN,BLUE,BROWN,Craigweb
$DEFAULT_FONTSIZE=10; //Set the Default font size. Any integer from 7 to 16
$DEFAULT_MAIL_PER_PAGE=50; //Set the Default amount of mail to be displayed per page
$SERVERS=array(
"localhost"=>"127.0.0.1"
);
//*** CONFIGURE Craigweb WebMail HERE *** STOP ***//
//**************************************//
$VER=array(
"NAME"=>"Craigweb WebMail", //If you change a significant protion of the code you are required to add the word "modifided" to the name
"WEB"=>"Craigweb",
"URL"=>"http://craigweb.net/",
"MAJOR"=>"1",
"MINOR"=>"01",
"BUILD"=>"104"
);
$_SESSION[email]="$_SESSION[username]@$EMAILDOMAIN";
$SECTION_RIGHT="
$SECTION_RIGHT";
$SECTION_LEFT=array(
"0"=>"Login",
"1"=>"Check Login",
"2"=>"Inbox - ".count($_SESSION[MESSAGES][CONTENT])." message".((count($_SESSION[MESSAGES][CONTENT])>1)?"s":"")." - ".sprintf("%.2f",$_SESSION[MESSAGES][SIZE]/1024)." KB",
"3"=>"Read message",
"4"=>"Compose new mail",
"5"=>"Delete messages",
"6"=>"Send message",
"999"=>"Credits"
);
// Define the colors below
$COLORSET=array(
"GREY"=>array("GROUND"=>"#999999","DARK"=>"#DFDFDF","MEDIUM"=>"#E8E8E8","LIGHT"=>"#F7F7F7","LINE"=>"#7F7F7F","LINKS"=>"#000000"),
"Craigweb"=>array("GROUND"=>"#6699CC","DARK"=>"#C7DDF8","MEDIUM"=>"white","LIGHT"=>"#F7F7F7","LINE"=>"#CCCCCC","LINKS"=>"#000000"),
"VIOLET"=>array("GROUND"=>"#CA6597","DARK"=>"#F6C5DB","MEDIUM"=>"#F3DAE8","LIGHT"=>"#FDEEF6","LINE"=>"#FE00BF","LINKS"=>"#FE4100"),
"GREEN"=>array("GROUND"=>"#64C969","DARK"=>"#C4F5C9","MEDIUM"=>"#D9F2D9","LIGHT"=>"#EDFCED","LINE"=>"#2FFE00","LINKS"=>"#F21DAB"),
"BLUE"=>array("GROUND"=>"#6699CC","DARK"=>"#C7DDF8","MEDIUM"=>"#DBEAF5","LIGHT"=>"#F0F8FF","LINE"=>"#00BFFF","LINKS"=>"#3E00FE"),
"BROWN"=>array("GROUND"=>"#C98A64","DARK"=>"#F5D9C4","MEDIUM"=>"#F2E1D9","LIGHT"=>"#FCF2ED","LINE"=>"#FE2300","LINKS"=>"#2727F9")
);
if(!$_SESSION[COLORS]) $_SESSION[COLORS]=$DEFAULT_COLORSET;
if(!$_SESSION[FONTSIZE]) $_SESSION[FONTSIZE]=$DEFAULT_FONTSIZE;
if($_GET[colorset]) $_SESSION[COLORS]=$_GET[colorset];
$COLORS=$_SESSION[COLORS];
if($_GET[fontsize]) $_SESSION[FONTSIZE]=$_GET[fontsize];
$cwm=$_SERVER[SCRIPT_NAME];
if((!$_SESSION[AUTH] && $_REQUEST[op]>1 && $_REQUEST[op]<100) || !$_REQUEST[op]) $_REQUEST[op]=0;
if(!$_SESSION[MPP]) $_SESSION[MPP]=$DEFAULT_MAIL_PER_PAGE;
$BOUNDARY="----------CraigwebWebmailBoundary";
$LEGAL_CHARS="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._@-";
$SOCK="";
?>
<html>
<head>
<title><?="$VER[NAME] $VER[MAJOR].$VER[MINOR]"?></title>
<style type="text/css"><!--
BODY,TABLE,TR,TD,INPUT,TEXTAREA,OPTION,SELECT { font-family:tahoma,sans-serif;font-size:<?=$_SESSION[FONTSIZE]?>pt;color:#333333;text-decoration:none; }
A:LINK,A:VISITED,.title { font-family:tahoma,sans-serif;font-size:<?=$_SESSION[FONTSIZE]?>pt;color:<?=$COLORSET[$COLORS][LINKS]?>;text-decoration:none; }
A:HOVER { text-decoration:underline; }
--></style>
</head>
<body bgcolor="<?=$COLORSET[$COLORS][GROUND]?>">
<table cellspacing="0" cellpadding="0" width="100%" height="90%" border="0" bgcolor="<?=$COLORSET[$COLORS][MEDIUM]?>">
<tr valign="middle" height="25">
<td width="75%"> <span style="font-size:<?=($_SESSION[FONTSIZE]+4)?>pt;"><b><?="$VER[NAME] $VER[MAJOR].$VER[MINOR]"?></b></span></td>
<td width="25%" align="right">Welcome <u><?="$_SESSION[username]"?></u> </td>
</tr>
<tr valign="top" height="100%">
<td colspan="2" style="padding:10pt;border-top:2pt solid #111111">
<table cellspacing="0" cellpadding="0" width="100%" border="0" bgcolor="<?=$COLORSET[$COLORS][LIGHT]?>">
<tr valign="middle"><td style="border-bottom:1pt solid <?=$COLORSET[$COLORS][LINE]?>"><table cellspacing="0" cellpadding="0" width="100%" border="0"><tr valign="middle">
<td width="35%" style="font-size:<?=($_SESSION[FONTSIZE]+2)?>pt;"><b> <?=$SECTION_LEFT[$_REQUEST[op]]?> </b></td>
<td width="65%" align="right"><b><?=$SECTION_RIGHT?></b> </td>
</tr></table></td></tr>
<tr>
<?
switch($_REQUEST[op]) {
//1:CHECK LOGIN
case "1":
$_SESSION[MESSAGES]=$_SESSION[LIMIT]="";
$auth_fields=array("username","password","server","auth_type");
foreach($auth_fields as $af) {
if($_POST[$af]) $_SESSION[$af]=$_POST[$af];
if(!$_SESSION[$af]) $fields_not_filled=1;
}
echo("<td valign='top'><p> </p><p> </p>");
if($fields_not_filled) {
ShowMessage("ERROR!","<p>You must fill all the fields of the login form!</p>\n<p><a href='$cwm' rel='nofollow' onclick='return false;'><b>Try again</b></a></p>");
} else {
switch(POP3OpenConnectionAndLogin()) {
case "1": //BAD CONNECTION
ShowMessage("ERROR!","<p>Connect to address ".$_SESSION[server].":<br>connection refused</p>\n<p><a href='$cwm' rel='nofollow' onclick='return false;'><b>Try again</b></a></p>");
break;
case "2": //LOGIN FAILED
ShowMessage("ERROR!","<p>Authentication failed (bad password?)<br>Connection closed by foreign host.</p>\n<p><a href='$cwm' rel='nofollow' onclick='return false;'><b>Try again</b></a></p>");
break;
case "3": //LOGIN OK, RETRIEVE MESSAGES
$retr_code=POP3RetrieveHeaders();
switch($retr_code) {
case "31":
$_SESSION[AUTH]=1;
ShowMessage("OK!","<p>Messages fully retrieved!</p>\n<p>If you are not automatically redirected to the next page in 5 seconds,<br>please <a href='$cwm?op=2' rel='nofollow' onclick='return false;'><b>click here</b></a>!</p>\n<script language='JavaScript'>window.location='$cwm?op=2'</script>");
break;
default: //UNKNOWN ANSWER
ShowMessage("ERROR!","<p>Retrieving messages from server ".$_SESSION[server].":<br>unknown answer from the server ($retr_code)</p>\n<p><a href='$cwm' rel='nofollow' onclick='return false;'><b>Try again</b></a></p>");
break;
}
break;
default: //UNKNOWN ANSWER
ShowMessage("ERROR!","<p>Connect to address ".$_SESSION[server].":<br>unknown answer from the server</p>\n<p><a href='$cwm' rel='nofollow' onclick='return false;'><b>Try again</b></a></p>");
break;
}
if($SOCK) POP3CloseConnection();
}
echo("</td>");
break;
//2:SHOW MESSAGE LIST
case "2":
$msgnum=count($_SESSION[MESSAGES][CONTENT])+1;
if($_GET[toggle_delete]) $_SESSION[MESSAGES][CONTENT][$_GET[toggle_delete]][DELETE]*=(-1);
if($_GET[change_limit]) $_SESSION[LIMIT]=$_GET[change_limit];
if($_GET[change_mpp]) {
$_SESSION[MPP]=$_GET[change_mpp];
$_SESSION[LIMIT]=1;
}
if($_POST[auto_mark_deletion]) {
for($i=1;$i<$msgnum;$i++) {
$header=MessageParseHeader(split("\r\n",$_SESSION[MESSAGES][CONTENT][$i][HEADER]));
if(strstr($header[subject],$_POST[auto_mark_deletion]) || strstr($header[from],$_POST[auto_mark_deletion])) $_SESSION[MESSAGES][CONTENT][$i][DELETE]=$message[DELETE]=1;
}
}
if($_GET[mark_all_messages]) {
for($i=$msgnum;$i>0;$i--) $_SESSION[MESSAGES][CONTENT][$i][DELETE]=$_GET[mark_all_messages];
}
$marked_messages_num=0;
fo