Stealth Script — File Browser

StealthScriptv1.0 / StealthScriptv1.0 / Stealth / Programs / mircmail-client.mrc

mircmail-client.mrc — 11.2 KB — Download this file

; =================================
;     CLIENT ADDON ALIASES
; =================================
alias msgcenter { dialog -dm msg.main msg.main }
alias msg.chknew {
  did -r msg.main 2,3,4
  if ($sock(mircmail) != $null) { sockwrite -n mircmail 003 }
  else { did -ra msg.main 10 Contacting %msgserv.server $+ ... | sockopen mircmail %msgserv.server 55 }
}
alias msg.history {
  %refr.ctr = 0 | %refr.total = $lines(srvHistory.txt)
  while (%refr.ctr < %refr.total) {
    inc %refr.ctr | %refr.temp = $read -l $+ %refr.ctr srvHistory.txt
    did -a msg.history 2 $gettok(%refr.temp,1,126) 
    did -a msg.history 3 $replace( [ $gettok(%refr.temp,2,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
    did -a msg.history 4 $gettok(%refr.temp,4,126)
} }
; =================================
;     HISTORY DIALOG CONTROL
; =================================
dialog msg.history {
  title "Message History.."
  size -1 -1 400 218

  button "hide", 1, 1 1 1 1, hide, cancel

  list 2, 3 25 100 180                                       ; to column
  list 3, 100 25 201 180                                  ; topic column
  list 4, 297 25 100 180                                   ; time column

  button "Refresh", 6, 56 192 70 23
  button "Read Msg", 7, 129 192 70 23
  button "Del Msg", 8, 202 192 70 23
  button "Del All", 9, 275 192 70 23

  box "", 11, 4 -1 98 25                                                     ; from box
  box "", 12, 100 -1 199 25                                             ; subject box
  box "", 13, 297 -1 99 25                                               ; time recv box

  text "Msg To", 14, 3 8 100 16, center
  text "Subject", 15, 100 8 210 16, center
  text "Sent", 16, 297 8 100 16, center
}
on *:DIALOG:msg.history:INIT:*: { did -r msg.history 2,3,4 | msg.history }
on *:DIALOG:msg.history:SCLICK:*: {
  if ($did isnum 2-4) { did -c msg.history 2,3,4 $did($did,1).sel }
  elseif ($did == 6) { did -r msg.history 2,3,4 | msg.history }
  elseif ($did == 7) { 
    if ($dialog(msg.read) == $null) { dialog -m msg.read msg.read }
    %read.temp = $read -l $+ $did(2,1).sel srvHistory.txt
    did -ra msg.read 5 $gettok(%read.temp,1,126)
    did -ra msg.read 6 $replace( [ $gettok(%read.temp,2,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
    did -ra msg.read 7 $replace( [ $gettok(%read.temp,3,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
    did -ra msg.read 2 Msg To: | did -h msg.read 8
  }
  elseif ($did == 8) {
    if ($did(2,1).sel == $null) { halt }
    write -dl $+ $did(2,1).sel srvHistory.txt | did -r msg.history 2,3,4 | msg.history
  }
  elseif ($did == 9) { .remove srvHistory.txt | did -r msg.history 2,3,4 | msg.history }
}
; =================================
;     COMPOSE DIALOG CONTROL
; =================================
dialog msg.compose {
  title "Compose New Message.."
  size -1 -1 400 241

  button "hide", 1, 1 1 1 1, hide
  button "Msg To:", 2, 3 5 60 23
  button "Topic:", 3, 3 30 60 23
  button "Send Msg", 4, 92 214 70 23
  button "Reset", 5, 165 214 70 23
  button "Return", 6, 238 214 70 23, cancel

  edit "<To>", 10, 65 4 330 23, autohs                                    ; to field
  edit "<Topic>", 11, 65 29 330 23, autohs                            ; topic field
  edit "<Msg Body>", 12, 3 58 392 150, multi, return           ; body field
}
on *:DIALOG:msg.compose:SCLICK:*: {
  if ($did == 4) {
    %compose.ctr = 0 | %compose.total = $did(12).lines
    while (%compose.ctr < %compose.total) {
      inc %compose.ctr | %compose.line = $did(12,%compose.ctr).text
      %compose.line = $replace(%compose.line,$chr(40),$chr(1),$chr(41),$chr(2),$chr(44),$chr(3)) $+ $chr(4)
      hadd msgcenter message $iif($hget(msgcenter,message) != $null, [ $hget(msgcenter,message) ] ) %compose.line
    }
    %compose.tonick = $iif($did(10).text == $null,No Name Entered, [ $did(10).text ] )
    %compose.topic = $did(11).text
    %compose.topic = $replace(%compose.topic,$chr(40),$chr(1),$chr(41),$chr(2),$chr(44),$chr(3)) | %compose.topic = $iif(%compose.topic == $null,No Topic, [ %compose.topic ] )
    sockwrite -n mircmail 001 %compose.tonick %compose.topic $+ ~ $+ $hget(msgcenter,message)
    write srvHistory.txt %compose.tonick $+ ~ $+ %compose.topic $+ ~ $+ $hget(msgcenter,message) $+ ~ $+ $date(ddd) $gmt(h:nn:sstt)
    dialog -x msg.compose | hdel msgcenter message | unset %compose.* | dialog -v msg.main
  }
  elseif ($did == 5) { did -r msg.compose 10,11,12 | did -f msg.compose 10 }
  elseif ($did == 6) { dialog -x msg.compose | dialog -v msg.main }
}
; =================================
;       READ DIALOG CONTROL
; =================================
dialog msg.read {
  title "Read A Msg..."
  size -1 -1 400 241

  button "hide", 1, 1 1 1 1, hide, ok
  button "From:", 2, 3 5 60 23
  button "Topic:", 3, 3 30 60 23
  button "Return", 4, 238 214 70 23, cancel
  button "Reply..", 8, 92 214 70 23
  button "Msg Cache..", 9, 165 214 70 23

  edit "<From>", 5, 65 4 330 23, autohs                          ; from field
  edit "<Topic>", 6, 65 29 330 23, autohs                       ; topic field
  edit "<Msg Body>", 7, 3 58 392 150, multi, return      ; body field
}
on *:DIALOG:msg.read:SCLICK:*: {
  if ($did == 4) { dialog -v msg.main }
  elseif ($did == 8) {
    %reply.replyto = $did(5).text | %reply.topic = Re: $remove($did(6).text,Re:)
    dialog -x msg.read | dialog -m msg.compose msg.compose
    did -ra msg.compose 10 %reply.replyto | did -ra msg.compose 11 %reply.topic
    did -r msg.compose 12 | did -f msg.compose 12 | unset %reply.*
  }
elseif ($did == 9) { dialog -dm msg.history msg.history }
}
; =================================
;    OPTIONS DIALOG CONTROL
; =================================
dialog msg.options {
  title "MsgCenter Config"
  size -1 -1 275 175

  button "Server:", 2, 3 5 65 23
  button "User Name:", 3, 3 30 65 23
  button "Password:", 4, 3 56 65 23
  button "Save", 5, 66 149 70 23
  button "Return", 6, 139 149 70 23, cancel
  button "", 12, 15 113 245 23                                ; sound button

  edit "<Server>", 7, 72 5 200 23                     ; server box
  edit "<User Name>", 8, 72 30 200 23        ;  Username
  edit "<Password>", 9, 72 56 200 23          ; password

  check "Beep On Msg", 10, 20 90 100 16

  box "", 11, 5 78 265 65
}
on *:DIALOG:msg.options:INIT:*: {
  did -ra msg.options 7 %msgserv.server | did -ra msg.options 8 %msgserv.username | did -ra msg.options 9 %msgserv.password
  if (%msgserv.sounds) { did -c msg.options 10 | did -ra msg.options 12 %msgserv.sndfile }
}  
on *:DIALOG:msg.options:SCLICK:*: {
  if ($did == 5) {
    %msgserv.server = $did(7).text
    %msgserv.username = $did(8).text
    %msgserv.password = $did(9).text
    %msgserv.sounds = $iif($did(10).state == 1,$true,$false) | %msgserv.sndfile = $did(12).text
    dialog -x msg.options | dialog -v msg.main
  }
  elseif ($did == 6) { dialog -v msg.main }
  elseif ($did == 12) { did -ra msg.options 12 $$file="Select sound file" $mircdir }
}
; =================================
;     MAIN DIALOG CONTROL
; =================================
dialog msg.main {
  title "MsgCenter Client"
  size -1 -1 400 241

  button "hide", 1, 1 1 1 1, hide, cancel

  list 2, 3 25 100 180                                       ; from column
  list 3, 100 25 201 180                                  ; topic column
  list 4, 297 25 100 180                                   ; time column

  button "Compose", 5, 19 192 70 23
  button "Check Msgs", 6, 92 192 70 23
  button "Read Msg", 7, 165 192 70 23
  button "Del Msg", 8, 238 192 70 23
  button "Options", 9, 311 192 70 23

  edit "Currently Inactive...", 10, 3 218 394 22, read           ; status box

  box "", 11, 4 -1 98 25                                                     ; from box
  box "", 12, 100 -1 199 25                                             ; subject box
  box "", 13, 297 -1 99 25                                               ; time recv box

  text "From", 14, 3 8 100 16, center
  text "Subject", 15, 100 8 210 16, center
  text "Recv'd", 16, 297 8 100 16, center
}
on *:DIALOG:msg.main:INIT:*: {
  %init.result = $dialog(msg.options,msg.options,-2) | unset %init.result
  if ($hget(msgcenter) != $null) { hfree msgcenter }
  hmake msgcenter 1000 | hadd msgcenter server %msgserv.server
  hadd msgcenter username %msgserv.username | hadd msgcenter password %msgserv.password
  sockopen mircmail %msgserv.server 55
}
on *:DIALOG:msg.main:DCLICK:*: { if ($did isnum 2-4) { sockwrite -n mircmail 002 $did($did,1).sel } }
on *:DIALOG:msg.main:SCLICK:*: {
  if ($did == 1) { hfree msgcenter | unset %serv.* | sockclose mircmail }
  elseif ($did isnum 2-4) { did -c msg.main 2,3,4 $did($did,1).sel }
  elseif ($did == 5) { %serv.result = $dialog(msg.compose,msg.compose,-2) | unset %serv.result }
  elseif ($did == 6) { msg.chknew }
  elseif ($did == 7) {
    if ($did(2,1).sel == $null) { did -ra msg.main 10 Select a message to read... }
    else { sockwrite -n mircmail 002 $did(2,1).sel }
  }
  elseif ($did == 8) {
    if ($did(2,1).sel == $null) { did -ra msg.main 10 Select a message to delete... }
    else { sockwrite -n mircmail 004 $did(2,1).sel | msg.chknew }
  }
  elseif ($did == 9) { %serv.result = $dialog(msg.options,msg.options,-2) | unset %serv.result }
}
; =================================
;     ADDON SOCKET EVENTS
; =================================
on *:SOCKCLOSE:mircmail: { did -ra msg.main 10 Disconnected from server... }
on *:SOCKOPEN:mircmail: { sockwrite -n mircmail 000 %msgserv.username %msgserv.password }
on *:SOCKREAD:mircmail: {
  sockread %serv.sockdata
  hadd msgcenter temp %serv.sockdata
  goto $gettok($hget(msgcenter,temp),1,32)
  :000 | did -ra msg.main 10 Could not log into system... | goto end
  :001
  did -ra msg.main 10 Registered on server... | sockwrite -n mircmail 003
  goto end
  :002
  did -a msg.main 2 $gettok($gettok($hget(msgcenter,temp),2-,32),1,126) 
  did -a msg.main 3 $replace( [ $gettok($gettok($hget(msgcenter,temp),2-,32),2,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
  did -a msg.main 4 $gettok($gettok($hget(msgcenter,temp),2-,32),4,126)
  goto end
  :003
  if ($dialog(msg.read) == $null) { dialog -m msg.read msg.read }
  did -ra msg.read 5 $gettok($gettok($hget(msgcenter,temp),2-,32),1,126)
  did -ra msg.read 6 $replace( [ $gettok($gettok($hget(msgcenter,temp),2-,32),2,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
  did -ra msg.read 7 $replace( [ $gettok($gettok($hget(msgcenter,temp),2-,32),3,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
  goto end
  :004 | did -ra msg.main 10 Message deleted... | goto end
  :005 | did -ra msg.main 10 Message sent... | goto end
  :006
  did -a msg.main 2 $gettok($gettok($hget(msgcenter,temp),2-,32),1,126) 
  did -a msg.main 3 $replace( [ $gettok($gettok($hget(msgcenter,temp),2-,32),2,126) ] ,$chr(1),$chr(40),$chr(2),$chr(41),$chr(3),$chr(44),$chr(4),$crlf)
  did -a msg.main 4 $gettok($gettok($hget(msgcenter,temp),2-,32),4,126)
  if ((%msgserv.sounds) && (%msgserv.sndfile != $null)) { .splay %msgserv.sndfile }
  goto end
  :end
  ;  unset %serv.*
}