<?php
/*
PHPwebmail is a webmail client written in php.
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.
*/
session_start();
require("not_registered.php");
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
</head>
<body bgcolor="<?php echo $bg_color_main; ?>" text="<?php echo $fg_color; ?>" link="<?php echo $link_color; ?>" vlink="<?php echo $link_color; ?>" alink="<?php echo $alink_color; ?>">
<font face="arial" size=2>
<?php
// main entry point
if ($db_link = mysql_connect($sql_host,$sql_user,$sql_pw)) {
@mysql_select_db("phpwebmail");
$sql_query = "SELECT folder, textmode FROM prefs WHERE user='$name'";
$result = mysql_query($sql_query);
// catch SQL errors
if (mysql_errno()) echo ("ERROR ".mysql_error());
$row = mysql_fetch_row($result);
$folder_pre = $row[0];
if ($folder_pre && substr($folder_pre,-1)!="/") $folder_pre .= "/";
$textmode = $row[1];
mysql_close($db_link);
} // if db_link ends
if (empty($operation)) {
?>
<h3>Manage your mail folders:<br><br></h3>
<TABLE>
<tr><td colspan=2><hr></td></tr>
<FORM ACTION="folder_ops.php?<?=SID?>&operation=create" target="message_text" METHOD="POST">
<TR><TD width=120><font face="arial" size=2><b>Create</td><td>
<?php if (!$textmode) echo "<img src=images/folder.gif> "; ?>
<font face="arial" size=2><b><INPUT TYPE="TEXT" SIZE=20 NAME="new_folder_name"></td></tr>
<tr><td></td><td align="right">
<?php if ($textmode) echo "<input type=submit value=\" create \">"; else echo "<input type=image src=images/_create.gif border=0 alt=\"create\">"; ?>
</td></tr>
</FORM>
<tr><td colspan=2><hr></td></tr>
<FORM ACTION="folder_ops.php?<?=SID?>&operation=rename" target="message_text" METHOD="POST">
<TR><TD width=120><font face="arial" size=2><b>Rename</td><td>
<?php if (!$textmode) echo "<img src=images/folder.gif> "; ?>
<SELECT NAME="select_folder"><OPTION VALUE="*** select ***" SELECTED>*** select ***
<?php
$mailbox = imap_open("{".$imap_server."}".$folder, $name, $passwd);
if ($mailbox) {
$mailboxes = imap_lsub($mailbox, "{".$imap_server.":143}", "*");
if (count($mailboxes) > 0) {
for ($index = 0; $index < count($mailboxes); $index++) {
$the_folder = substr(stristr($mailboxes[$index],"}"),1);
$has_pre = strstr($the_folder,$folder_pre);
if ($has_pre) $the_folder = substr($has_pre,strlen($folder_pre));
if (strtoupper($the_folder) != "INBOX" && $the_folder != "Sent")
echo("<OPTION VALUE=\"".urlencode($the_folder)."\">".$the_folder."\n");
}
}
imap_close($mailbox);
} else {
echo("<OPTION VALUE=\"Error\">Error");
}
?>
</SELECT></td></tr>
<tr><td></td><td align="right"><font face="arial" size=2><b>to <INPUT TYPE="TEXT" SIZE=20 NAME="new_folder_name"></td></tr>
<tr><td></td><td align="right">
<?php if ($textmode) echo "<input type=submit value=\" rename \">"; else echo "<input type=image src=images/_rename.gif border=0 alt=\"rename\">"; ?>
</td></tr>
</FORM>
<tr><td colspan=2><hr></td></tr>
<FORM ACTION="folder_ops.php?<?=SID?>&operation=delete" target="message_text" METHOD="POST">
<TR><TD width=120><font face="arial" size=2><b>Delete</td><td>
<?php if (!$textmode) echo "<img src=images/folder.gif> "; ?>
<SELECT NAME="select_folder"><OPTION VALUE="*** select ***" SELECTED>*** select ***
<?php
$mailbox = imap_open("{".$imap_server.":143}".$folder, $name, $passwd);
if ($mailbox) {
$mailboxes = imap_lsub($mailbox, "{".$imap_server.":143}", "*");
if (count($mailboxes) > 0) {
for ($index = 0; $index < count($mailboxes); $index++) {
$the_folder = substr(stristr($mailboxes[$index],"}"),1);
$has_pre = strstr($the_folder,$folder_pre);
if ($has_pre) $the_folder = substr($has_pre,strlen($folder_pre));
if (strtoupper($the_folder) != "INBOX" && $the_folder != "Sent")
echo("<OPTION VALUE=\"".urlencode($the_folder)."\">".$the_folder."\n");
}
}
imap_close($mailbox);
} else {
echo("<OPTION VALUE=\"Error\">Error");
}
?>
</SELECT></td></tr>
<tr><td></td><td align="right">
<?php if ($textmode) echo "<input type=submit value=\" delete \">"; else echo "<input type=image src=images/_delete.gif border=0 alt=\"delete\">"; ?>
</td></tr>
</FORM>
<tr><td colspan=2><hr></td></tr>
</table>
<?php
} else
if ($operation == "create") {
$new_folder_name = $folder_pre.$new_folder_name;
$mailbox = imap_open("{".$imap_server.":143}INBOX", $name, $passwd);
$the_new_folder = imap_utf7_encode("{".$imap_server.":143}".imap_8bit($new_folder_name));
if(@imap_createmailbox($mailbox,$the_new_folder)) {
echo "<b>Mail folder ";
if (!$textmode) echo "<img src=images/folder.gif> ";
echo $new_folder_name." created.";
$result = imap_subscribe ($mailbox, $the_new_folder);
} else echo "<b>ERROR - mail folder not created.";
$dummy = imap_close($mailbox);
// use JavaScript to update the folder index
echo "<script language=\"JavaScript\">
parent.frames[0].location.href='iconbar.php?<?=SID?>'
</script>";
}
else
if ($operation == "rename") {
$mailbox = imap_open("{".$imap_server.":143}INBOX", $name, $passwd);
$select_folder = urldecode($select_folder);
$select_folder = $folder_pre.$select_folder;
$the_old_folder = "{".$imap_server.":143}".$select_folder;
$new_folder_name = $folder_pre.$new_folder_name;
$the_new_folder = imap_utf7_encode("{".$imap_server.":143}".imap_8bit($new_folder_name));
if(@imap_renamemailbox($mailbox,$the_old_folder,$the_new_folder)) {
echo "<b>Mail folder ";
if (!$textmode) echo "<img src=\"images/folder.gif\"> ";
echo $select_folder." renamed to ";
if (!$textmode) echo "<img src=\"images/folder.gif\"> ";
echo $new_folder_name;
$result = imap_unsubscribe ($mailbox, $the_old_folder);
$result = imap_subscribe ($mailbox, $the_new_folder);
} else echo "<b>ERROR - mail folder not renamed.";
$dummy = imap_close($mailbox);
if ($select_folder == $folder) $folder = $new_folder_name;
// use JavaScript to update the folder and message index
echo "<script language=\"JavaScript\">
parent.frames[0].location.href='iconbar.php?<?=SID?>'
parent.frames[1].location.href='mail_index.php?<?=SID?>'
</script>";
}
else
if ($operation == "delete") {
$mailbox = imap_open("{".$imap_server.":143}INBOX", $name, $passwd);
$select_folder = urldecode($select_folder);
$select_folder = $folder_pre.$select_folder;
$the_old_folder = "{".$imap_server.":143}".$select_folder;
if(@imap_deletemailbox($mailbox,$the_old_folder)) {
echo "<b>Mail folder ";
if (!$textmode) echo "<img src=\"images/folder.gif\"> ";
echo $select_folder." deleted.";
$result = imap_unsubscribe ($mailbox, $the_old_folder);
if ($select_folder == $folder) $folder = "INBOX";
} else echo "<b>ERROR - mail folder not deleted.";
$dummy = imap_close($mailbox);
// use JavaScript to update the folder and message index
echo "<script language=\"JavaScript\">
parent.frames[0].location.href='iconbar.php?<?=SID?>'
parent.frames[1].location.href='mail_index.php?<?=SID?>'
</script>";
}
?>
</BODY></HTML>