<?
//   XUL Webmail, a web based mailclient
//
//   Copyright (C) 2004 Wouter van Wijk (wvw@dds.nl),
//
//   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

include('settings.php');
// session check
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user'] == '')
{

$user = $_POST['user'];
$pass = $_POST['pass'];
$server = $_POST['server'];
$usessl = $_POST['usessl'];
//$pop3 = $_POST['pop3'];
$pop3 = false;
$portin = $_POST['port'];
$email = $_POST['email'];
if (!$user || !$pass || !$email)
	{
		header("Location: error.php?ec=1");
		exit;
	}

	if ($onlyusestandardserver) {
	 	$server = $standardserver;
		$portin = $standardport;
		$pop3 = $standardpop3;
	}
	if ($onlyusestandardssl) {
		$usessl = $standardusessl;
	}

	if (($portin != '') && (is_numeric($portin))) {
		$port = $portin;
	} else {
		if ($pop3) {
			$port = '110';
		} else {
			$port = '143';
		}
	}

	$server = makeServerString ($server, $port, $pop3, $usessl);

	// store the details in session variables
	session_start();
	// assign values to the session variables
	$_SESSION['user'] = $user;
	$_SESSION['pass'] = $pass;
	$_SESSION['server'] = $server;
	$_SESSION['email'] = $email;
}

header ("Content-type: application/vnd.mozilla.xul+xml; charset=iso-8859-15");
echo '<' . '?xml version="1.0" encoding="iso-8859-15" ?' . '>';
echo '<' . '?xml-stylesheet href="chrome://global/skin/" type="text/css"?' . '>' . "\n";
echo '<' . '?xml-stylesheet href="xulwebmail.css" type="text/css"?' . '>' . "\n";

?>

<window title="<? echo $standardtitle ?>"
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onunload="closeSession();" onload="initMain('<? echo $_SESSION['user'].'-'.$_SESSION['server']; ?>');" persist="width height" >

<script type="application/x-javascript" src="xulwebmail.js" />
<script src="chrome://global/content/nsDragAndDrop.js"/>
<script src="chrome://global/content/nsTransferable.js"/>


<commandset>
 <command id="cmd_close" state="false" label="Close" oncommand="closeSession();"/>
 <command label="Get Messages" id="cmd_getmessages" state="false" oncommand="refreshMessages();"/>
 <command id="cmd_new" label="New Message" state="false" oncommand="sendMessage(0);"/>
 <command id="cmd_reply" state="false" label="Reply" oncommand="sendMessage(1);"/>
 <command id="cmd_replyall" state="false" label="Reply All" oncommand="sendMessage(2);"/>
 <command id="cmd_forward" state="false" label="Forward" oncommand="sendMessage(3);"/>
 <command id="cmd_delete" state="false" label="Delete" oncommand="deleteMessage();"/>
 <command id="cmd_junk" state="false" label="Junk" hidden="true" oncommand=""/>
 <command id="cmd_print" label="Print" state="false" oncommand="printMessage();"/>
 <command id="cmd_stop" label="Stop" state="false" hidden="true" oncommand=""/>
 <command id="cmd_viewsource" label="View Source" state="false"  oncommand="viewSource();" />
 <command id="cmd_about" label="About <? echo $standardtitle ?>" state="false" oncommand="showAbout();"/>
 <command id="cmd_moveto" label="Move to..." />
 <command id="cmd_copyto" label="Copy to..." />
 <command id="cmd_emptytrash" label="Empty Trash"  oncommand="emptyTrash();"/>
 <command id="cmd_newfolder" label="New Folder"  oncommand="createMailbox();"/>
 <command id="cmd_deletefolder" label="Delete Folder" oncommand="deleteMailbox();"/>
 <command id="cmd_renamefolder" label="Rename Folder"  oncommand="renameMailbox();"/>
 <command id="cmd_refreshfolders" label="Refresh Folders" oncommand="refreshMailboxes();"/>
</commandset>

<keyset>
  <key id="cut_cmd" modifiers="accel" key="X"/>
  <key id="copy_cmd" modifiers="accel" key="C"/>
  <key id="paste_cmd" modifiers="accel" key="V"/>
  <key id="close_cmd" keycode="VK_ESCAPE" observers="cmd_close"/>
  <key id="delete_cmd" keycode="VK_DELETE" observes="cmd_delete"/>
</keyset>

<vbox flex="1">
  <toolbox>

    <menubar>
      <menu label="Messages" accesskey="M">
        <menupopup>
           <menuitem observes="cmd_getmessages" />
           <menuitem observes="cmd_new" />
               <menuseparator />
           <menuitem observes="cmd_reply" />
           <menuitem observes="cmd_replyall" />
           <menuitem observes="cmd_forward" />
           <menuitem observes="cmd_delete" />
               <menuseparator />
<!--           <menuitem label="Save as.." /> -->
<!-- copy and move menus build from templates -->
    <menu datasources="mailboxlist.rdf.php" ref="http://www.xulwebmail.com/rdf/mblist" observes="cmd_moveto">
      <template>
        <rule iscontainer="true">
          <menupopup>
            <menu uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name">
              <menupopup>
		       <menuitem value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'move');" />
	               <menuseparator />
		</menupopup>
            </menu>
          </menupopup>
        </rule>
        <rule>
          <menupopup>
            <menuitem uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'move');" />
          </menupopup>
        </rule>
      </template>
	</menu>

    <menu datasources="mailboxlist.rdf.php" ref="http://www.xulwebmail.com/rdf/mblist" observes="cmd_copyto" >
      <template>
        <rule iscontainer="true">
          <menupopup>
            <menu uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name">
              <menupopup>
		       <menuitem value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'copy');" />
	               <menuseparator />
		</menupopup>
            </menu>
          </menupopup>
        </rule>
        <rule>
          <menupopup>
            <menuitem uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'copy');" />
          </menupopup>
        </rule>
      </template>
	</menu>

<!-- end copy and move menus  -->
               <menuseparator />
           <menuitem observes="cmd_print" />
           <menuitem observes="cmd_viewsource" />
               <menuseparator />
           <menuitem observes="cmd_close"/>
        </menupopup>
      </menu>

      <menu label="Folders" accesskey="F" >
        <menupopup>
           <menuitem observes="cmd_newfolder" />
           <menuitem observes="cmd_renamefolder" />
           <menuitem observes="cmd_deletefolder" />
           <menuseparator />
           <menuitem observes="cmd_emptytrash"  />
           <menuseparator />
           <menuitem observes="cmd_refreshfolders"   />
<!--               <menuseparator />
           <menuitem label="Folder Properties" />
-->        </menupopup>
      </menu>

<!--      <menu label="Tools" accesskey="T">
        <menupopup>
           <menuitem label="Filters" />
           <menuitem label="Junk mail" />
               <menuseparator />
           <menuitem label="Options" />
        </menupopup>
      </menu>
-->
      <menu label="Help" accesskey="H">
        <menupopup>
<!--           <menuitem label="usr/svr" oncommand="alert('<? echo $_SESSION['user'].'-'.$_SESSION['server']; ?>');" />
                          <menuseparator />
-->           <menuitem observes="cmd_about" />
        </menupopup>
      </menu>

    </menubar>

    <toolbar>
      <toolbarbutton id="button-getmsg" class="toolbarbutton-1" tooltiptext="Get (new) mail messages" type=""  observes="cmd_getmessages" />
      <toolbarspacer />
      <toolbarbutton  id="button-newmsg" class="toolbarbutton-1" observes="cmd_new" label="Write" type="" />
      <toolbarspacer />
      <toolbarbutton id="button-reply" class="toolbarbutton-1" observes="cmd_reply" />
      <toolbarbutton id="button-replyall" class="toolbarbutton-1" observes="cmd_replyall" />
      <toolbarbutton id="button-forward" class="toolbarbutton-1" observes="cmd_forward"  />
      <toolbarspacer />
      <toolbarbutton id="button-delete" class="toolbarbutton-1" observes="cmd_delete" />
      <toolbarbutton id="button-junk" class="toolbarbutton-1" observes="cmd_junk" />
      <toolbarspacer />
      <toolbarbutton id="button-print" class="toolbarbutton-1" observes="cmd_print" />
      <toolbarspacer />
<!--      <toolbarbutton id="button-move" class="toolbarbutton-1" type="menu" observes="cmd_moveto" menupopup="movepopup"/>
      <toolbarbutton id="button-copy" class="toolbarbutton-1" type="menu" observes="cmd_copyto" menupopup="copypopup" />
      <toolbarspacer />
-->      <toolbarbutton id="button-stop" class="toolbarbutton-1" observes="cmd_stop" />
    </toolbar>
  </toolbox>
	<popupset>
		<popup position="after_start" id="movepopup">
<popupmenu datasources="mailboxlist.rdf.php" ref="http://www.xulwebmail.com/rdf/mblist" observes="cmd_moveto">
      <template>
        <rule iscontainer="true">
          <menupopup>
            <menu uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name">
              <menupopup>
		       <menuitem value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'move');" />
	               <menuseparator />
		</menupopup>
            </menu>
          </menupopup>
        </rule>
        <rule>
          <menupopup>
            <menuitem uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'move');" />
          </menupopup>
        </rule>
      </template>
	</popupmenu>
	</popup>

	<popup id="messagelistpopup">
           <menuitem observes="cmd_reply" />
           <menuitem observes="cmd_replyall" />
           <menuitem observes="cmd_forward" />
           <menuitem observes="cmd_delete" />
               <menuseparator />
<!--           <menuitem label="Save as.." /> -->
<!-- copy and move menus build from templates -->
    <menu datasources="mailboxlist.rdf.php" ref="http://www.xulwebmail.com/rdf/mblist" observes="cmd_moveto">
      <template>
        <rule iscontainer="true">
          <menupopup>
            <menu uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name">
              <menupopup>
		       <menuitem value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'move');" />
	               <menuseparator />
		</menupopup>
            </menu>
          </menupopup>
        </rule>
        <rule>
          <menupopup>
            <menuitem uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'move');" />
          </menupopup>
        </rule>
      </template>
	</menu>

    <menu datasources="mailboxlist.rdf.php" ref="http://www.xulwebmail.com/rdf/mblist" observes="cmd_copyto" >
      <template>
        <rule iscontainer="true">
          <menupopup>
            <menu uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name">
              <menupopup>
		       <menuitem value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'copy');" />
	               <menuseparator />
		</menupopup>
            </menu>
          </menupopup>
        </rule>
        <rule>
          <menupopup>
            <menuitem uri="rdf:*" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" oncommand="copymoveMessage(this.value, 'copy');" />
          </menupopup>
        </rule>
      </template>
	</menu>

<!-- end copy and move menus  -->
               <menuseparator />
           <menuitem observes="cmd_print" />
           <menuitem observes="cmd_viewsource" />

	</popup>

	<popup id="mailboxlistpopup">

           <menuitem observes="cmd_newfolder" />
           <menuitem observes="cmd_renamefolder" />
           <menuitem observes="cmd_deletefolder" />
           <menuseparator />
           <menuitem observes="cmd_emptytrash"  />
           <menuseparator />
           <menuitem observes="cmd_refreshfolders"   />
	</popup>


	</popupset>
<hbox flex="1">

		<tree id="MailBoxTree" context="mailboxlistpopup" flex="1" hidecolumnpicker="true" datasources="" ref="http://www.xulwebmail.com/rdf/mblist" onselect="selectMailbox();" persist="height width" width="200" >
			<treecols>
				<treecol id="mailboxName" label="Folders" flex="1" primary="true" />
			</treecols>
			<template>
      			<rule>
				<treechildren flex="1">
				<treeitem uri="rdf:*" open="true">
					<treerow>
						<treecell label="rdf:http://www.xulwebmail.com/rdf/mailboxlist#name" value="rdf:http://www.xulwebmail.com/rdf/mailboxlist#id" src="icons/folder-open.png" />
					</treerow>
				</treeitem>
				</treechildren>
			</rule>
			</template>
		</tree>
		<splitter state="open" collapse="before" resizebefore="closest" resizeafter="closest" id="vsplitter" />

	<vbox persist="width height" flex="8">
		<tree context="messagelistpopup" enableColumnDrag="true" height="100" persist="width height" flex="2" id="msgTree" datasources="" flags="dont-build-content" ref="urn:items:root" onselect="selectMessage();">
			<treecols>
			<treecol id="subject" label="Subject" flex="3" class="sortDirectionIndicator"
					sort="rdf:http://www.xulwebmail.com/rdf/messagelist#subject" tooltiptext="rdf:http://www.xulwebmail.com/rdf/messagelist#subject" persist="width ordinal hidden sortActive sortDirection" />
			<splitter class="tree-splitter"/>
			<treecol id="fromaddress" label="From" flex="1"
						class="sortDirectionIndicator"
						sort="rdf:http://www.xulwebmail.com/rdf/messagelist#fromaddress"  persist="width ordinal hidden sortActive sortDirection"/>
			<splitter class="tree-splitter"/>
			<treecol id="date" label="Date" flex="2" class="sortDirectionIndicator"
					sort="rdf:http://www.xulwebmail.com/rdf/messagelist#date"  persist="width ordinal hidden sortActive sortDirection"/>
			</treecols>
			<template>
				<treechildren>
				<treeitem uri="rdf:*">
					<treerow tooltiptext="rdf:http://www.xulwebmail.com/rdf/messagelist#subject">
					<treecell label="rdf:http://www.xulwebmail.com/rdf/messagelist#subject"  value="rdf:http://www.xulwebmail.com/rdf/messagelist#id"/>
						<treecell label="rdf:http://www.xulwebmail.com/rdf/messagelist#fromaddress" />
						<treecell label="rdf:http://www.xulwebmail.com/rdf/messagelist#date"/>
					</treerow>
				</treeitem>
				</treechildren>
			</template>
			</tree>

		<splitter state="open" collapse="before" resizebefore="closest" resizeafter="closest" id="hsplitter" />
		<iframe persist="width height" flex="4" id="contentFrame" name="contentFrame" type="content-primary" src="mailsplash.php"/>
	</vbox>
</hbox>

</vbox>


</window>

