Unit MsgArea;
Interface

Uses Crt,Dos,io,records,genstr,filehandle,protcomm;


             { .BF  = Base Conf File               }
             { .SCN = Base Conf Lastscan File      }
             { .NDX = Base Index File              }
             { .BOD = Base Message Body            }
type
          (*   Type M_NDX_Type = Record
                  Author      :String[35];
                  Reciever    :String[35];
                  Title       :String[45];
                  FilePos     :LongInt;
                  Numlines    :LongInt;
                  Deleted     :Boolean;
                  Status   : Byte; { Bit 1 - Private }
                                   { Bit 2 - Anonymous }
                  UserNote : String[50];
                  DateTime : string[8];
                  end;


                  B_File_Type = Record
                     Name        : String[40];
                     DataFile    : String[8];
                     QWKID       : String[10];
                     BaseType    : array[1..7] of boolean;
                     { Bit 0  : Allow Anonymous?
                       Bit 1  : Use Real Names?
                       Bit 2  : Allow Quoting?
                       Bit 3  : Allow Private?
                       Bit 4  : Echomail Area?
                       Bit 5  : Award Post?
                       Bit 6-7: Not Used           }
                     Sponsor     : String[30];
                     PostAccess  : String[80]; {i.e. "a17$513"}
                     ReadAccess  : String[80];
                     ListAccess  : String[80];
                     Password    : String[30]; {i.e. "SMEEGLEDIPO"}
                     MaxMessages : 1..1000;
                     UseNet      : Boolean;

                     EchoMailDir : String[80]; {i.e. "C:\NETS\BLACK\ANSI"}
                     NetAddress  : string[10]; {i.e. "23:200/17 }
                     OriginLine  : string[80];       {i.e. "Stolen Archives .."}
                     EchoTag     : String[80]; {i.e. "BLK_ANSI"}
                     NetID       : String[20]; {i.e. "BlackNet"}
                     Kill_Kludge : Boolean;
                     Kill_Seenby : Boolean;
                     Kill_TearLn : Boolean;

                  end;*)

                  Snc_File_Type = Record
                  UserNum:Longint;
                  Lastread:Array[1..255] Of Integer;
                 end;

           type
               cc=array[1..80] of char;
               bb=array[1..255] of cc;

             var
                 Cur_BaseFile     : String;
                 Cur_BaseDataFile : String;

                 CurrentBase      : B_File_Type;
                 M_Buff           : ^bb;
                 currentndx       : m_ndx_type;
                 msgm             : mcis;
                 currentline      : integer;
                 bot              : byte;
                 insert           : boolean;
                 total            : byte;
                 s                : string;
                 c                : char;
                 msgx             : integer;
                 currentbasenum   : byte;
{--- Message Misc Procedures / Functions ---------------------------------- }

Procedure Message_Area_List;
function  postit(reply:boolean;sx:longint):boolean;
procedure read_messages(prompt:boolean);
function  totallines:integer;
procedure msgheader;

{--- Message Base Procedures Reading/Writing Low Level Procedures --------- }

Function  Total_Bases(const fn:string):Byte;
Function  Read_Base  (const fn:string; BaseNum:Byte; Var Base:B_File_Type):Boolean;
Procedure Write_Base (const fn:string; Base:B_File_Type);
Procedure Modify_Base(const fn:string; Base:B_File_Type; BaseNum:Byte);
Procedure Switch_Base(const fn:string; BaseA,BaseB:Byte);
Procedure Delete_Base(const fn:string; BaseNum:Byte);
Procedure Insert_Base(const fn:string; Base:B_File_Type; BaseNum:Byte);

{--- Message Reading/Writing Low Level Procedures / Functions ------------- }

Function  Total_Msg (const fn:string):Integer;
Function  Read_Ndx  (const fn:string; num:longint; var Ndx:M_Ndx_Type):Boolean;
Procedure Write_Ndx (const fn:string; Ndx:M_Ndx_Type);
Procedure Write_Body(const fn:string; var Ndx:M_Ndx_Type);
Procedure Read_Body (const fn:string; Ndx:M_Ndx_Type);

{----Message Scanning Low Level Procedures / Functions -------------------- }

Procedure Check_Last_Read(const fn:string; I:byte);


Implementation

Procedure Check_Last_Read(const fn:string; I:byte);
var x,y,fz    : longint;
    f         : file of Snc_File_Type;
    scan      : Snc_File_Type;
begin
assign(f,FN);
{$i-} reset(f); {$i+}
if ioresult<>0 then rewrite(F);
end;


Procedure Message_Area_List;
var msgarea:mcis;
    i:B_File_type;
    x,y:integer;
    fa:string[3];
begin
fillchar(msgarea,sizeof(msgarea),#0);
msgarea[1].mci:='~AN';
msgarea[2].mci:='~AT';
msgarea[3].mci:='~NM';
msgarea[4].mci:='~SP';
x:=1;
printfile(Config.Textfile_Dir+'marea.top',msgarea,false);
for x:=1 to total_Bases('MSGCONF1') do
begin
read_base('MSGCONF1',X,I);
msgarea[1].str:=strr(x);
msgarea[2].str:=i.name;
msgarea[3].str:=strr(total_msg(i.datafile));
msgarea[4].str:='none';
printfile(Config.Textfile_Dir+'marea.mid',msgarea,false);
end;

printfile(Config.Textfile_Dir+'marea.bot',msgarea,false);
PRINT('|B0|12Message Base ..-> ');
buflen:=3;
sreadln(fa);
buflen:=255;
if valu(fa) in [1..total_bases('MSGCONF1')] then
read_base('MSGCONF1',valu(fa),currentbase);
end;

Function Total_Bases(const fn:string):Byte;
Var Bf:File Of B_File_Type;
Begin
     Assign(Bf,config.board_dir+Fn+'.BF');
     {$I-} Reset(Bf); {$I+}
     If Ioresult<>0 then {$I-} Rewrite(Bf); {$I+}
     Total_Bases:=Filesize(Bf);
     close(bf);
end;

Function Read_Base(const fn:string; BaseNum:Byte; Var Base:B_File_Type):Boolean;
Var Bf:File Of B_File_Type;
    Temp:Boolean;
Begin
     Temp:=False;
     Assign(Bf,config.board_dir+Fn+'.BF');
     {$I-} Reset(Bf); {$I-}
     If Ioresult<>0 then {$I-} Rewrite(Bf); {$I+}
     if BaseNum <= Filesize(bf) then begin
     Temp:=True;
     seek(bf,basenum-1);
     read(Bf,base);
     end else Temp:=False;
     Close(Bf);
     read_base:=temp;
     currentbasenum:=basenum;
   end;

Procedure Write_Base(const fn:string; Base:B_File_Type);
Var Bf:File Of B_File_Type;
Begin
     Assign(Bf,config.board_dir+Fn+'.BF');
     {$I-} Reset(Bf); {$I+}
     If Ioresult<>0 then {$I-} Rewrite(Bf); {$I+}
     Seek(Bf,FileSize(Bf));
     Write(Bf,Base);
     Close(Bf);
end;

Procedure Modify_Base(const fn:string; Base:B_File_Type; BaseNum:Byte);
Var Bf:File Of B_File_Type;
    TB:B_File_Type;
Begin
     Assign(Bf,config.board_dir+Fn+'.BF');
     {$I-} Reset(Bf); {$I+}
     If Ioresult<>0 then {$I-} Rewrite(Bf); {$I+}
     if BaseNum <= Filesize(Bf) then begin
     FillChar(TB,sizeof(B_File_Type),#0);
     Seek(Bf,BaseNum-1);
     Write(Bf,Tb);
     Seek(Bf,BaseNum-1);
     Write(Bf,Base);
     end;
     close(bf);
     end;


Procedure Switch_Base(const fn:string; BaseA,BaseB:Byte);
Var Bf:File Of B_File_Type;
    B1:B_File_Type;
    B2:B_File_Type;
    B3:B_File_Type;
Begin
     Assign(Bf,config.board_dir+Fn+'.BF');
     {$I-} reset(Bf); {$I+}
     If Ioresult<>0 then {$I-} rewrite(bf); {$I+}
     If (BaseA <= Filesize(Bf)) and (BaseB <= Filesize(Bf)) then
     begin
       Fillchar(B3,Sizeof(B_File_Type),#0);
       Seek(Bf,BaseA-1);
       Read(Bf,B1);
       Seek(Bf,BaseB-1);
       Read(Bf,B2);
       Seek(Bf,BaseA-1);
       write(Bf,B3);
       Seek(Bf,BaseA-1);
       write(Bf,b2);
       Seek(Bf,BaseB-1);
       write(bf,b3);
       Seek(Bf,BaseB-1);
       write(bf,b1);
       end;
       close(bf);
     end;



Procedure Delete_Base(const fn:string; BaseNum:Byte);
Var Bf:File Of B_File_Type;
    Temp:B_File_Type;
    Count:Byte;
    RecNum:Byte;
Begin
     Assign(Bf,config.board_dir+fn+'.BF');
     {$I-} reset(bf); {$I+}
     if ioresult<>0 then {$I-} rewrite(Bf); {$I+}
     If BaseNum <= Filesize(Bf) then
     Begin
       for Count:=BaseNum to Filesize(Bf)-1 do begin
        seek(bf,count);
        read(bf,Temp);
        Seek(bf,count-1);
        write(bf,Temp);
       end;
      Seek(bf,filesize(bf));
      truncate(bf);
     end;
   close(bf);
 end;



Procedure Insert_Base(const fn:string; Base:B_File_Type; BaseNum:Byte);
Var Bf:File Of B_File_Type;  { I hate Base Inserting! }
    Base2:B_File_Type;       { This May Or May Not Work }
    Count:Byte;
    RecNum:Byte;
Begin
     Write_Base(Fn,Base);
     For Count:=BaseNum To Total_Bases(fn) do
     Switch_Base(Fn,BaseNum+Count,Total_Bases(fn));
end;


Function Total_Msg(const fn:string):Integer;
Var Nf:File Of M_Ndx_Type;
Begin
     Assign(Nf,config.board_dir+Fn+'.NDX');
     {$I-} Reset(Nf); {$I+}
     If Ioresult<>0 then {$I-} Rewrite(Nf); {$I+}
     Total_Msg:=Filesize(Nf);
     Close(Nf);
End;


Function Read_Ndx(const fn:string; Num:Longint; var Ndx:M_Ndx_Type):Boolean;
var
   NF:File Of M_NDX_Type;
   TV:Boolean;
begin
     TV:=False;
     Fillchar(Ndx,sizeof(Ndx),#0);
     Assign(Nf,config.board_dir+fn+'.NDX');
     {$I-} reset(nf); {$I+}
     If Ioresult<>0 then {$I-} rewrite(nf); {$I+}
     if filesize(nf)=0 then begin
                            read_ndx:=false;
                            close(nf);
                            exit;
                            end;
     If Num <= 0 Then Num:=1;
     If Num-1  <= filesize(nf) then
        Begin
             Seek(Nf,Num-1);
             Read(Nf,Ndx);
             TV:=True;
        end else tv:=false;
    read_ndx:=tv;
    close(Nf);
      end;


Procedure Write_Ndx(const fn:string; Ndx:M_Ndx_Type);
Var NF:File of M_Ndx_Type;
Begin
     Assign(Nf,config.board_dir+Fn+'.NDX');
     {$I-} reset(Nf); {$I+}
     If Ioresult<>0 then {$I-} Rewrite(Nf); {$I+}
     Seek(Nf,filesize(Nf));
     Write(Nf,Ndx);
     close(nf);
   End;

Procedure Read_Body(const fn:string; Ndx:M_Ndx_Type);
Var Bf:Text;
    TmpVar:Integer;
    TmpVar2:String;
Begin
    Assign(Bf,config.board_dir+Fn+'.BOD');
    {$I-} reset(Bf); {$I+}
    if ioresult<>0 then {$I-} rewrite(Bf); {$I+}
    TextSeek(Bf,Ndx.Filepos);
    For TmpVar:=1 to Ndx.Numlines do
     begin
          readln(bf,TmpVar2);
          if length(tmpvar2)=80 then print(tmpvar2) else
          println(tmpVar2);
     end;
   close(Bf);
   end;

Procedure Write_Body(const Fn:String; var Ndx:M_Ndx_Type);
Var Bf:Text;
    y,TempVar:Integer;
    s:string[80];
Begin
     Assign(Bf,config.board_dir+fn+'.BOD');
     {$I-} Reset(Bf); {$I+}
     If Ioresult<>0 then {$I-} rewrite(Bf); {$I+}
     Ndx.Filepos:=Textfilesize(Bf);
     TextSeek(Bf,Ndx.Filepos);
     append(bf);
     ndx.numlines:=totallines;
     For TempVar:=1 to Ndx.Numlines do begin
                                       s:=M_Buff^[TempVar];
                                       for y:=80 downto 1 do
                                       if s[y]=#0 then dec(s[0]);
                                       Writeln(Bf,s);
                                       end;
     close(Bf);
     end;

procedure Reply_Read_Body(const fn:string;var Ndx:M_Ndx_Type;Too,from:Byte);
Var Bf      : Text;
    TmpVar  : Integer;
    tmpvar2 : cc;
    x       : byte;
    y       : byte;
    s       : String[80];
    count   : Byte;
    lines   : byte;
Begin
    Assign(Bf,config.board_dir+Fn+'.BOD');
    {$I-} reset(Bf); {$I+}
    if ioresult<>0 then {$I-} rewrite(Bf); {$I+}
    TextSeek(Bf,Ndx.Filepos);
    if from<>too then
    for tmpvar:=1 to from-1 do readln(bf,s);
    lines:=totallines;
    count:=1;
    y:=too-from;
    if y=0 then y:=1;
    if too=from then begin
                     inc(count);
                     readln(bf,s);
                     for x:=1 to length(s) do m_buff^[lines][x]:=s[x];
                     end else
     For TmpVar:=0 to y do
     begin
          inc(count);
          readln(bf,s);
          for x:=1 to length(s) do m_buff^[tmpvar+lines][x]:=s[x];
     end;
   inc(count,1);
   ndx.numlines:=count;
   close(Bf);
   currentline:=1;
   end;

procedure read_messages(prompt:boolean);
Var msgread    : mcis;
    done       : boolean;
begin
fillchar(msgread,sizeof(msgread),#0);
msgread[1].mci:='~DT'; { DATE }
msgread[2].mci:='~TI'; { TIME }
msgread[3].mci:='~MN'; { DUNNO }
msgread[4].mci:='~ST'; { DUNNO }
msgread[5].mci:='~MT'; { SUBJECT}
msgread[6].mci:='~SN'; { FROM }
msgread[7].mci:='~RN'; { TO }
msgread[8].mci:='~ML'; { lines }
msgread[9].mci:='%CM'; { current msg }
msgread[10].mci:='%CT'; { total msg }
msgx:=1;
done:=false;
repeat
msgread[9].str:=strr(msgx);
msgread[10].str:=strr(total_msg(currentbase.datafile));
fillchar(currentndx,sizeof(currentndx),#0);
if Read_Ndx(currentbase.datafile,msgx,currentndx)=false then
       begin
       println('|B0|12 no more messages. ');
       exit;
       end;
msgread[1].str:=currentndx.datetime;
msgread[2].str:=currentndx.datetime;
msgread[3].str:='none';
msgread[4].str:=strr(currentndx.status);
msgread[5].str:=currentndx.title;
msgread[6].str:=currentndx.author;
msgread[7].str:=currentndx.Reciever;
msgread[8].str:=strr(currentndx.numlines);

printfile(config.textfile_dir+'mailhead.ans',msgread,false);

Read_Body(currentbase.datafile,currentndx);

if prompt=false then exit;

printfile(config.textfile_dir+'mailbot.ans',msgread,false);

c:=sreadkey;
case upcase(c) of

'-':BEGIN  { previous }
    dec(msgx);
    if msgx=0 then msgx:=1;
    end;

#13,'+':begin  { next }
        inc(msgx);
        if msgx>total_msg(currentbase.datafile) then exit;
        end;

'R': postit(true,msgx);  { reply }

'Q': done:=true;

end;

until (done) OR ((Not Carrier) AND (Not Localon)) or (hungup) or (loggedoff);

end;

procedure clearbox;
var i:integer;
begin
for i:=msgm[4].y to msgm[5].y do begin
                                 goxy(msgm[4].x,i);
                                 swrite('[0m[K');
                                 end;
end;

function findlast(line:byte):byte;
var i:integer;
    ii:integer;
begin
 for i:=80 downto 1 do begin
                      if m_buff^[line][i]<>#0 then begin
                                       ii:=i;
                                       if ii=80 then dec(ii);
                                       findlast:=ii+1;
                                       exit;
                                       end;
                      end;
findlast:=1;
end;

function totallines:integer;
var xx:boolean;
    x,y,z:integer;

begin
z:=1;
totallines:=0;
for y:=1 to 100 do
begin
for x:=1 to 80 do if m_buff^[y][x]{.c}<>#0 then begin;
                                               xx:=true;
                                               x:=80;
                                               inc(z);
                                               end;
end;
totallines:=z;
end;


procedure FullScreenEditor;

var Key     : char;
    FseX    : byte;
    FseY    : byte;
    MsgDone : boolean;
    TopLine : byte;
    Insert  : boolean;

procedure UpdateFSE;
Var TempS:string;
    xx,yy:Byte;
    savec:byte;
begin
    savec:=textattr;
    xx:=wherex;
    yy:=wherey;
    if currentline in [1..9]     then temps:='00'+strr(currentline) else
    if currentline in [10..99]   then temps:='0'+strr(currentline) else
    if currentline in [100..255] then temps:=strr(currentline);
    MSGM[6].STR:=temps;
    if fsex in [1..9]   then temps:='0'+strr(fsex) else
    if fsex in [10..80] then temps:=strr(fsex);
    MSGM[7].STR:=temps;
    MSGM[9].str:=yn(insert);

    goxy(msgm[6].x,msgm[6].y);
    ansicolor(msgm[6].Back shl 4 + msgm[6].Fore);
    print(msgm[6].str);

    goxy(msgm[7].x,msgm[7].y);
    ansicolor(msgm[7].Back shl 4 + msgm[7].Fore);
    print(msgm[7].str);

    goxy(msgm[9].x,msgm[9].y);
    ansicolor(msgm[9].Back shl 4 + msgm[9].Fore);
    print(msgm[9].str);

    goxy(xx,yy);
    ansicolor(savec);
end;

Procedure Quote;
begin
(* if Read_Ndx(currentbase.datafile,sx,currentndx)=false then exit;
 quote:=showstring(26);
 REPLACEIT(quote,'~TA',CURRENTNDX.author);
 println('|B0|15');
 println('|B0|15Total Lines [1..'+Strr(currentndx.numlines)+']');
 print('|B0|13Quote Line start > ');
 buflen:=3;
 sreadln(tempb);
 st:=valu(tempb);
 print('|B0|13Quote Line stop > ');
 buflen:=3;
 sreadln(tempb);
 sp:=valu(tempb);
 if st>currentndx.numlines then st:=1 else
 if sp<1 then sp:=currentndx.numlines else
 if sp<st then sp:=currentndx.numlines else
 if st>sp then st:=1 else
 if sp>currentndx.numlines then sp:=currentndx.numlines;
                       for x:=1 to length(quote) do
                               m_buff^[1][x]:=quote[x];

                               reply_read_body(currentbase.datafile,CURRENTNDX,Sp,St);
                               quote:=showstring(27);{'< '+user.alias+' said >';}
                               REPLACEIT(quote,'~TB',USER.ALIAS);
                               currentline:=currentndx.numlines;
                               for x:=1 to length(quote) do
                               m_buff^[currentline][x]:=quote[x];
                               currentline:=1;
                               nclose(f);
                               msgm[1].str:=currentndx.author;
                               msgm[2].str:=user.alias;
                               msgm[3].str:=currentndx.title;
                               MSGM[6].STR:='001';
                               MSGM[7].STR:='01';
                               MSGM[9].str:=yn(insert);*)
                               end;

{procedure killchar(b:boolean);
begin
            if b=true then dec(fsex);
            swrite(#8+' '+#8);
            m_buff^[currentline][fsex]:=#0;
            direction(3);
end;}

procedure display(from:byte);
var i:integer;
    x,y:integer;
    s:string[80];
begin
topline:=from+1;
goxy(1,msgm[4].y);
x:=from;
savexy;
for i:=msgm[4].y to msgm[5].y do
     begin
     goxy(1,i);
     for y:=1 to 80 do write(m_buff^[x][y]);
     inc(x);
     end;
goxy(savedx,savedy);
updatefse;
end;

procedure Scroll(Dir:char);
begin
case upcase(Dir) Of
'U':begin                 { up }
    if currentline=1 then exit;
    dec(currentline);
    display(currentline);
    updatefse;
    end;
'D':begin                 { down }
    if currentline=100 then exit;
    inc(currentline);
    display(currentline-(msgm[5].y-msgm[4].y));
    updatefse;
    end;
end;
end;

procedure Direction(a:byte);
begin
case a of

  1:if currentline>1 then    { up }
    begin
    fsex:=1;
    if wherey=msgm[4].y then scroll('U') else
    begin
    dec(currentline);
    dec(fsey);
    end;
    fsex:=findlast(currentline);
    updatefse;
    end;
  2:if currentline<100 then   { down }
    begin
    fsex:=1;
    if wherey=msgm[5].y then scroll('D') else
    begin
    inc(currentline);
    inc(fsey);
    end;
    fsex:=1;
    updatefse;
    end;
  3:begin                      { left }
    dec(fsex);
    if fsex=0 then if currentline>1 then direction(1) else
    fsex:=1;
    updatefse;
    end;
  4:begin                      { right }
    inc(fsex);
    if fsex=findlast(currentline)+1 then if currentline<100 then
    direction(2) else fsex:=80;
    updatefse;
    end;

end;
goxy(fsex,fsey);
end;

procedure killchar(t:boolean);
var s:string;
    y,G:INTEGER;

begin
if (currentline=1) and (fsex=0) then exit;
if t=true then dec(fsex);
if fsex=0 then begin
               if currentline=1 then exit;
               dec(currentline);
               move(currentline,s,80);
               fsex:=findlast(currentline);
               m_buff^[currentline][fsex]:=#0;
               Swrite(' '+#8);
               direction(3);
               fsex:=findlast(currentline)+1;
               updatefse;
               exit;
               end;
               m_buff^[currentline][fsex]:=#0;
               Swrite(#8+' '+#8);
               FOR G:=fsex TO 79 DO m_buff^[CURRENTLINE][G]:=m_buff^[CURRENTLINE][G+1];
               m_buff^[CURRENTLINE][80]:=#0;
               goxy(1,fsey);
               swrite(#27+'[K');
               for y:=1 to 80 do Swrite(m_buff^[CURRENTLINE][y]{.c});
               goxy(fsex,fsey);
               updatefse;
               end;

procedure command;

var s:string[2];
    xx,yy:byte;
begin
xx:=wherex;
yy:=wherey;
goxy(msgm[8].x,msgm[8].y);
ansicolor(msgm[8].Back shl 4 + msgm[8].Fore);
buflen:=1;
sreadln(s);
case upcase(s[1]) of
'S':begin                         { Save }
      currentndx.usernote:=user.usernote;
      currentndx.datetime:=date;
      currentndx.numlines:=totallines;
      write_body(currentbase.datafile,currentndx);
      Write_Ndx (currentbase.datafile,currentndx);
      msgdone:=true;
    end;
'A':msgdone:=true;                { abort }
'Q':;                             { quote }
'C':begin;                        { clear/restart }
    fillchar(m_buff^,sizeof(m_buff^),#0);
    clearbox;
    currentline:=1;
    msgdone:=false;
    fsex:=1;
    fsey:=msgm[4].y;
    goxy(fsex,fsey);
    end;
'?':begin;                        { Help }
    printfile(config.textfile_dir+'fsehelp.ans',msgm,false);
    printfile(config.textfile_dir+'post.ans',msgm,false);
    display(topline-1);
    end;
'I':;                             { Attach File }
end;
goxy(msgm[8].x,msgm[8].y);
print(' ');
goxy(xx,yy);
ansicolor(7);
end;

var yy:byte;

begin
currentline:=1;
msgdone:=false;
fsex:=1;
fsey:=msgm[4].y;
goxy(fsex,fsey);
repeat
key:=readkey;

case key of
 '0':msgdone:=true;
 '/':begin
     if fsex=1 then command else
     begin
     Swrite(key);
     m_buff^[currentline][fsex]:=key;
     inc(fsex);
     end;
     end;
 #8 :killchar(true);
 #13:direction(2);
 #0: begin
     key:=readkey;
     case key of
        #72:direction(1);  {up}
        #80:direction(2);  {down}
        #75:direction(3);  {left}
        #77:direction(4);  {right}
        #83:killchar(false); { delete }
     end;
 end
else begin
     Swrite(key);
     m_buff^[currentline][fsex]:=key;
     inc(fsex);
     if fsex=81 then begin
                     if wherey=msgm[5].y+1 then goxy(1,msgm[5].y);
                     fsex:=1;
                     direction(2);
                     end;
     updatefse;
     end;
end;

until msgdone=true;
end;

procedure msgheader;
var too  :  string[30];
    desc :  string[30];
begin
                               print('|B0|07');
                               ansiclr;
                               currentline:=1;
                               println('');
                               print('|B0|01(|09Message |09To|01) ');
                               buflen:=20;
                               sreadln(too);
                               print('|B0|01(|09Message Description|01) ');
                               sreadln(desc);
                               buflen:=255;
                               currentndx.author:=user.alias;
                               currentndx.reciever:=too;
                               currentndx.title:=desc;
                               msgm[1].str:=too;
                               msgm[2].str:=user.alias;
                               msgm[3].str:=desc;
                               MSGM[6].STR:='001';
                               MSGM[7].STR:='01';
                               MSGM[9].str:=yn(insert);
end;

function postit(reply:boolean;sx:longint):boolean;

var MsgPtr: Pointer;

begin
 mark(MsgPtr);
 new(m_buff);
 fillchar(m_buff^,sizeof(m_buff^),#0);
 fillchar(msgm,sizeof(msgm),#0);
 msgm[1].mci:='%MT'; msgm[2].mci:='%MF';
 msgm[3].mci:='%MS'; msgm[4].mci:='%MH';
 msgm[5].mci:='%MB'; msgm[6].mci:='%MC';
 msgm[7].mci:='%MX'; msgm[8].mci:='%MM';
 msgm[9].mci:='%MI';

 if reply=false then msgheader else begin
                                    end;

 printfile(config.textfile_dir+'post.ans',msgm,false);

 fullscreeneditor;

 dispose(m_buff);
 release(MsgPtr);
end;


begin
end.