All pastes #394187 Raw Edit

SilverMail 1.1

public text v1 · immutable
·published 2007-03-14 02:53 UTC
rendered paste body
;SilverMail 1.1 ALPHA 
;SilverSwd, 2000
;All bug reports and comments can be sent to silversword@pairc.com
;This was started under 5.61 and not all code has been updated with the new versions, old code was left alone if it still worked as I have just started scripting again and didn't feel like messing with it.

on *:start: { 
  loadvars    
  if (%sm.check == 1) .timerauchk 0 $calc(%sm.chkmin * 60) auchk
}
on *:connect: { if (%sm.check == 1) && ($timer(auchk) == $null) { .timerauchk 0 $calc(%sm.chkmin * 60) auchk } }

alias smail {
  if ($dialog(mail)) { dialog -v mail mail | return } 
  var %1 = $readini $smfile(profiles.sml) user color
  if (%1 != $rgb(face)) {
    writeini $smfile(profiles.sml) user color $rgb(face)
    bmpvert
  }  
  dialog -md mail mail
  did -g mail 2 $scriptdirgraphics\bmail1.bmp
  did -g mail 5 $scriptdirgraphics\bmail2.bmp
  did -g mail 6 $scriptdirgraphics\bmail3.bmp
  did -g mail 7 $scriptdirgraphics\bmail4.bmp
  did -g mail 8 $scriptdirgraphics\bmail5.bmp
  did -g mail 11 $scriptdirgraphics\bmail10.bmp
  disfolder mail 9
  loadvars
  smsgs
}

alias smsgs { 
  did -r mail 3   
  var %msg.file = $scriptdir $+ %sm.user $+ \ $+ $did(mail,9,$did(mail,9).sel) $+ \messages.sml
  if ($exists(%msg.file) != $true) { goto end }    
  var %msg.lines = $lines(%msg.file)
  var %msg.cur = 1
  :loop
  var %msg.temp = $read -l $+ %msg.cur $smadd(%msg.file)
  did -a mail 3  $gettok(%msg.temp,1,159)
  inc %msg.cur
  if (%msg.cur > %msg.lines) goto end
  goto loop
  :end
  if (%msg.lines < 0) var %msg.lines = 0
  did -o mail 10 1 Total messages: %msg.lines
}

dialog mail {
  title "SilverMail 1.1"  
  size -1 -1 500 350
  button "okeeDokee", 1, 1 1 1 1, ok
  icon 2, 3 2 49 38
  list 3, 1 45 498 100
  edit "",4, 1 135 498 210, multi, vsbar, read
  icon 5, 57 2 49 38
  icon 6, 111 2 49 38
  icon 7, 165 2 49 38
  icon 8, 273 2 49 38
  combo 9, 348 2 150 150, drop 
  text "", 10, 348 28 150 15
  icon 11, 219 2 49 38
}

on *:dialog:mail:sclick:2: {  sockopen mail %sm.pop3 110 | sockmark mail get 1 | dialog -md getso getso | did -g getso 2 $scriptdir\graphics\mail1.bmp | did -o getso 3 1 Contacting %sm.pop3 }
on *:dialog:mail:dclick:3: { 
  var %msg.file = $scriptdir $+ %sm.user $+ \ $+ $did(mail,9,$did(mail,9).sel) $+ \messages.sml
  var %read.temp = $read -l $+ $did(3).sel $smadd(%msg.file)
  did -r mail 4
  var %msg.file = $scriptdir $+ %sm.user $+ \ $+ $did(mail,9,$did(mail,9).sel) $+ \ $+ $gettok(%read.temp,2,159) $+ .sml
  filter -fo $smadd(%msg.file) mail 4
}
on *:dialog:mail:sclick:5: { if ($did(3).sel == $null) { return }
  var %msg.file = $scriptdir $+ %sm.user $+ \ $+ $did(mail,9,$did(mail,9).sel) $+ \messages.sml
  var %del.temp = $read -l $+ $did(3).sel $smadd(%msg.file)
  var %del.temp = $gettok(%del.temp,2,159)
  write -dl $+ $did(3).sel $smadd(%msg.file)
  var %msg.file = $scriptdir $+ %sm.user $+ \ $+ $did(mail,9,$did(mail,9).sel) $+ \ $+ %del.temp $+ .sml
  .remove $smadd(%msg.file)
  smsgs
}
on *:dialog:mail:sclick:6: { if ($dialog(wmail)) { dialog -v wmail wmail }
  else dialog -md wmail wmail 
}
on *:dialog:mail:sclick:7: { if ($dialog(pmail)) { dialog -v pmail pmail }
  else { dialog -md pmail pmail | .timer 1 0 shus | .timer 1 0 vh3 | .timer 1 0 shab | .timer -m 1 250 shpro } 
}
on *:dialog:mail:sclick:8: { if ($dialog(aboutsm)) { dialog -v aboutsm aboutsm }
  else dialog -md aboutsm aboutsm 
}
on *:dialog:mail:sclick:9: { smsgs }
on *:dialog:mail:sclick:11: { if ($dialog(filesml)) { dialog -v filesml filesml }
  else dialog -md filesml filesml
}

on *:sockopen:mail: { 
  if ($sockerr > 0) { 
    if (%mail.auchk != 1) did -o getso 3 1 Error contacting %sm.pop3
  }
}

on *:sockread:mail: {
  if ($sockerr > 0) { if (%mail.auchk != 1) did -o getso 3 1 Error recieving data | return }
  :get
  sockread -f %mail.temp
  if ($sockbr == 0) return
  if (%mail.temp == $null) set %mail.temp $chr(160)
  if ($gettok(%mail.temp,1,32) == +OK) && ($sock(mail).mark == get 1) {
    sockwrite -n mail USER %sm.login
    sockmark mail get 2
    if (%mail.auchk != 1) { did -o getso 3 1 Contacted, logging in }
    goto end
  }
  if ($gettok(%mail.temp,1,32) == -ERR) {
    sockwrite -n mail QUIT
    sockclose mail    
    if (%mail.auchk != 1) { did -o getso 3 1 Error getting mail }
    goto end
  }
  if ($gettok(%mail.temp,1,32) == +OK) && ($sock(mail).mark == get 2) {
    sockwrite -n mail PASS $decrypt(%sm.pass)    
    sockmark mail get 3
    goto end  
  }
  if ($gettok(%mail.temp,1,32) == +OK) && ($sock(mail).mark == get 3) {
    sockwrite -n mail STAT
    sockmark mail get 4    
    if (%mail.auchk != 1) { did -o getso 3 1 Logged in, checking for mail }
    goto end
  }
  if ($gettok(%mail.temp,1,32) == +OK) && ($sock(mail).mark == get 4) && ($gettok(%mail.temp,2,32) > 0) {  
    if (%mail.auchk != 1) {  
      set %mail.getnum $gettok(%mail.temp,2,32)
      set %mail.curnum 1
      set %mail.tbyte $gettok(%mail.temp,3,32)
      sockmark mail get 5
      sockwrite -n mail RETR 1
      if ($calc(%mail.getnum + 1) > 1) { did -o getso 3 1 Getting message %mail.curnum of %mail.getnum }
      goto end
    }  
    if (%mail.auchk == 1) {
      if ($calc($gettok(%mail.temp,2,32) + 1) > 1) aumail $gettok(%mail.temp,2,32) $gettok(%mail.temp,3,32) 
      sockwrite -n mail QUIT
      unset %mail.*
    }  
  }
  if ($gettok(%mail.temp,1,32) == +OK) && ($sock(mail).mark == get 4) && ($gettok(%mail.temp,2,32) == 0) {
    sockwrite -n mail QUIT
    if (%mail.auchk != 1) { did -o getso 3 1 No messages }
    goto end
  }
  if ($sock(mail).mark == get 5) && ($gettok(%mail.temp,1,32) != .) && ($gettok(%mail.temp,1,32) != +OK)  {
    var %mail.file = temp $+ %mail.curnum $+ .sml    
    write $smfile(%mail.file) %mail.temp
    inc %mail.cbyte $sockbr
    did -o getso 4 1 Retrieving: $percent(%mail.cbyte,%mail.tbyte)    
    goto end
  }  
  if ($sock(mail).mark == get 5) && ($gettok(%mail.temp,1,32) == .) && ($gettok(%mail.temp,1,32) != +OK)  {
    mailvert %mail.curnum      
    if (%mail.curnum == %mail.getnum) { sockwrite -n mail QUIT | sockclose mail | dialog -x getso  | unset %mail.* | goto end }
    inc %mail.curnum
    did -o getso 3 1 Getting message %mail.curnum of %mail.getnum    
    sockwrite -n mail RETR %mail.curnum
  }
  :end
}

alias mailvert {
  var %vert.file = $scriptdirtemp $+ $1 $+ .sml
  window -lh @1
  window -lh @2
  window -lh @3
  window -lh @4
  window -lh @5
  filter -fwn $smadd(%vert.file) @1 *From:*
  filter -fwn $smadd(%vert.file) @2 *To:*
  filter -fwn $smadd(%vert.file) @3 Subject:*
  filter -fwn $smadd(%vert.file) @4 *Date:*
  filter -fwn $smadd(%vert.file) @5 *Status:*
  var %vert.hash = $deltok($line(@1,1),1,32) $deltok($line(@3,1),1,32)
  var %vert.hash = $hash(%vert.hash,32) 
  var %msg.file = $scriptdir $+ %sm.user $+ \Inbox\ $+ %vert.hash $+ .sml
  var %vert.file2 = $smadd(%msg.file)
  write %vert.file2 $read -l $+ $gettok($line(@1,1),1,32) %vert.file
  write %vert.file2 $read -l $+ $gettok($line(@2,1),1,32) %vert.file
  write %vert.file2 $read -l $+ $gettok($line(@3,1),1,32) %vert.file
  write %vert.file2 $read -l $+ $gettok($line(@4,1),1,32) %vert.file
  var %vert.line = [ $calc($gettok($line(@5,1),1,32) + 1) $+ - [ $+ [ $lines(%vert.file) ] ] ] 
  filter -ffr %vert.line %vert.file %vert.file2
  var %vert.temp1 = $read -l1 %vert.file2
  var %vert.temp2 = $read -l3 %vert.file2
  var %msg.file = $scriptdir $+ %sm.user $+ \Inbox\messages.sml  
  write $smadd(%msg.file) $gettok(%vert.temp1,2,58) $gettok(%vert.temp2,2,58) $+ $chr(159) $+ %vert.hash
  .remove %vert.file  
  window -c @1
  window -c @2
  window -c @3
  window -c @4
  window -c @5
  smsgs
}

dialog wmail {
  title "SilverMail Composer"
  size -1 -1 430 300
  button "I hate these things", 1, 1 1 1 1, ok
  icon 2, 3 2 49 38
  text "To:", 3, 23 47 15 20
  edit "", 4, 45 45 380 20, autohs
  text "Subject:", 5, 1 72 40 20
  edit "", 6, 45 70 380 20, autohs
  edit "", 7, 5 95 420 200, multi, autovs, vsbar, return
  icon 8, 57 2 49 38
  icon 9, 111 2 49 38
  icon 10, 165 2 49 38
}

on *:dialog:wmail:init:0: { 
  did -g wmail 2 $scriptdirgraphics\bmail6.bmp
  did -g wmail 8 $scriptdirgraphics\bmail7.bmp
  did -g wmail 9 $scriptdirgraphics\bmail8.bmp
  did -g wmail 10 $scriptdirgraphics\bmail9.bmp
}
on *:dialog:wmail:sclick:2: {  
  sockopen send %sm.smtp 25  
  sockmark send send 1  
  svsentmsg
  dialog -md getso getso  
  did -g getso 2 $scriptdir\graphics\mail1.bmp 
  did -o getso 3 1 Contacting %sm.smtp 
}
on *:dialog:wmail:sclick:8: { if ($dialog(pmail)) { dialog -v pmail pmail }
  else { dialog -md pmail pmail | .timer 1 0 shus | .timer 1 0 vh16 | .timer 1 0 shab | .timer -m 1 250 shpro 2 }
}
on *:dialog:wmail:sclick:9: { .timer 1 0 sadr }
on *:dialog:wmail:sclick:10: { .timer 1 0 opdr }

on *:sockopen:send: {
  if ($sockerr > 0) { did -o getso 3 1 Error contacting %sm.smtp | return }  
}

on *:sockread:send: {
  if ($sockerr > 0) { aline -p @watch Error | return }  
  sockread -f %send.temp
  if ($left(%send.temp,1) == 2) && ($sock(send).mark == send 1) {
    did -o getso 3 1 Logging in    
    sockwrite -n send HELO $ip
    sockmark send send 2
  }
  if (($left(%send.temp,1) == 4) || ($left(%send.temp,1) == 5)) && ($sock(send).mark == send 1) {
    sockwrite -n send QUIT
    did -o getso 3 1 Error logging in
  }
  if ($left(%send.temp,1) == 2) && ($sock(send).mark == send 2) {
    sockwrite -n send MAIL FROM: %sm.address
    did -o getso 3 1 Sending    
    sockmark send send 3
  }
  if (($left(%send.temp,1) == 4) || ($left(%send.temp,1) == 5)) && ($sock(send).mark == send 2) {
    sockwrite -n send QUIT
    did -o getso 3 1 Error sending  
  }
  if ($left(%send.temp,1) == 2) && ($sock(send).mark == send 3) {
    if ($numtok($did(wmail,4).text,44) > 1) { var %rcpt.num $numtok($did(wmail,4).text,44)
      var %rcpt.cur = 1      
      :sendloop
      sockwrite -n send RCPT TO: $gettok($did(wmail,4).text,%rcpt.cur,44)
      inc %rcpt.cur
      if (%rcpt.cur > %rcpt.num) goto endrcpt
      goto sendloop
    }      
    else { sockwrite -n send RCPT TO: $did(wmail,4).text }   
    :endrcpt      
    sockmark send send 4
  }
  if (($left(%send.temp,1) == 4) || ($left(%send.temp,1) == 5)) && ($sock(send).mark == send 3) {
    sockwrite -n send QUIT
    did -o getso 3 1 Error sending  
  }
  if ($left(%send.temp,1) == 2) && ($sock(send).mark == send 4) {
    sockwrite -n send DATA
    sockmark send send 5
  }
  if (($left(%send.temp,1) == 4) || ($left(%send.temp,1) == 5)) && ($sock(send).mark == send 4) {
    sockwrite -n send QUIT
    did -o getso 3 1 Error sending  
  }
  if ($left(%send.temp,3) == 354) && ($sock(send).mark == send 5) {
    set %send.num $did(wmail,7).lines
    set %send.temp 1    
    sockwrite -n send From: %sm.address
    sockwrite -n send To: $did(wmail,4).text     
    sockwrite -n send Subject: $did(wmail,6).text
    sockwrite -n send Return-Address: %sm.address
    sockwrite -n send Date: $fulldate
    sockmark send send 6
  }  
  if (($left(%send.temp,1) == 4) || ($left(%send.temp,1) == 5)) && (($sock(send).mark == send 5) || ($sock(send).mark == send 6) || ($sock(send).mark == send 7)) {
    sockwrite -n send QUIT
  }
}

on *:sockwrite:send: { if ($sock(send).mark == send 6) {
    if ($sockerr > 0) { did -o getso 3 1 Error sending | return }
    if (%send.temp > %send.num) { if (%sm.sig == 1) addsig | dialog -x getso | dialog -x wmail | sockwrite -n send $crlf $+ . | sockwrite -n send QUIT | sockmark send send 7 | return }
    sockwrite -n send $did(wmail,7,%send.temp).text    
    inc %send.temp 
  }
  :end
}

dialog getso {
  title "Contacting..."
  size -1 -1 200 34
  button "holyhell", 1, 1 1 1 1, cancel
  icon 2, 1 1 32 32
  text "", 3, 40 1 158 15
  text "", 4, 40 16 158 15
}

on *:dialog:getso:sclick:1: { 
  sockclose mail
  sockclose send
}

dialog pmail {
  title "SilverMail Profiles"
  size -1 -1 380 170
  button "Ok", 1, 120 145 60 23, ok
  combo 2, 1 1 95 100, drop  
  radio "Servers", 3, 100 1 52 21, push
  text "POP3 Server:", 4, 1 38 65 20
  edit "", 5, 70 35 300 20, autohs
  text "Login:", 6, 37 63 65 20
  edit "", 7,  70 60 130 20, autohs
  text "Pass:", 8, 205 63 65 20
  edit "", 9, 235 60 135 20, autohs, pass
  text "SMTP Server:", 10, 1 87 68 20
  edit "", 11, 70 85 300 20, autohs
  text "Email Address:", 12, 1 112 69 20
  edit "", 13, 70 110 300 20, autohs
  button "New User", 14, 185 145 60 23
  button "Cancel", 15, 315 145 60 23, cancel
  radio "Address", 16, 156 1 52 21, push
  list 17,  219 35 150 108, extsel
  text "Email Address:", 18, 1 38 69 20
  edit "", 19, 70 35 145 20, autohs
  text "Nickname:", 20, 19 63 65 20
  edit "", 21, 70 60 145 20, autohs
  button "Add", 22, 25 85 60 20
  button "Delete", 23, 155 85 60 20
  button "Mail To", 24, 90 85 60 20
  radio "Options", 25, 212 1 52 21, push
  check "Check for new mail every", 26, 10 35 150 20
  edit "", 27, 165 35 40 20
  check "Show new mail graphic", 28, 10 60 150 20
  check "Show Nicknames in Address Book", 29, 10 85 200 20
  check "Play new mail sound", 30, 10 110 115 20
  radio "Signature", 31, 268 1 52 21, push
  check "Use signature file", 32, 10 35 100 20
  edit "", 33, 115 35 187 20, read, autohs
  button "Browse", 34, 307 35 60 20
  edit "", 35, 10 60 357 72, read, multi, autovs, vsbar
  edit "", 36, 130 110 172 20, read, autohs
  button "Browse", 37, 307 110 60 20
  button "Modify", 38, 25 110 60 20
  button "Import", 39, 90 110 60 20
  button "Export", 40, 155 110 60 20
  button "Del. User", 41, 250 145 60 23
  radio "Folders", 42, 324 1 52 21, push
  list 43,  219 35 150 108
  button "Add", 44, 3 35 50 20
  edit "", 45, 58 35 156 20, autohs
  button "Empty", 46, 3 60 50 20
  edit "", 47,  58 60 156 20, read, autohs
  button "Delete", 48, 3 85 50 20
  edit "", 49, 58 85 156 20, read, autohs
}

on *:dialog:pmail:sclick:14: { .timer 1 0 addmus }
on *:dialog:pmail:sclick:1: { if ($did(2).sel != $null) writeini $smfile(profiles.sml) user number $did(2).sel
  if ($did(2,$did(2).sel).text != $null) writeini $smfile(profiles.sml) user current $did(2,$did(2).sel).text
  if ($did(5).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text pop3 $did(5).text
  if ($did(7).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text login $did(7).text
  if ($did(9).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text pass $encrypt($did(9).text)
  if ($did(11).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text smtp $did(11).text
  if ($did(13).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text address $did(13).text
  writeini $smfile(profiles.sml) $did(2,$did(2).sel).text check $did(26).state
  if ($did(27).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text chkmin $did(27).text
  writeini $smfile(profiles.sml) $did(2,$did(2).sel).text graphic $did(28).state
  writeini $smfile(profiles.sml) $did(2,$did(2).sel).text nickname $did(29).state
  writeini $smfile(profiles.sml) $did(2,$did(2).sel).text sound $did(30).state
  writeini $smfile(profiles.sml) $did(2,$did(2).sel).text signature $did(32).state
  if ($did(33).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text sigfile $did(33).text  
  if ($did(36).text != $null) writeini $smfile(profiles.sml) $did(2,$did(2).sel).text sndfile $did(36).text  
  loadvars
  if (%sm.check == 1) { .timerauchk off | .timerauchk 0 $calc(%sm.chkmin * 60) auchk }
  if (%sm.check == 0) && ($timer(auchk) != $null) .timerauchk off
}
on *:dialog:pmail:sclick:2: { uscha }
on *:dialog:pmail:sclick:16: { vh16 }
on *:dialog:pmail:sclick:3: { vh3 }
on *:dialog:pmail:sclick:22: { write $smfile($smuser(abook)) $did(19).text $+ $chr(159) $+ $did(21).text | did -r pmail 19 | did -r pmail 21 | shab }
on *:dialog:pmail:sclick:23: if ($did(17).sel != $null) { write -dl $+ $did(17).sel $smfile($smuser(abook)) | shab }
on *:dialog:pmail:sclick:24: { 
  if ($dialog(wmail) != wmail) { dialog -md wmail wmail } 
  if ($did(17,0).sel == 1) { var %temp388 = $read -l $+ $did(17).sel $smfile($smuser(abook)) | did -a wmail 4 $gettok(%temp388,1,159) } 
  if ($did(17,0).sel > 1) { var %temp11 = $did(17,0).sel
    var %temp12 = 1  
    :lewpy
    var %temp388 = $read -l $+ $did(17,%temp12).sel $smfile($smuser(abook)) 
    did -a wmail 4 $gettok(%temp388,1,159)
    inc %temp12
    if (%temp12 > %temp11) goto end
    did -a wmail 4 ,
    goto lewpy
    :end
  }
}
on *:dialog:pmail:sclick:25: { vh25 }
on *:dialog:pmail:sclick:26: { if ($did(26).state == 1) { did -e pmail 27,28,30,36,37 }
  if ($did(26).state == 0) { did -b pmail 27,28,30,36,37 } 
}
on *:dialog:pmail:sclick:31: { vh31 }
on *:dialog:pmail:sclick:32: { if ($did(32).state == 1) { did -e pmail 33,34,35 }
  if ($did(32).state == 0) { did -b pmail 33,34,35 } 
}
on *:dialog:pmail:sclick:34: { .timer 1 0 getsig }
on *:dialog:pmail:sclick:37: { .timer 1 0 getsnd }
on *:dialog:pmail:sclick:38: { if ($did(17).sel != $null) {
    var %ab.temp = $read -l $+ $did(17).sel $smfile($smuser(abook))
    did -r pmail 19,21
    did -a pmail 19  $gettok(%ab.temp,1,159)
    did -a pmail 21  $gettok(%ab.temp,2,159) 
    write -dl $+ $did(17).sel $smfile($smuser(abook)) 
    shab
  }
}
on *:dialog:pmail:sclick:39: { inab }
on *:dialog:pmail:sclick:40: { exab }
on *:dialog:pmail:sclick:41: { remus }
on *:dialog:pmail:sclick:42: { vh42 }
on *:dialog:pmail:sclick:44: {
  if ($did(45) != $null) {
    var %1 = $scriptdir $+ $smuser(folders)
    if ($exists(%1) != $true) write -c $smfile($smuser(folders))
    var %1 = $replace($did(45),$chr(32),$chr(160))
    window -h @1
    filter -fw $smfile($smuser(folders)) @1 %1
    window -c @1
    if ($filtered > 0) { 
      did -r pmail 45
      return
    }
    write $smfile($smuser(folders)) %1
    var %1 = $scriptdir $+ %sm.user $+ \ $+ %1
    mkdir $smadd(%1)
    var %1 = %1 $+ \ $+ messages.sml
    write -c $smadd(%1)
    disfolder pmail 43
    if ($dialog(filesml)) disfolder filesml 4
    if ($dialog(mail)) disfolder mail 9
    did -r pmail 45
  }
}

alias getsig {
  did -r pmail 33,35
  var %browse.temp = $dir"Select File"  
  did -a pmail 33 %browse.temp
  filter -fo $smadd(%browse.temp) pmail 35
  dialog -v pmail pmail
}

alias getsnd {
  did -r pmail 36
  var %browse.temp = $dir"Select File"  
  did -a pmail 36 %browse.temp
  dialog -v pmail pmail
}

alias vh3 {
  did -v pmail 4,5,6,7,8,9,10,11,12,13
  did -h pmail 17,18,19,20,21,22,23,24,26,27,28,29,30,32,33,34,35,36,37,38,39,40,43,44,45,46,47,48,49
}

alias vh16 {
  did -v pmail 17,18,19,20,21,22,23,24,38,39,40
  did -h pmail 4,5,6,7,8,9,10,11,12,13,26,27,28,29,30,32,33,34,35,36,37,43,44,45,46,47,48,49
}

alias vh25 {
  did -v pmail 26,27,28,29,30,36,37
  did -h pmail 17,18,19,20,21,22,23,24,4,5,6,7,8,9,10,11,12,13,32,33,34,35,38,39,40,43,44,45,46,47,48,49
}

alias vh31 {
  did -v pmail 32,33,34,35
  did -h pmail 26,27,28,29,30,36,37,17,18,19,20,21,22,23,24,4,5,6,7,8,9,10,11,12,13,38,39,40,43,44,45,46,47,48,49
}

alias vh42 {
  did -v pmail 43,44,45,46,47,48,49
  did -h pmail 26,27,28,29,30,36,37,17,18,19,20,21,22,23,24,4,5,6,7,8,9,10,11,12,13,38,39,40,32,33,34,35
}

alias addmus {
  var %temppp = $mailput(Username?) 
  var %temppp = $replace(%temppp,$chr(32),$chr(160)) 
  write $smfile(users.sml) %temppp
  mkdir $smfile(%temppp) 
  var %tmpm = %temppp $+ \inbox\messages.sml
  var %1 = %temppp $+ \sent\messages.sml
  var %2 = %temppp $+ \inbox 
  var %3 = %temppp $+ \sent 
  var %tmpa = %temppp $+ \abook.sml  
  mkdir $smfile(%2)
  mkdir $smfile(%3)  
  write -c $smfile(%tmpm) 
  write -c $smfile(%1) 
  write -c $smfile(%tmpa)    
  shus
  did -c pmail 2 $did(pmail,2).lines
  uscha
  dialog -v pmail pmail
}

alias remus {
  var %temppp = $did(pmail,2,$did(pmail,2).sel).text
  var %temppp2 = $did(pmail,2).sel  
  var %bleh = $scriptdir $+ %temppp  
  write -dl $+ %temppp2 $smfile(users.sml)
  remini $smfile(profiles.sml) %temppp
  var %temp = $findfile(%bleh,*.*,0,.remove $1)  
  rmdir $smfile(%temppp)  
  shus
  did -c pmail 2 1
  uscha
  dialog -v pmail pmail
}

alias shus { did -r pmail 2 | filter -fo $smfile(users.sml) pmail 2 }

alias shab { 
  did -r pmail 17 
  var %ab.file = $scriptdir $+ %sm.user $+ \abook.sml  
  if ($exists(%ab.file) != $true) { goto end }  
  var %ab.lines = $lines(%ab.file)
  var %ab.cur = 1
  :loop
  var %ab.temp = $read -l $+ %ab.cur $smadd(%ab.file)
  if (%sm.nickname != 1) did -a pmail 17  $gettok(%ab.temp,1,159)
  if (%sm.nickname == 1) did -a pmail 17  $gettok(%ab.temp,2,159)  
  inc %ab.cur
  if (%ab.cur > %ab.lines) goto end
  goto loop
  :end
}

alias shpro {
  if ($1 == $null) did -c pmail 3
  if ($1 == 2) did -c pmail 16  
  if ($1 == 3) did -c pmail 42
  did -c pmail 2 %sm.unum
  did -a pmail 5 %sm.pop3
  did -a pmail 7 %sm.login
  did -a pmail 9 %sm.pass
  did -a pmail 11 %sm.smtp
  did -a pmail 13 %sm.address
  if (%sm.check == 1) did -c pmail 26
  if (%sm.check == 0) { did -b pmail 27,28,30,36,37 }
  did -a pmail 27 %sm.chkmin
  if (%sm.graphic == 1) did -c pmail 28
  if (%sm.nickname == 1) did -c pmail 29
  if (%sm.sound == 1) did -c pmail 30  
  if (%sm.sig == 1) { did -c pmail 32 }
  if (%sm.sig == 0) { did -b pmail 33,34,35 }
  did -a pmail 33 %sm.sigfile
  did -a pmail 36 %sm.sndfile
  if ($exists(%sm.sigfile) == $true) filter -fo $smadd(%sm.sigfile) pmail 35
  did -h pmail 35
  if ($1 != 3) did -h pmail 43
  disfolder pmail 43
}

alias -l encrypt { return $replace($1-,a,Ç,b,À,c,Á,d,Â,e,Ã,f,Ä,g,Å,h,Æ,i,ý,j,È,k,É,l,Ë,m,Ì,n,Í,o,Î,p,Ï,q,Ð,r,Ñ,s,Ò,t,ï,u,Ô,v,Õ,w,Ö,x,Ù,y,Ú,z,Û,?,Ü,!,ÿ,:,Ý,;,Þ,1,ß,2,à,3,á,4,â,5,ã,6,ä,7,å,8,æ,9,ç,0,è) }
alias -l decrypt { return $replace($1-,è,0,ç,9,æ,8,å,7,ä,6,ã,5,â,4,á,3,à,2,ß,1,Þ,;,Ý,:,ÿ,!,Ü,?,Û,z,Ú,y,Ù,x,Ö,w,Õ,v,Ô,u,ï,t,Ò,s,Ñ,r,Ð,q,Ï,p,Î,o,Í,n,Ì,m,Ë,l,É,k,È,j,ý,i,Æ,h,Å,g,Ä,f,Ã,e,Â,d,Á,c,À,b,Ç,a)  }

alias uscha {
  set %sm.unum $did(pmail,2).sel
  set %sm.user $did(pmail,2,$did(pmail,2).sel).text
  set %sm.pop3 $readini $smfile(profiles.sml) %sm.user pop3
  set %sm.login $readini $smfile(profiles.sml) %sm.user login
  set %sm.pass $readini $smfile(profiles.sml) %sm.user pass
  set %sm.smtp $readini $smfile(profiles.sml) %sm.user smtp
  set %sm.address $readini $smfile(profiles.sml) %sm.user address
  set %sm.check $readini $smfile(profiles.sml) %sm.user check
  set %sm.chkmin  $readini $smfile(profiles.sml) %sm.user chkmin
  set %sm.graphic $readini $smfile(profiles.sml) %sm.user graphic
  set %sm.nickname  $readini $smfile(profiles.sml) %sm.user nickname
  set %sm.sound $readini $smfile(profiles.sml) %sm.user sound  
  set %sm.sig $readini $smfile(profiles.sml) %sm.user signature
  set %sm.sigfile $readini $smfile(profiles.sml) %sm.user sigfile  
  set %sm.sndfile $readini $smfile(profiles.sml) %sm.user sndfile
  did -r pmail 5,7,9,11,13,27,33,35,36 
  did -u pmail 26,28,29,30,32
  did -a pmail 5 %sm.pop3
  did -a pmail 7 %sm.login
  did -a pmail 9 %sm.pass
  did -a pmail 11 %sm.smtp
  did -a pmail 13 %sm.address
  if (%sm.check == 1) { did -c pmail 26 | did -e pmail 27,28,30,36,37 }
  if (%sm.check == 0) { did -b pmail 27,28,30,36,37 }
  did -a pmail 27 %sm.chkmin
  if (%sm.graphic == 1) did -c pmail 28
  if (%sm.nickname == 1) did -c pmail 29
  if (%sm.sound == 1) did -c pmail 30  
  if (%sm.sig == 1) { did -c pmail 32 | did -e pmail 33,34,35 }
  if (%sm.sig == 0) { did -b pmail 33,34,35 }
  did -a pmail 33 %sm.sigfile
  did -a pmail 36 %sm.sndfile
  if ($exists(%sm.sigfile) == $true) filter -fo $smadd(%sm.sigfile) pmail 35
  if ($did(pmail,32).visible == $false) did -h pmail 35
  shab   
  if ($dialog(mail) == mail) { did -r mail 3 | smsgs }
}

alias auchk {
  set %mail.auchk 1
  sockopen mail %sm.pop3 110 
  sockmark mail get 1
}

alias aumail {  
  var %temp! $readini $smfile(profiles.sml) %sm.user new? 
  if (%temp! != $1 $2) {
    echo -a You have $1 new message(s)
    if (%sm.graphic == 1) { .timer 1 0 set %mail.draw 0 | .timerfred -m 0 500 damail }
    if (%sm.sound == 1) { .splay $smadd(%sm.sndfile) }
  }
  writeini $smfile(profiles.sml) %sm.user new? $1 $2
}

alias damail {
  if (%mail.draw == 0) { window -apk +b @mail 1 1 77 41 | drawpic @mail 0 0 $smfile(graphics\mail2.bmp) | set %mail.draw 1 | goto end }
  if (%mail.draw == 1) { window -apk +b @mail 1 1 77 41 | drawpic @mail 0 0 $smfile(graphics\mail3.bmp) | set %mail.draw 0 | goto end }
  :end
}

menu @mail {
  sclick: { .timerfred off | window -c @mail | unset %mail.draw }
}

alias addsig {
  if ($exists(%sm.sigfile) == $false) return
  var %sig.temp = $lines(%sm.sigfile)
  var %sig.temp2 = 1
  :addsig
  if (%sig.temp2 > %sig.temp) goto end
  var %sig.temp3 = $read -l $+ %sig.temp2 $smadd(%sm.sigfile)
  sockwrite -n send %sig.temp3
  inc %sig.temp2
  goto addsig
  :end
}

dialog aboutsm {
  title "About SilverMail"
  size -1 -1 200 115
  button ":(", 100, 390 290 1 1, cancel
  text "SilverMail 1.1 ALPHA", 1, 1 1 200 25
  text "By SilverSwd (silversword@pairc.com)", 2, 1 15 200 25
  text "http://silvrscript.hypermart.net", 3, 1 29 200 25
  box "Dedicated to:", 4, 1 45 197 65
  text "Rebecca Traylor", 5, 5 60 100 15
  text "Ryann Frye", 6, 5 75 100 15
  text "April Yamarino", 7, 5 90 100 15
}

menu menubar,status {
  SilverMail: smail
}

alias exab {  
  var %ab.file = $scriptdir $+ %sm.user $+ \abook.sml  
  if ($exists(%ab.file) != $true) { goto end }  
  var %ab.lines = $lines(%ab.file)
  var %ab.cur = 1
  :loop
  var %ab.temp = $read -l $+ %ab.cur $smadd(%ab.file)
  writeini $smadd($mircdiraddrbk.ini) $gettok($gettok(%ab.temp,2,159),1,32) email $gettok(%ab.temp,1,159)  
  inc %ab.cur
  if (%ab.cur > %ab.lines) goto end
  goto loop
  :end
}

alias inab {
  if ($exists($mircdiraddrbk.ini) != $true) { goto end }
  filter -ff $smadd($mircdiraddrbk.ini) $smfile(temp.sml) [*]
  var %inab.lines = $lines($scriptdirtemp.sml)
  var %inab.cur = 1
  :loop
  var %inab.temp = $read -l $+ %inab.cur $smfile(temp.sml)
  var %inab.temp = $remove(%inab.temp,[,])
  var %inab.temp1 = $readini $smadd($mircdiraddrbk.ini) %inab.temp email 
  write $smfile($smuser(abook)) %inab.temp1 $+ $chr(159) $+ %inab.temp
  if (%inab.lines = %inab.cur) goto end
  inc %inab.cur
  goto loop  
  :end
  shab
  .remove $smfile(temp.sml)
}

alias sadr {
  var %sadr.dir = $scriptdir $+ %sm.user $+ \drafts
  if ($isdir(%sadr.dir) != $true) .mkdir $smadd(%sadr.dir) 
  var %sadr.temp = $mailput(Save draft as?)
  var %1 = %sadr.dir $+ \ $+ %sadr.temp $+ .sml
  write $smadd(%1) $did(wmail,4)
  write $smadd(%1) $did(wmail,6)
  filter -if wmail 7 $smadd(%1)
}

alias opdr {
  did -r wmail 4,6,7
  window -h @opdr  
  var %opdr.dir = $smfile($smuser(drafts\*))
  var %opdr.temp = $dir="Open Draft" %opdr.dir
  did -a wmail 4 $read -l1 $smadd(%opdr.temp)
  did -a wmail 6 $read -l2 $smadd(%opdr.temp)
  filter -fw $smadd(%opdr.temp) @opdr 
  dline @opdr 1-2
  filter -wo @opdr wmail 7
  window -c @opdr
  dialog -v wmail wmail
}

alias -l loadvars {
  set %sm.unum $readini $smfile(profiles.sml) user number    
  set %sm.user $readini $smfile(profiles.sml) user current
  set %sm.pop3 $readini $smfile(profiles.sml) %sm.user pop3
  set %sm.login $readini $smfile(profiles.sml) %sm.user login
  set %sm.pass $readini $smfile(profiles.sml) %sm.user pass
  set %sm.smtp $readini $smfile(profiles.sml) %sm.user smtp
  set %sm.address $readini $smfile(profiles.sml) %sm.user address  
  set %sm.check $readini $smfile(profiles.sml) %sm.user check
  set %sm.chkmin  $readini $smfile(profiles.sml) %sm.user chkmin
  set %sm.graphic $readini $smfile(profiles.sml) %sm.user graphic
  set %sm.nickname  $readini $smfile(profiles.sml) %sm.user nickname
  set %sm.sound $readini $smfile(profiles.sml) %sm.user sound  
  set %sm.sndfile $readini $smfile(profiles.sml) %sm.user sndfile  
  set %sm.sig $readini $smfile(profiles.sml) %sm.user signature
  set %sm.sigfile $readini $smfile(profiles.sml) %sm.user sigfile  
}

alias -l smfile { return " $+ $scriptdir $+ $1 $+ " }
alias -l smuser { return %sm.user $+ \ $+ $1 $+ .sml }
alias -l smadd { return " $+ $1 $+ " }

alias -l bmpvert {
  var %1 = 1
  window -hp +b @1 1 1 52 41
  :1
  drawfill -r @1 $rgb(face) $rgb(0,1,0) 1 1
  var %2 = graphics\base $+ %1 $+ .bmp
  var %3 = graphics\bmail $+ %1 $+ .bmp
  drawpic -t @1 $rgb(157,185,200) 0 0 $smfile(%2) 
  drawsave @1 $smfile(%3)
  clear @1
  inc %1
  if (%1 > 10) {
    window -c @1
    return
  }
  goto 1
}

alias -l percent {
  if (($2 < 1) || ($2 !isnum)) return 100%
  if (($1 < 1) || ($1 !isnum)) return 0%
  return $round($calc($1 / $2 * 100),0) $+ $chr(37)
}

alias -l disfolder {
  did -r $1-
  did -a $1- Inbox
  did -a $1- Sent 
  var %1 = $scriptdir $+ $smuser(folders)
  if ($exists(%1) != $false) { filter -fo $smadd(%1) $1- } 
  did -c $1- 1
}

alias -l svsentmsg {
  var %msg.add = $did(wmail,4) $did(wmail,6)
  var %msg.hash = $hash(%msg.add,32)
  var %msg.file = $scriptdir $+ %sm.user $+ \sent\ $+ %msg.hash $+ .sml
  var %msg.file2 = $scriptdir $+ %sm.user $+ \sent\messages.sml
  write $smadd(%msg.file2) %msg.add $+ $chr(159) $+ %msg.hash
  write $smadd(%msg.file) From: %sm.address
  write $smadd(%msg.file) To: $did(wmail,4)
  write $smadd(%msg.file) Subject: $did(wmail,6)
  write $smadd(%msg.file) Date: $fulldate
  write $smadd(%msg.file) $chr(160)
  filter -if wmail 7 $smadd(%msg.file)
  if (%sm.sig == 1) filter -ff $smadd(%sm.sigfile) $smadd(%msg.file)
}

alias -l mailput {
  set %1 $1
  return $$dialog(mailput,mailput,-4)
}

dialog mailput {
  title "SilverMail Input"
  size -1 -1 210 47
  button "Ok", 1, 163 1 45 20, ok
  edit "", 2, 1 23 150 22, autohs, result, focus
  text "", 3, 2 5 160 12 
  button "Cancel", 4, 163 26 45 20, cancel
}

on *:dialog:mailput:init:0: { 
  did -a mailput 3 %1
  unset %1
}

dialog filesml {
  title "File Message"
  size -1 -1 182 47
  button "Ok", 1, 1 1 50 20, ok
  button "Edit Folders", 2, 56 1 70 20
  button "Cancel", 3, 131 1 50 20, cancel
  combo 4, 1 25 180 100, drop
}

on *:dialog:filesml:init:0: { disfolder filesml 4 }
on *:dialog:filesml:sclick:2: {
  if ($dialog(pmail)) { dialog -v pmail pmail }
  else { 
    dialog -md pmail pmail 
    .timer 1 0 shus 
    .timer 1 0 vh42
    .timer 1 0 shab  
    .timer -m 1 250 shpro 3
  }
}