// IfsMailStatus.bcpl -- telnet interface to mail system
// Copyright Xerox Corporation 1980, 1981
// Last modified October 4, 1981  4:16 PM by Taft

get "Ifs.decl"
get "IfsSystemInfo.decl"
get "IfsRs.decl"
get "IfsMail.decl"

external
[
// outgoing procedures
MailStatus

// incoming procedures
PutTemplate; Ws; Plural; WritePackedDT; MoveBlock; Div32x16
VFileReadPage; LockCell; UnlockCell

// incoming statics
infoVMD; dsp
]

//----------------------------------------------------------------------------
let MailStatus() be
//----------------------------------------------------------------------------
[
let ms = VFileReadPage(infoVMD, msPage)
LockCell(lv ms)

PutTemplate(dsp, "*N*NThe mail system is $Sabled",
 (ms>>MS.enabled? "en", "dis"))
if ms>>MS.enabled then
   [
   PutTemplate(dsp, "; forwarding is $Sabled.*nStatistics reset at $P",
    (ms>>MS.forward? "en", "dis"), WritePackedDT, lv ms>>MS.timeReset)

   Ws("*N*N  Samples    Avg     Histogram")
   DoMailStat(lv ms>>MS.mseLen,
    "Length (characters) <64   <128   <256   <512  <1024  <2048  <4096  >4096")
   DoMailStat(lv ms>>MS.mseMlbx,
    "Recipients          0-1    2-3    4-7   8-15    <32    <64   <128   >128")
   DoMailStat(lv ms>>MS.mseSort,
    "Sort delay (sec)      0    1-2    2-3    4-7   8-15    <32    <64    >64")
   DoMailStat(lv ms>>MS.mseFwd,
    "Fwd delay (sec)       0    1-2    2-3    4-7   8-15    <32    <64    >64")
   DoMailStat(lv ms>>MS.mseRetr,
    "Retrieve delay (min) <4    <16   <1 hr    <4    <16  <3 day   <11    >11")

   let discard = lv ms>>MS.discard
   unless discard!0 eq 0 & discard!1 eq 0 do
      PutTemplate(dsp, "*N$EUD message$S discarded",
       discard, Plural(discard!0 % discard!1))
   ]

UnlockCell(lv ms)
]

//----------------------------------------------------------------------------
and DoMailStat(realMSE, text) be
//----------------------------------------------------------------------------
[
let mse = vec lenMSE; MoveBlock(mse, realMSE, lenMSE)
while mse>>MSE.calls↑0 ne 0 do
   [ Div32x16(lv mse>>MSE.calls, 2); Div32x16(lv mse>>MSE.total, 2) ]
if mse>>MSE.calls↑1 ne 0 then Div32x16(lv mse>>MSE.total, mse>>MSE.calls↑1)

PutTemplate(dsp, "*N$S*N$9ED$7ED", text, lv realMSE>>MSE.calls,
 lv mse>>MSE.total)
for i = 0 to 7 do PutTemplate(dsp, "$7ED", lv mse>>MSE.histogram↑i)
]