<?
//   Wouter van Wijk
//   2004
//
//   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 check
session_start();
if (!isset($_SESSION['user']))
{
	header("Location: error.php?ec=2");
	exit;
}
   $mailbox=$_GET['mailbox'];
   $id=$_GET['id'];
   $action=$_GET['action'];
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="composemail.css" type="text/css"?' . '>' . "\n";
?>

<window title="XULMail"
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

	<script type="application/x-javascript" src="xulwebmail.js" />

<commandset>
<command label="Send" id="cmd_send" state="false" oncommand="submitMessage();"  tooltiptext="Send this message" />
<command label="Save" id="cmd_save" state="false" oncommand="saveMessage();" hidden="true" tooltiptext="Save this message" />
<command label="Address" id="cmd_address" state="false" oncommand="showAddresses();" hidden="true" tooltiptext="Show address book" />
<command label="Attach" id="cmd_attach" state="false" oncommand="attachToMessage();" hidden="true" tooltiptext="Attach a file to this message" />
 <command id="cmd_about" label="About XUL Webmail" state="false" oncommand="showAbout();"/>
</commandset>

<vbox flex="1">
  <toolbox id="non-functioning-toolbox">

    <menubar>
      <menu  id="my-menubar"  label="File" accesskey="F" >
        <menupopup>
<!--           <menuitem label="New Message" />
           <menuitem label="Save" />
               <menuseparator />
           <menuitem label="Print Preview" />
           <menuitem label="Print" />

           <menuseparator />
-->
           <menuitem observes="cmd_send" />
           <menuseparator />
           <menuitem label="Close" oncommand="window.close();" />
        </menupopup>
      </menu>
<!--      <menu label="Edit" accesskey="E">
        <menupopup>
           <menuitem label="Undo" />
           <menuitem label="Redo" />
               <menuseparator />
        <menuitem label="Cut" />
           <menuitem label="Copy" />
           <menuitem label="Paste" />
           <menuitem label="Delete" />
               <menuseparator />
           <menuitem label="Select" />
               <menuseparator />
           <menuitem label="Find" />
        </menupopup>
      </menu>
      <menu label="Options" accesskey="O">
        <menupopup>
           <menuitem label="Priority" />
           <menuitem label="Security" />
           <menuitem label="Return Receipt" />
           <menuitem label="Quote" />
        </menupopup>
      </menu>
      <menu label="Tools" accesskey="T">
        <menupopup>
           <menuitem label="Address Book" />
               <menuseparator />
           <menuitem label="Options" />
        </menupopup>
      </menu>
      <menu label="Help" accesskey="H">
        <menupopup>
           <menuitem label="Online Manual" />
                          <menuseparator />
           <menuitem observes="cmd_about" />
        </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 id="main-toolbar" >
      <toolbarbutton id="button-send" class="toolbarbutton-1"  observes="cmd_send"/>
      <toolbarspacer />
      <toolbarbutton  id="button-address" class="toolbarbutton-1"  observes="cmd_address"/>
      <toolbarspacer />
      <toolbarbutton id="button-attach" class="toolbarbutton-1"  observes="cmd_attach" />
      <toolbarspacer />
      <toolbarbutton id="button-save" class="toolbarbutton-1" observes="cmd_save" />
    </toolbar>

  </toolbox>



    <vbox flex="1">
    <toolbox id="headers-box" class="toolbox-top" mode="icons">
    <toolbar id="MsgHeadersToolbar" persist="collapsed" flex="1"
             tborient="vertical" tbalign="stretch">
      <vbox id="msgheaderstoolbar-box" flex="1">
          <hbox align="center">
            <label value="To" accesskey="T" control="msgTo"/>
            <textbox id="to" flex="1" value="<?
if (($action == "reply") || ($action == "replyall") || ($action == "forward")) {
  	/*
	Gets a message from imap/pop3
	*/
      $mbox = imap_open($_SESSION['server'].$mailbox, $_SESSION['user'], $_SESSION['pass'])
      or die("can't connect: ".$mailbox.'-'.imap_last_error());
$headers = imap_header($mbox, $id);
$body = imap_body($mbox, $id);
$structure = imap_fetchstructure($mbox, $id);
$subject = $headers->Subject;
$from = $header->From;
//to becomes the from
$to = $from[1]->mailbox . '@' . $from[1]->host;

imap_close($mbox);
if (($action == "reply") || ($action == "replyall")) {
  echo $to;
}
}
?>" />
          </hbox>
          <hbox align="center">
            <label value="Subject" accesskey="S" control="msgSubject"/>
            <textbox id="subject" flex="1" class="toolbar" disableonsend="true" value="<?
if ($action == "reply") {
  echo 'Re: ' . $subject;
}
if ($action == "replyall") {
  echo 'Re: ' . $subject;
}
if ($action == "forward") {
  echo 'Fwd: ' .$subject;
}
?>" />
          </hbox>
        </vbox>
    </toolbar>


  </toolbox>

<!--  <splitter id="compose-toolbar-sizer" onmousedown="awSizerListen()" collapse="after"/>  -->

  <!-- The mail message body frame -->
  <vbox id="appcontent" flex="1">
       <textbox class="body" id="message" flex="1" multiline="true" value="<?
if (($action == "reply") || ($action == "replyall") || ($action == "forward")) {
  echo htmlspecialchars($body);
}
?>" />
      </vbox>
  <vbox id="appcontent" flex="1" hidden="true">

  <html:form id="htform" method="POST" enctype="multipart/form-data" action="sendmessage.php">
<html:input type="input" name="subject" id="htsubject" />
<html:input type="input" name="to" id="htto" />
<html:textarea name="message" id="htmessage" />
<html:input type="submit" value="" />
</html:form>
  </vbox>

  </vbox>

</vbox>

</window>

