<?vsp 
--  
--  $Id$
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2018 OpenLink Software
--  
--  This project 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; only version 2 of the License, dated June 1991.
--  
--  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.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  
 http_rewrite(); http_header('Content-type: text/vnd.wap.wml\r\n');
 declare _mm_bcc, _mm_body, _mm_cc, _mm_fld, _mm_from, _mm_own, _mm_rec_date, _mm_snd_time, _mm_subj, _mm_to varchar;
 declare _mm_id, _mm_is_readed varchar;

   declare _user_name, _login_ok varchar;
        declare _login_ok varchar;
  declare _sid, _msg_id, _start, _list, _to_do varchar;
  declare _msg_idd, _list integer;
  declare _display_from, _folder varchar;
  declare _leftquote, _rightquote integer;
  declare _random1 integer;

  _random1 := rnd(9999999);

  _sid := '';
  _sid := get_keyword('SESS', params, '');
   _msg_id := get_keyword('MSG_ID', params, '');
   _start := get_keyword('START', params, '');
   _list := get_keyword('LIST', params, '');
   _to_do := get_keyword('TO_DO', params, '');
   _folder := get_keyword('FOLDER', params, '');
   _list := atoi(get_keyword('LIST', params, ''));

   _msg_idd := atoi(_msg_id);

   _login_ok := 'NO';

 if (_sid  <> '') {
  for select _username from wapsession where sid = _sid  do
  {
   _login_ok := 'YES';
   _user_name := _username;
   update wapsession set _time_last_active = datestring ( now() ) where  sid = _sid;
    declare cr cursor for select MM_ID, MM_FROM, MM_TO, MM_SUBJ, MM_BODY from MAIL_MESSAGE where MM_OWN = _user_name and MM_ID = _msg_idd and MM_FLD = _folder;
       open cr;
   fetch cr into  _mm_id, _mm_from, _mm_to, _mm_subj, _mm_body;
   if(_to_do = 'REPLY')
   {
    _display_from := _mm_from;
    if (strstr(_display_from,'<') >= 0)
    {
     _leftquote := strstr(_display_from, '<');
     _rightquote := strstr(_display_from, '>');
     _display_from := subseq(_display_from, _leftquote + 1, _rightquote);
    }

   }
   if(_to_do = 'FORWARD')
   {
    _display_from := '';
   }
  }
  }else{
    _login_ok := 'NO';

  }

if (_login_ok = 'YES')
{ http_rewrite(); http_header('Content-type: text/vnd.wap.wml\r\n');
?><?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">


<wml>
<card id="compose" title="Write Mail">
   <onevent type ="onenterforward">
    <refresh>
   <setvar name="to" value="<?=_display_from?>"/>
   <setvar name="subj" value="<?=_mm_subj?>"/>
   <setvar name="msg_body" value=""/>
  </refresh>
   </onevent>
  <do type="accept" label="Options">
   <go href="#opt"/>
  </do>
    <p>
 To:<input name="to" title="To:" value="$(to)" tabindex="2" maxlength="100" /><br/>
 Subj:<input name="subj" value="RE:$(subj)" tabindex="2" maxlength="100" />
 Write Msg:<input name="msg_body" value="$msg_body" tabindex="3" maxlength="500" /><br/>
    </p>
 <p><a href="send.vsp?SESS=<?=_sid?>&amp;TO=$(to:e)&amp;MSG=$(msg_body:e)&amp;SUBJ=$(subj:e)&amp;ACTION=<?=_to_do?>&amp;MSG_ID=0" title="Send">Send</a></p>
 <?vsp
  if (not(_to_do = 'REPLY' or _to_do = 'FORWARD'))
  {
 ?>
   <p><a href="save_draft.vsp?SESS=<?=_sid?>&amp;TO=$(to:e)&amp;MSG=$(msg_body:e)&amp;SUBJ=$(subj:e)&amp;ACTION=SAVE_DRAFT&amp;MSG_ID=<?=get_keyword('MSG_ID',params,'')?>" title="Save">Save Draft</a></p>
 <?vsp
 }
 ?>
 <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REFRESH=<?vsp http(sprintf('%d',_random1));?>" title="Cancel">Cancel</a></p>
</card>

<card id="opt">
  <do type="options" label="Exit">
   <go href="#compose"/>
  </do>
 <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REFRESH=<?vsp http(sprintf('%d',_random1));?>">Mail Menu</a></p>
 <p><a href="#compose">Exit</a></p>
</card>

</wml>
<?vsp
}else{ http_rewrite(); http_header('Content-type: text/vnd.wap.wml\r\n');
?><?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">


<wml>
  <card id="P1" title="Wrong" >
    <p mode="nowrap">
   Wrong Login
    </p>
  </card>
</wml>
<?vsp
}
?>


