alias get.address { return $readini($findfile($mm.folder $+ addresses,*.add,$1), $remove($findfile($mm.folder $+ addresses,*.add,$1),$mm.folder $+ addresses,.add,$chr(92)), $2)   }
alias addresses {
  var %in = 1
  :i
  did -a mail 29 1 $+($get.address(%in,E-Mail),$chr(9),$get.address(%in,Nick),$chr(9),$get.address(%in,Full)))
  inc %in
  goto e
  :e
  if ($get.address(%in,Nick)) { goto i } 
}
alias mm.get.lan { return $readini($mm.folder $+ languages.ini, %mm.lan.sel, $1) }
alias mmailer { if (!$dialog(load).table) && (!$dialog(mail).table)  { dialog -m load load } }
alias -l mm.s.time.bar { dec %mm.timeout | did -ri mail 12 4 $mm.get.lan(1) ( $+ %mm.timeout $+ ) }
alias -l s_ok { return }
alias mm.folder { return $scriptdirmailsys $+ $chr(92) } 
alias -l wdll { return $mircdir $+ $chr(92) $+ dll $+ $chr(92) $+ nhtmln.dll }
alias -l web.load {
  window -ph @load
  $dll($wdll,attach,$window(@load).hwnd)
  $dll($wdll,navigate, $+ $mm.folder $+ graphics $+ $chr(92) $+ load.html)
}

alias -l mdx_fullpath { return $+(",$mircdir $+ dll $+ $chr(92) $+ mdx.dll,") }
alias -l mdx { dll $mdx_fullpath $1- }
alias -l mdxinit {
  dll $mdx_fullpath SetMircVersion $version
  dll $mdx_fullpath MarkDialog $dname
}
alias mm.type {
  var %i = $calc($len($1-) + 1)
  var %x = 1
  $iif($dialog(mail),did -r mail 12)
  :go
  if (%x == $calc(%i - 1)) { .timer $+ $rand(0,10000) -m 1 $calc(%x * 60) $iif($dialog(mail),did -ri mail 12 4 $1-) }
  if (%x < %i) {
    var %txt = $left($1-,%x) $+ _
    .timer $+ $rand(0,10000) -m 1 $calc(%x * 60) $iif($dialog(mail),did -ri mail 12 4 %txt)
    inc %x
    goto go
  }
}
alias -l mm.cookies {
  var %t = 10
  var %r = 1 
  var %chk = 1
  :getcook
  if (%r < %t) {
    if ($readini($mm.folder $+ mailsys.ini, textmail, text $+ %r)) {
      did -a mail 4 $readini($mm.folder $+ mailsys.ini, textmail, text $+ %r)
    }
    if ($readini($mm.folder $+ mailsys.ini, textcc, text $+ %r)) {
      did -a mail 5 $readini($mm.folder $+ mailsys.ini, textcc, text $+ %r)
    }
    if ($readini($mm.folder $+ mailsys.ini, textsubject, text $+ %r)) {
      did -a mail 6 $readini($mm.folder $+ mailsys.ini, textsubject, text $+ %r)
    }
    inc %r
    goto getcook
  }
}
alias -l mm.msg {
  var %da = $date
  var %ti = $time
  var %mm = $did(mail,7).lines
  var %rl = 1
  var %nn = 3
  var %to = $replace(%mm.to,@,-arroba-)
  var %sub = %mm.sub
  $iif(%mm.snt.s == si, write $mm.folder $+ sent $+ $chr(92) $+ sent $+ $replace(%da,$chr(47),-) $+ _ $+ $replace(%ti,:,-) $+ .sent $+($chr(35),%ti,$chr(35),%da,$chr(35),%sub,$chr(35),%to))
  sockwrite -tn mail <HTML> 
  goto rr
  :rr
  if ($did(mail,7,%rl)) { sockwrite -tn mail $replace($did(mail,7,%rl),&b,<b>,&=b,</b>,&u,<u>,&=u,</u>,&i,<i>,&=i,</i>,&r,<FONT COLOR="#FF0000">,&=r,</FONT>,&l,<FONT COLOR="#0000FF">,&=l,</FONT>,&g,<FONT COLOR="#00FF00">,&=g,</FONT>,&y,<FONT COLOR="#FFFF00">,&=y,</FONT>) <BR> | $iif(%mm.snt.s == si, write $+(-l,%nn) $mm.folder $+ sent $+ $chr(92) $+ sent $+ $replace(%da,$chr(47),-) $+ _ $+ $replace(%ti,:,-) $+ .sent $did(mail,7,%rl)) }
  if (!$did(mail,7,%rl)) { sockwrite -tn mail <BR> | $iif(%mm.snt.s == si, write $+(-l,%nn) $mm.folder $+ sent $+ $chr(92) $+ sent $+ $replace(%da,$chr(47),-) $+ _ $+ $replace(%ti,:,-) $+ .sent &vinempty) }
  goto re  
  :re
  if (%rl < %mm) { inc %rl | inc %nn | goto rr }
  if (%rl == %mm) { 
    sockwrite -tn mail <BR>
    mm.enclose.sign
    sockwrite -tn mail <BR>   
    $iif(%enc.t == si, sockwrite -tn mail $time <BR>)
    $iif(%enc.d == si, sockwrite -tn mail $date <BR>)  
    sockwrite -tn mail </HTML> 
    sockwrite -tn mail .
    .timerinc off
    .timerinccm off
    .timerso off
    .timersc off
    sockwrite -tn mail quit
    mm.type Sent.    
    did -a mail 64 stop
    did -a mail 64 close 
    did -a mail 64 open $mm.folder $+ graphics $+ $chr(92) $+ wait.avi
    did -a mail 64 play  
    did -ra mail 112 100 0 100
    .timer 1 1 did -ra mail 112 0 0 100
    .timer 1 1 mm.type $mm.get.lan(2) 
    sockwrite -tn mail quit
    sockclose mail
    mm.mails
  }
}
alias -l mail { sockopen mail %sm.tp 25 }
alias -l sendmail { 
  sockwrite -tn mail ehlo %sm.tp
  sockwrite -tn mail auth login
  set %mm.chk.334 great
}
alias -l sendmail.ident { 
  unset %mm.chk.334
  sockwrite -tn mail $encode(%mm.us,m)
  sockwrite -tn mail $encode(%mm.ps,m)
}
alias -l send.end {
  .timerout off
  sockwrite -tn mail Mail From: $+ $iif($chr(64) !isin %mm.us, $+(%mm.us,$chr(64),$gettok(%mm.us,-2,46),$chr(46),$gettok(%mm.us,-1,46)), %mm.us)
  sockwrite -tn mail Rcpt to: $+ %mm.to
  sockwrite -tn mail Data  
  sockwrite -tn mail Cc: $+ %mm.cc 
  sockwrite -tn mail Subject: %mm.sub
  mm.msg
}
alias -l time.o.ut { sockclose mail | .timer 1 1 did -ra mail 12 4 $mm.get.lan(2) | did -ra mail 112 0 0 100 | mm.type $mm.get.lan(3) | did -a mail 64 close | did -a mail 64 open $mm.folder $+ graphics $+ $chr(92) $+ wait.avi | did -a mail 64 play  }
on 1:sockread:mail:{
  sockread %temp
  tokenize 32 %temp
  $iif($dialog(mm_console).table, did -i mm_console 1 1 %temp) 
  if ($1 == 220) { sendmail }
  if ($1 == 334) && (%mm.chk.334) { sendmail.ident }
  if ($1 == 421) { time.o.ut }
  if ($1 == 501) || ($1 == 535) || ($1 == 500) { .timersc off | .timerso off | sockclose mail | .timerinc off | .timerinccm off | .timerout off | mm.type Error! Incorrect login. | did -ra mail 112 0 0 100 | did -a mail 64 close | did -a mail 64 open $mm.folder $+ graphics $+ $chr(92) $+ wait.avi | did -a mail 64 play  }
  if ($1 == 235) { send.end }
}
alias -l mm.load.ing {
  dialog -x load
  window -c @load 
  dialog -md mail mail
}
on 1:dialog:mail:*:*:{
  if ($devent == menu) {
    if ($did == 16) { dialog -c mail }
  }
  if ($devent == init) {
    $iif(%mm.snt.s == si, did -c $dname 35, did -u $dname 35)
    $iif(%enc.d == si, did -c $dname 24, did -u $dname 24)
    $iif(%enc.t == si, did -c $dname 26, did -u $dname 26)
    $iif(%mm.aut.chk == si, did -c $dname 101, did -u $dname 101)
    if (%mm.auto.chk == si) { pop3 }
    mdxinit  
    mm.font
    did -ra mail 86,88,89 -
    mdx SetControlMDX 91 window > $mm.folder $+ dll $+ $chr(92) $+ dialog.mdx   
    web.pop
    did -ra mail 91 grab $window(@pop).hwnd @pop
    mdx SetColor $dname 48 background $rgb(255,255,255) 
    mdx SetColor $dname 48 textbg $rgb(255,255,255)   
    mdx SetColor $dname 48 text $rgb(0,0,0)   
    mdx SetControlMDX $dname 48 richedit multi read result > $mm.folder $+ dll $+ $chr(92) $+ ctl_gen.mdx
    did -i $dname 48 1 text +m &b - Bold Text ; &=b - Bold Text Disable .                                    
    did -i $dname 48 1 text +m &u - Underlined Text ; &=u - Underlined Text Disable .
    mdx SetControlMDX $dname 64,55 animation center transparent > $mm.folder $+ dll $+ $chr(92) $+ ctl_gen.mdx 
    mdx SetControlMDX $dname 12 StatusBar sizeGrip > $mm.folder $+ dll $+ $chr(92) $+ bars.mdx
    mdx SetBorderStyle $dname 12 windowedge
    mdx SetControlMDX $dname 112 ProgressBar > $mm.folder $+ dll $+ $chr(92) $+ ctl_gen.mdx
    mdx SetControlMDX $dname 75 ListView report checkboxes oneclick rowselect headerdrag > $mm.folder $+ dll $+ $chr(92) $+ views.mdx 
    mdx SetControlMDX $dname 29,54 ListView report rowselect grid headerdrag > $mm.folder $+ dll $+ $chr(92) $+ views.mdx  
    mdx SetColor $dname 73,68,69,25,16 background $rgb(255,255,255) 
    mdx SetColor $dname 73,68,69,25,16 textbg $rgb(255,255,255)    
    mdx SetBorderStyle 8
    mdx SetControlMDX 8 toolbar arrows flat nodivider noresize > $mm.folder $+ dll $+ $chr(92) $+ bars.mdx
    did -a $dname 107 English
    did -a $dname 107 Deutsch
    did -i $dname 8 1 bmpsize 32 32 
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ mail.ico
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ save.ico
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ load.ico
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ copy.ico
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ paste.ico
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ delete.ico
    did -i $dname 8 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ console.ico
    did -a $dname 8 1 $mm.get.lan(11) $chr(9) $+ $mm.get.lan(10)  
    did -a $dname 8 -
    did -a $dname 8 2 $mm.get.lan(12) $chr(9) $+ $mm.get.lan(4) 
    did -a $dname 8 3 $mm.get.lan(13) $chr(9) $+ $mm.get.lan(5) 
    did -a $dname 8 -
    did -a $dname 8 4 $mm.get.lan(14) $chr(9) $+ $mm.get.lan(6) 
    did -a $dname 8 5 $mm.get.lan(15) $chr(9) $+ $mm.get.lan(7) 
    did -a $dname 8 -
    did -a $dname 8 6 $mm.get.lan(16) $chr(9) $+ $mm.get.lan(8)
    did -a $dname 8 -
    did -a $dname 8 7 $mm.get.lan(17) $chr(9) $+ $mm.get.lan(9)
    mdx SetBorderStyle 1,2,10,13,70,74
    mdx SetControlMDX 1,2,10,13,70,74 toolbar arrows flat list nodivider noresize > $mm.folder $+ dll $+ $chr(92) $+ bars.mdx
    did -i $dname 1 1 bmpsize 16 15
    did -i $dname 1 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ icon.bmp
    did -a $dname 1 1 $mm.get.lan(84)
    did -i $dname 2 1 bmpsize 16 15
    did -i $dname 2 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ icon.bmp
    did -a $dname 2 1 Cc:
    did -i $dname 10 1 bmpsize 16 15
    did -i $dname 10 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ red.bmp
    did -a $dname 10 1 $mm.get.lan(22) $chr(9) $+ $mm.get.lan(18)
    did -i $dname 13 1 bmpsize 16 15
    did -i $dname 13 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ blue.bmp
    did -a $dname 13 1 $mm.get.lan(23) $chr(9) $+ $mm.get.lan(19)
    did -i $dname 70 1 bmpsize 16 15
    did -i $dname 70 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ green.bmp
    did -a $dname 70 1 $mm.get.lan(24) $chr(9) $+ $mm.get.lan(20)
    did -i $dname 74 1 bmpsize 16 15
    did -i $dname 74 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ yellow.bmp
    did -a $dname 74 1 $mm.get.lan(25) $chr(9) $+ $mm.get.lan(21)
    did -i $dname 58 1 setimage +nhd 0 icon large $mm.folder $+ graphics $+ $chr(92) $+ under.bmp
    did -a $dname 58 1 $chr(9) $+ Insert Underline HTML variable
    did -a $dname 112 BarColor $rgb(0,0,255)    
    did -i $dname 12 1 setparts 30 30 -1    
    did -i $dname 75 1 headerdims 180:1 210:2 110:3 
    did -i $dname 75 1 headertext 0 $+($mm.get.lan(26),$chr(9),$mm.get.lan(27),$chr(9),$mm.get.lan(28)) 
    did -i $dname 54 1 headerdims 110:1 110:2 255:3 
    did -i $dname 54 1 headertext 0 $+($mm.get.lan(29),$chr(9),$mm.get.lan(30),$chr(9),$mm.get.lan(31)) 
    did -i $dname 29 1 headerdims 150:1 110:2 210:3 
    did -i $dname 29 1 headertext 0 $+($mm.get.lan(32),$chr(9),$mm.get.lan(33),$chr(9),$mm.get.lan(34))  
    did -a $dname 64 open $mm.folder $+ graphics $+ $chr(92) $+ wait.avi
    did -a $dname 64 play 
    mdx SetControlMDX mail 27 treeview haslines  linesatroot  > $mm.folder $+ dll $+ $chr(92) $+ views.mdx  
    did -i $dname 27 1 iconsize normal small
    did -i $dname 27 1 dragmethod copy move link
    did -i $dname 27 1 seticon normal $mm.folder $+ graphics $+ $chr(92) $+ right.ico
    did -i $dname 27 1 seticon normal $mm.folder $+ graphics $+ $chr(92) $+ down.ico
    did -i $dname 27 1 cb root 
    did -a $dname 27 +be 1 1 2 1 0 $mm.get.lan(35) 
    did -i $dname 27 1 cb last
    did -a $dname 27 +ie 1 2 $mm.get.lan(36) 
    did -i $dname 27 1 b last
    did -a $dname 27 +e 1 2 $mm.get.lan(37) 
    did -i $dname 27 1 cb root
    did -a $dname 27 +be 1 2 0 2 0 $mm.get.lan(38) 
    did -i $dname 27 1 cb last
    did -a $dname 27 +ie 1 2 $mm.get.lan(39) 
    did -i $dname 27 1 cb root
    did -a $dname 27 +be 1 2 0 2 0 $mm.get.lan(40)
    did -i $dname 27 1 cb root
    did -a $dname 27 +be 1 2 0 2 0 $mm.get.lan(41) 
    did -i $dname 27 1 cb root
    did -a $dname 27 +be 1 2 $mm.get.lan(42) 
    addresses  
    mm.style.off
    mm.mails
    mm.type $mm.get.lan(2)
    mm.cookies
    mm.l.sign   
    did -ra $dname 39 %sm.tp
    did -ra $dname 40 %mm.us
    did -ra $dname 41 %mm.ps
    did -ra $dname 99 %pop.serv
    did -ra $dname 98 %pop.us
    did -ra $dname 97 %pop.ps
  }
  if ($devent == sclick) {
    if ($did == 107) { 
      if ($did(107).text == Deutsch) { set %mm.lan.sel 2 }
      if ($did(107).text == English) { set %mm.lan.sel 1 }
      dialog -c mail
      dialog -m mail mail
    }
    if ($did == 92) { pop3 }
    if ($did == 1) { did -f mail 49 }
    if ($did == 2) { did -f mail 49 }
    if ($did == 7) { 
      set %sm.tp $did(39).text
      set %mm.us $did(40).text
      set %mm.ps $did(41).text
      set %pop.serv $did(99).text
      set %pop.us $did(98).text
      set %pop.ps $did(97).text
    }
    if ($did == 8) {
      if ($did(8).sel == 4) { 
        if ($did(7).text) {
          sav.msg $dll($scriptdirmailsys\dll\EDialogs.dll,EDlg,Smails>eMail - %bsver - Speicher eMail>|eMail Dateien (*.mail)|*.mail;*.txt>y)
        }
      }
      if ($did(8).sel == 5) { read.msg $dll($scriptdirmailsys\dll\EDialogs.dll,EDlg,omails>eMail - %bsver - eMail Auswahl>|eMail Dateien (*.mail)|*.mail;*.txt>y) }
      if ($did(8).sel == 7) && ($did(7).seltext) { clipboard $did(7).seltext | writeini $mm.folder $+ mailsys.ini system copytext $did(7).seltext | did -f mail 7 }
      if ($did(8).sel == 8) { did -a $dname 7 $readini($mm.folder $+ mailsys.ini, system, copytext) | did -f mail 7 }
      if ($did(8).sel == 10) { did -r mail 7 | did -f mail 7 }   
      if ($did(8).sel == 12) { $iif(!$dialog(mm_console).table,dialog -md mm_console mm_console), dialog -x mm_console }
    }  
    if ($did == 8) && ($did(8).sel == 2) && (!$sock(mail).status) {
      if (!%sm.tp) { mm.type $mm.get.lan(43) }
      if (!%mm.us) { mm.type $mm.get.lan(44) }
      if (!%mm.ps) { mm.type $mm.get.lan(45) }
      if (!$did(7).text) && ($did(4).text) { mm.type $mm.get.lan(46)  }
      if (!$did(4).text) || ($chr(64) !isin $did(4).text) || ($chr(46) !isin $did(4).text) { mm.type $mm.get.lan(47) }
      if (%sm.tp) && (%mm.us) && (%mm.ps) && ($did(7).text) { 
        set %mm.to $did(4).text
        set %mm.cc $did(5).text
        set %mm.sub $did(6).text
        mail      
        unset %incline 
        did -ra mail 112 0 0 100
        did -ra mail 12
        .timerout 1 41 time.o.ut
        set %incline 0
        .timerinccm 5 1 incline
        did -a mail 64 close
        did -a $dname 64 open $mm.folder $+ graphics $+ $chr(92) $+ send.avi
        did -a $dname 64 play 
        set %mm.timeout 30
        .timersc 10 1 .timerso 30 1 mm.s.time.bar
        mm.add.cook.mail
        mm.add.cook.cc
        mm.add.cook.sub
      }
    }    
    if ($did == 24) { 
      if ($did(24).state == 0) { mm.did.24 }
      if ($did(24).state == 1) { mm.didnt.24 }
    } 
    if ($did == 26) { 
      if ($did(26).state == 0) { mm.did.26 }
      if ($did(26).state == 1) { mm.didnt.26 }
    }
    if ($did == 101) { 
      if ($did(101).state == 0) { mm.did.101 }
      if ($did(101).state == 1) { mm.didnt.101 }
    }
    if ($did == 27) {
      tokenize 32 $did($dname,$did,1)
      if ($1 == slclick) {
        if ($4 == 2) { 
          if ($5 == 2) { did -f mail 17 | mm.type $mm.get.lan(36)  }
          if ($5 == 3) { did -f mail 19  | mm.type $mm.get.lan(37) }
        }
        if ($4 == 3) {
          if ($5 == 2) { did -f mail 65 | mm.type $mm.get.lan(39) }
        }
        if ($4 == 4) { did -f mail 49 | mm.type $mm.get.lan(40) }
        if ($4 == 5) { did -f mail 46 | mm.type $mm.get.lan(41) }
        if ($4 == 6) { did -f mail 18 | mm.type $mm.get.lan(42) }
      }
    }
    if ($did == 28) {
      set %sm.tp $did(39).text
      set %mm.us $did(40).text
      set %mm.ps $did(41).text    
      set %pop.serv $did(99).text
      set %pop.us $did(98).text
      set %pop.ps $did(97).text
      mm.s.sign  
      mm.type $mm.get.lan(48)
    }
    if ($did == 30) {
      if ($exists($mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add) == $false) {
        if ($did(42).text) && ($did(43).text) && ($did(44).text) {
          writeini $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add $did(43).text E-Mail $did(42).text
          writeini $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add $did(43).text Nick $did(43).text
          writeini $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add $did(43).text Full $did(44).text
          did -i mail 29 $did(29).lines $+($did(42).text,$chr(9),$did(43).text,$chr(9),$did(44).text)
          mm.type Created: $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add      
          did -r mail 42,43,44      
          did -r mail 29 
          addresses    
        }
        else { mm.type $mm.get.lan(49) }
      }
      else { mm.type $mm.get.lan(50) }
    }
    if ($did == 31) { 
      catch.it $remove($did(29).seltext,$chr(9),$+(+fs,$chr(32),0,$chr(32),0,$chr(32),0))
      did -r mail 42,43,44   
      did -r mail 29 
      addresses  
    }
    if ($did == 32) {
      if ($exists($mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add) == $true) {
        if ($did(29).sel) {        
          if ($did(42).text) && ($did(43).text) && ($did(44).text) {
            writeini $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add $did(43).text E-Mail $did(42).text
            writeini $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add $did(43).text Nick $did(43).text
            writeini $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add $did(43).text Full $did(44).text
            did -d mail 29 $did(29).sel
            did -a mail 29 $did(29).sel $+($did(42).text,$chr(9),$did(43).text,$chr(9),$did(44).text)
            mm.type $mm.get.lan(51) $mm.folder $+ addresses $+ $chr(92) $+ $did(43).text $+ .add         
            did -r mail 42,43,44  
            did -r mail 29 
            addresses          
          }
          else { mm.type $mm.get.lan(52) }
        }
        else { mm.type $mm.get.lan(53) }
      }
    }
    if ($did == 35) { 
      if ($did(35).state == 0) { mm.did.35 } 
      if ($did(35).state == 1) { mm.didnt.35 }
    }
    if ($did == 45) { $iif($did(42).text, mm.clp, mm.type $mm.get.lan(54) ) }
    if ($did == 52) { $iif(!%mm.bold, mm.bold.on, mm.bold.off) | did -f mail 7  }
    if ($did == 59) { $iif(!%mm.und, mm.und.on, mm.und.off) | did -f mail 7 }
    if ($did == 58) { $iif(!%mm.ita, mm.ita.on, mm.ita.off) | did -f mail 7 }
    if ($did == 62) {
      did -r mail 4,5,6
      mm.type $mm.get.lan(55)
      .timere 1 2 mm.type $mm.get.lan(2)
      remini $mm.folder $+ mailsys.ini textmail
      remini $mm.folder $+ mailsys.ini textcc
      remini $mm.folder $+ mailsys.ini textsubject
    }
    if ($did == 10) { $iif(!%mm.red, mm.red.on, mm.red.off) | did -f mail 7 }
    if ($did == 71) { if ($did(54).seltext) { remove.it $remove($did(54).seltext,$chr(9),$+(+fs,$chr(32),0,$chr(32),0,$chr(32),0))) | did -r mail 68,69,73,16,25 } }
    if ($did == 72) { did -r mail 68,69,73 | mm.l.sent.click $remove($did(54).seltext,$chr(9),$+(+fs,$chr(32),0,$chr(32),0,$chr(32),0)) }
    if ($did == 13) { $iif(!%mm.blue, mm.blue.on, mm.blue.off) | did -f mail 7 }
    if ($did == 70) { $iif(!%mm.green, mm.green.on, mm.green.off) | did -f mail 7 }
    if ($did == 74) { $iif(!%mm.yellow, mm.yellow.on, mm.yellow.off) | did -f mail 7 }

    if ($did == 75) && ($did(75).sel) { $dll($wdll,navigate, $+ $findfile($scriptdirmailsys $+ $chr(92) $+ temp,*.html,$calc($did(75).sel - 1))) | did -ra mail 86 $iif($chr(64) !isin %pop.us, $+(%pop.us,$chr(64),$gettok(%pop.us,-2,46),$chr(46),$gettok(%pop.us,-1,46)), %pop.us) | did -ra mail 88 $remove($gettok($mm.get.pop($calc($did(75).sel - 1)),1,9),<,!,--,/,>) | did -ra mail 89 $remove($gettok($mm.get.pop($calc($did(75).sel - 1)),2,9),<,!,-,/,>) }
    if ($did == 75) && (!$did(75).sel) { $dll($wdll,navigate, $+ $mm.folder $+ graphics $+ $chr(92) $+ nomsg.html) | did -ra mail 86 - | did -ra mail 88 - | did -ra mail 89 -  }
    if ($did == 82) { url vitboy@hotmail.com?subject=Contact }
    if ($did == 83) { url http://usuarios.lycos.es/mircscripts }
    if ($did == 102) { 
      if (%pop.sel) {
        sockopen pop.r %pop.serv 110
      }
    }
    if ($did == 75) { 
      tokenize 32 $did($dname,$did,1)
      if ($1 == stateclick) { pop.sel $mdx-info($dname,$did).event }
    }
  }
  if ($devent == menu) {  
    if ($did == 34) { dialog -c mail }  
  }
  if ($devent == dclick) {
    if ($did == 29) { get.it 29 $remove($did(29).seltext,$chr(9),$+(+fs,$chr(32),0,$chr(32),0,$chr(32),0)) }
    if ($did == 54) { get.it 54 $remove($did(54).seltext,$chr(9),$+(+fs,$chr(32),0,$chr(32),0,$chr(32),0)) | mm.l.sent $remove($did(54).seltext,$chr(9),$+(+fs,$chr(32),0,$chr(32),0,$chr(32),0)) }
  }
}

alias -l mm.clp { clipboard $did(mail,42).text | mm.type $mm.get.lan(56) $did(mail,42).text }
alias -l catch.it {
  if ($3) {
    did -d mail 29 $did(mail,29).sel
    .remove $mm.folder $+ addresses $+ $chr(92) $+ $3 $+ .add
    mm.type $mm.get.lan(57) $mm.folder $+ addresses $+ $chr(92) $+ $3 $+ .add  
  }
  else { mm.type $mm.get.lan(58) }
}  
alias -l sav.msg {
  if ($1) {
    mm.type $mm.get.lan(51) $1 $+ .mail
    var %m = $calc($did(mail,7).lines + 1)
    var %r = 1
    :rr
    if (%m > %r) {
      if (!$did(mail,7,%r)) { write $1 &vinempty }
      if ($did(mail,7,%r)) { write $1 $+ .mail $did(mail,7,%r) }
      inc %r      
      goto rr
    }
  }
}
alias -l read.msg {
  mm.type $mm.get.lan(59) $1
  did -r mail 7
  var %pi = 1
  goto go
  :go
  if ($calc($lines($1) + 1) > %pi) {
    if ($read($1,%pi)) && ($read($1,%pi) != &vinempty)  {
      did -i mail 7 %pi $read($1,%pi)
    }
    if ($read($1,%pi) == &vinempty) {
      did -i mail 7 %pi $chr(32)
    }
    inc %pi
    goto go
  }
}
alias -l remove.it {
  .remove $mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent))
  mm.mails
}
alias -l get.it { 
  if ($1 == 29) {
    did -ra mail 42 $3
    did -ra mail 43 $4
    did -ra mail 44 $5-
    mm.type Selected: $3 - $4 - $5-
  }
  if ($1 == 54) {
    did -ra mail 68 $gettok($read($5,1),2,35)
    did -ra mail 69 $gettok($read($5,1),1,35)
    did -ra mail 25 $replace($gettok($read($5,1),3,35),-arroba-,@)
    did -ra mail 16 $replace($gettok($read($5,1),4-,35),-arroba-,@)
    mm.type Selected: $gettok($read($5,1),2,35) - $gettok($read($5,1),1,35)
  }
}
alias -l get.mails { return $findfile($mm.folder $+ sent,*.sent,$1)   }
alias -l mm.mails {
  did -r mail 54
  var %in = 1
  :i
  did -a mail 54 1 $+($gettok($read($get.mails(%in),1),2,35),$chr(9),$gettok($read($get.mails(%in),1),1,35),$chr(9),$get.mails(%in)))
  inc %in
  goto e
  :e
  if ($get.mails(%in)) { goto i } 
}
alias -l incline { 
  inc %incline $rand(10,20)
  did -ra mail 112 %incline 0 100
  did -oi mail 12 2,4 %incline $+ $chr(37) 
}
alias -l mailsys_img { return $mm.folder $+ graphics $+ $chr(92) $+ load.png }
alias -l mm.enclose.sign {
  var %g = $lines($mm.folder $+ sign)
  var %t = 0
  :l
  if (%t != %g) {
    sockwrite -tn mail $read($mm.folder $+ sign,%t) <BR>
    inc %t
    goto l
  }
}
alias -l mm.l.sign {
  var %g = $calc($lines($mm.folder $+ sign) + 1)
  var %t = 1
  :l
  if (%t != %g) {
    did -i mail 22 %t $read($mm.folder $+ sign,%t)
    inc %t
    goto l
  }
}
alias -l mm.s.sign {
  var %g = $calc($did(mail,22).lines + 1)
  var %t = 1
  .remove $mm.folder $+ sign
  :l
  if (%t != %g) {
    write -il $+ %t $mm.folder $+ sign $did(mail,22,%t).text
    inc %t
    goto l
  }
}
alias -l mm.add.cook.mail {
  var %t = 1
  :go
  if (%t < 5) {
    if ($did(mail,4).text !iswm $readini($mm.folder $+ mailsys.ini, textmail, text $+ 1)) && ($did(mail,4).text !iswm $readini($mm.folder $+ mailsys.ini, textmail, text $+ 2)) && ($did(mail,4).text !iswm $readini($mm.folder $+ mailsys.ini, textmail, text $+ 3)) && ($did(mail,4).text !iswm $readini($mm.folder $+ mailsys.ini, textmail, text $+ 4)) && ($did(mail,4).text !iswm $readini($mm.folder $+ mailsys.ini, textmail, text $+ 5)) {
      if (!$readini($mm.folder $+ mailsys.ini, textmail, text $+ %t)) {  
        did -a mail 4   $did(mail,4).text      
        writeini $mm.folder $+ mailsys.ini textmail text $+ %t $did(mail,4).text 
        break    
      }
      else {
        inc %t 
        goto go 
      }
    }
    if (%t == 5) {
      did -a mail 4 $did(mail,4).text      
      writeini $mm.folder $+ mailsys.ini textmail text $+ %t $did(mail,4).text
      break  
    }
  }
}
alias -l mm.add.cook.cc {
  var %c = 1
  :go
  if ($did(mail,5).text) {
    if (%c < 5) {
      if ($did(mail,5).text !iswm $readini($mm.folder $+ mailsys.ini, textcc, text $+ 1)) && ($did(mail,5).text !iswm $readini($mm.folder $+ mailsys.ini, textcc, text $+ 2)) && ($did(mail,5).text !iswm $readini($mm.folder $+ mailsys.ini, textcc, text $+ 3)) && ($did(mail,5).text !iswm $readini($mm.folder $+ mailsys.ini, textcc, text $+ 4)) && ($did(mail,5).text !iswm $readini($mm.folder $+ mailsys.ini, textcc, text $+ 5)) {
        if (!$readini($mm.folder $+ mailsys.ini, textcc, text $+ %c)) {
          did -a mail 5   $did(mail,5).text      
          writeini $mm.folder $+ mailsys.ini textcc text $+ %c $did(mail,5).text 
          break    
        }
        else {
          inc %c 
          goto go 
        }
      }
      if (%c == 5) {
        did -a mail 5 $did(mail,5).text      
        writeini $mm.folder $+ mailsys.ini textcc text $+ %c $did(mail,5).text
        break  
      }
    }
  }
}
alias -l mm.add.cook.sub {
  var %s = 1
  :go
  if (%s < 5) {
    if ($did(mail,6).text !iswm $readini($mm.folder $+ mailsys.ini, textsubject, text $+ 1)) && ($did(mail,6).text !iswm $readini($mm.folder $+ mailsys.ini, textsubject, text $+ 2)) && ($did(mail,6).text !iswm $readini($mm.folder $+ mailsys.ini, textsubject, text $+ 3)) && ($did(mail,6).text !iswm $readini($mm.folder $+ mailsys.ini, textsubject, text $+ 4)) && ($did(mail,6).text !iswm $readini($mm.folder $+ mailsys.ini, textsubject, text $+ 5)) {
      if (!$readini($mm.folder $+ mailsys.ini, textsubject, text $+ %s)) {
        did -a mail 6   $did(mail,6).text      
        writeini $mm.folder $+ mailsys.ini textsubject text $+ %s $did(mail,6).text 
        break    
      }
      else {
        inc %s
        goto go 
      }
    }
    if (%t == 5) {
      did -a mail 6 $did(mail,6).text      
      writeini $mm.folder $+ mailsys.ini textmail text $+ %s $did(mail,6).text
      break  
    }
  }
}
alias -l mm.l.sent {
  did -r mail 73
  var %g = $calc($lines($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent)) + 1)
  var %t = 2
  var %r = 1
  :l
  if (%r != %g) {
    if ($read($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent),%t) == &vinempty) {
      did -i mail 73 %r $chr(32)
      inc %t
      inc %r
      goto l
    }
    if ($read($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent),%t) != &vinempty) {
      did -i mail 73 %r $read($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent),%t)
      inc %t
      inc %r
      goto l
    }
  }
}
alias -l mm.l.sent.click {
  did -r mail 7
  var %g = $calc($lines($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent)) + 1)
  var %t = 2
  var %r = 1
  :l
  if (%r != %g) {
    if ($read($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent),%t) == &vinempty) {
      did -i mail 7 %r $chr(32)
      inc %t
      inc %r
      goto l
    }
    if ($read($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent),%t) != &vinempty) {
      did -i mail 7 %r $read($mm.folder $+ sent $+ $chr(92) $+ $+(sent,$replace($2,/,-),_,$replace($3,:,-),.sent),%t)
      inc %t
      inc %r
      goto l
    }
  }
}
alias -l mm.font {
  var %h = 1
  :i
  if (%h < 200) {
    mdx SetFont mail %h +a 13 400 Tahoma
    inc %h
    goto i
  }
}
alias -l mm.style.off { unset %mm.bold %mm.und %mm.ita %mm.red %mm.blue %mm.green %mm.yellow }
alias -l mm.bold.on { did -a $dname 7 &b | set %mm.bold on }
alias -l mm.bold.off { did -a $dname 7 &=b | unset %mm.bold }
alias -l mm.und.on { did -a $dname 7 &u | set %mm.und on }
alias -l mm.und.off { did -a $dname 7 &=u | unset %mm.und }
alias -l mm.ita.on { did -a $dname 7 &i | set %mm.ita on }
alias -l mm.ita.off { did -a $dname 7 &=i | unset %mm.ita }
alias -l mm.red.on { did -a $dname 7 &r | set %mm.red on }
alias -l mm.red.off { did -a $dname 7 &=r | unset %mm.red }
alias -l mm.blue.on { did -a $dname 7 &l | set %mm.blue on }
alias -l mm.blue.off { did -a $dname 7 &=l | unset %mm.blue }
alias -l mm.green.on { did -a $dname 7 &g | set %mm.green on }
alias -l mm.green.off { did -a $dname 7 &=g | unset %mm.green }
alias -l mm.yellow.on { did -a $dname 7 &y | set %mm.yellow on }
alias -l mm.yellow.off { did -a $dname 7 &=y | unset %mm.yellow }
alias -l mm.did.24 { set %enc.d no | did -u $dname 24 }
alias -l mm.didnt.24 { set %enc.d si | did -c $dname 24 }
alias -l mm.did.26 { set %enc.t no | did -u $dname 26 }
alias -l mm.didnt.26 { set %enc.t si | did -c $dname 26 }
alias -l mm.did.35 { set %mm.snt.s no | did -u $dname 35 }
alias -l mm.didnt.35 { set %mm.snt.s si | did -c $dname 35 }
alias -l mm.did.101 { set %mm.auto.chk no | did -u $dname 101 }
alias -l mm.didnt.101 { set %mm.auto.chk si | did -c $dname 101 }
dialog mail {
  title eMail - %bsver
  size -1 -1 330 267
  option dbu
  icon $mm.folder $+ graphics $+ $chr(92) $+ mail.ico, 0
  list 12, 58 257 272 10, disable size
  tab "Senden", 17, 73 -19 258 288
  text  $+ $mm.get.lan(60) $+ , 3, 85 65 21 8, tab 17 right
  edit "", 7, 82 88 243 134, group tab 17 multi return autovs vsbar
  combo 4, 107 40 216 50, tab 17 size edit drop
  combo 5, 107 52 216 50, tab 17 size edit drop
  combo 6, 107 64 216 50, tab 17 size edit drop
  button "", 64, 120 225 169 30, tab 17
  list 8, 83 7 240 32, tab 17 size
  list 1, 81 40 25 12, tab 17 size
  list 2, 81 52 25 12, tab 17 size
  list 10, 205 76 30 12, tab 17 size
  list 13, 235 76 30 12, tab 17 size
  list 70, 265 76 30 12, tab 17 size
  list 74, 295 76 30 12, tab 17 size
  icon 52, 83 77 28 10,  $mm.folder $+ graphics $+ $chr(92) $+ bold.bmp, 0, tab 17 noborder
  icon 59, 147 77 28 10,  $mm.folder $+ graphics $+ $chr(92) $+ under.bmp, 0, tab 17 noborder
  icon 58, 115 77 28 10,  $mm.folder $+ graphics $+ $chr(92) $+ italic.bmp, 0, tab 17 noborder
  tab  $+ $mm.get.lan(42) $+ , 18
  edit "", 22, 79 132 247 108, tab 18 multi return autohs autovs
  text  $+ $mm.get.lan(61) $+ , 38, 85 53 31 8, tab 18 right
  text  $+ $mm.get.lan(62) $+ , 37, 86 40 30 8, tab 18 right
  text  $+ $mm.get.lan(63) $+ , 36, 82 27 34 8, tab 18 right
  edit "", 39, 117 26 90 10, tab 18 multi return autohs
  edit "", 40, 117 39 90 10, group tab 18 multi autohs
  edit "", 41, 117 52 90 10, group tab 18 pass autohs
  button  $+ $mm.get.lan(64) $+ , 62, 296 91 23 10, tab 18
  button  $+ $mm.get.lan(65) $+ , 28, 286 244 41 11, tab 18
  check "", 26, 295 43 23 10, group tab 18
  check "", 24, 295 29 23 10, group tab 18
  check "", 35, 295 57 23 10, group tab 18
  check "", 101, 295 74 23 10, group tab 18
  text  $+ $mm.get.lan(66) $+ , 61, 251 92 43 8, tab 18 right
  text  $+ $mm.get.lan(67) $+ , 21, 245 44 48 8, tab 18 right
  text  $+ $mm.get.lan(68) $+ , 20, 245 30 48 8, tab 18 right
  text  $+ $mm.get.lan(69) $+ , 23, 243 58 50 8, tab 18 right
  text  $+ $mm.get.lan(70) $+ , 56, 80 125 25 8, tab 18
  box  $+ $mm.get.lan(71) $+ , 51, 80 5 130 116, tab 18
  text  $+ $mm.get.lan(72) $+ , 57, 124 15 41 8, tab 18 center
  text  $+ $mm.get.lan(73) $+ , 100, 224 72 69 14, tab 18 right
  text  $+ $mm.get.lan(74) $+ , 93, 125 68 41 8, tab 18 center
  text  $+ $mm.get.lan(75) $+ , 94, 82 81 34 8, tab 18 right
  edit "", 99, 117 80 90 10, tab 18 multi return autohs
  text  $+ $mm.get.lan(76) $+ , 95, 86 94 30 8, tab 18 right
  edit "", 98, 117 93 90 10, group tab 18 multi autohs
  text  $+ $mm.get.lan(77) $+ , 96, 85 107 31 8, tab 18 right
  edit "", 97, 117 106 90 10, group tab 18 pass autohs
  tab  $+ $mm.get.lan(78) $+ , 19
  list 54, 85 9 236 86, tab 19 size
  text  $+ $mm.get.lan(79) $+ , 66, 94 139 14 8, tab 19 right
  edit "", 68, 109 138 69 10, result tab 19 read
  button  $+ $mm.get.lan(64) $+ , 71, 284 96 37 11, tab 19
  edit "", 69, 202 138 69 10, result tab 19 read
  text  $+ $mm.get.lan(80) $+ , 67, 186 139 15 8, tab 19 right
  button  $+ $mm.get.lan(81) $+ , 72, 245 96 37 11, tab 19
  edit "", 73, 85 149 236 102, group result tab 19 read multi return autovs vsbar
  box  $+ $mm.get.lan(82) $+ , 60, 82 2 243 108, tab 19
  box  $+ $mm.get.lan(83) $+ , 63, 82 111 243 144, tab 19
  text  $+ $mm.get.lan(84) $+ , 11, 95 119 13 8, tab 19 right
  edit "", 16, 109 118 211 10, result tab 19 read
  edit "", 25, 109 128 211 10, result tab 19 read
  text  $+ $mm.get.lan(60) $+ , 15, 86 129 22 8, tab 19 right
  tab "Adressbuch", 49
  list 29, 84 4 238 228, tab 49 size
  edit "", 42, 84 232 76 10, group tab 49
  edit "", 43, 161 232 55 10, group tab 49
  edit "", 44, 217 232 105 10, group tab 49
  button  $+ $mm.get.lan(85) $+ , 30, 189 243 37 11, tab 49
  button  $+ $mm.get.lan(64) $+ , 31, 232 243 37 11, tab 49
  button  $+ $mm.get.lan(86) $+ , 32, 276 243 46 11, tab 49
  button  $+ $mm.get.lan(14) $+ , 45, 85 243 32 10, tab 49
  tab "Tab 5", 46
  text  $+ $mm.get.lan(87) $+ , 47, 101 20 220 14, tab 46
  edit "", 48, 120 35 163 17, result tab 46 read multi
  text  $+ $mm.get.lan(88) $+ , 50, 102 54 219 26, tab 46 center
  text "bIRC eMail", 77, 93 136 78 7, tab 46
  text "mIRC 6.x Addon", 78, 93 144 78 7, tab 46
  text "Coded by ViTboY", 79, 245 246 78 7, tab 46 right
  text "Contact:", 80, 100 211 25 8, tab 46 right
  text "Home Page:", 81, 89 233 36 8, tab 46 right
  link "vitboy@hotmail.com", 82, 129 211 52 8, tab 46
  link "http://usuarios.lycos.es/mircscripts", 83, 129 233 94 8, tab 46
  icon 84, 287 131 32 32,  $mm.folder $+ $chr(92) $+ graphics $+ $chr(92) $+ mail.ico, 0, tab 46 noborder
  box "Credits", 85, 80 122 246 133, tab 46
  text "This mail administrator is my second serious project at this moment. I started it with a simple dialog with three edits and one button. This make me to learn more about mIRC Scripting and DLL functions, in the future i'll try to make more addons and put them in a Script. I hope that this mail system can be useful for you. Thanks for use it.", 55, 93 166 223 27, tab 46
  box "Help", 53, 80 2 246 117, tab 46
  text  $+ $mm.get.lan(89) $+ , 103, 100 9 56 8, tab 46
  text  $+ $mm.get.lan(90) $+ , 104, 102 82 90 8, tab 46
  text  $+ $mm.get.lan(91) $+ , 105, 102 93 220 20, tab 46
  tab "Tab 6", 65
  list 75, 77 19 252 103, tab 65 size
  text  $+ $mm.get.lan(92) $+ , 76, 83 123 15 8, tab 65 right
  text "", 88, 100 123 230 8, tab 65
  button "", 91, 77 150 252 105, tab 65
  text  $+ $mm.get.lan(84) $+ , 87, 83 132 15 8, tab 65 right
  text "", 86, 100 132 230 8, tab 65
  text "", 89, 100 141 230 8, tab 65
  text  $+ $mm.get.lan(60) $+ , 90, 77 141 21 8, tab 65 right
  button  $+ $mm.get.lan(93) $+ , 92, 291 4 37 12, tab 65
  button  $+ $mm.get.lan(64) $+ , 102, 252 4 37 12, tab 65
  text  $+ $mm.get.lan(101) $+ , 106, 263 109 25 8, tab 18 right
  combo 107, 289 108 39 50, tab 18 size drop sort 
  text "0 0 100", 112, 0 258 57 9
  list 27, -1 0 76 258, size
  menu  $+ $mm.get.lan(31) $+ , 9
  item  $+ $mm.get.lan(13) $+ , 14, 9
  item  $+ $mm.get.lan(12) $+ , 33, 9
  item  $+ $mm.get.lan(94) $+ , 34, 9
}


on 1:dialog:mm_console:*:*:{
  if ($devent == init) {
    mdxinit
    mdx SetColor mm_console 1 background $rgb(255,255,255) 
    mdx SetColor mm_console 1 textbg $rgb(255,255,255)   
  }
  if ($devent == menu) {
    if ($did == 3) { did -r mm_console 1 }
    if ($did == 4) { dialog -x mm_console }
  }
}
on 1:dialog:load:init:*:{
  mdxinit
  mdx SetDialog $dname style border > $mircdir $+ $chr(92) $+ dll $+ $chr(92) $+ mdx.dll
  mdx SetControlMDX 1 window > $mircdir $+ dll $+ $chr(92) $+ dialog.mdx   
  web.load
  did -ra load 1 grab $window(@load).hwnd @load
  .timer 1 6 mm.load.ing
}
dialog load {
  size -1 -1 485 310
  option pixels
  button "", 1, -12 -22 528 378
}
dialog mm_console {
  title "Console"
  size -1 -1 192 122
  option dbu
  edit "", 1, 1 1 190 119, read result multi autovs vsbar
  menu "Co&mmands", 2
  item "&Clear Console", 3, 2
  item "Cl&ose", 4, 2 
}

;################################################
;#                                              #
;#                                              #
;#             POP3 Module v1.1                 #
;#                                              #
;#                                              #
;################################################
; 

alias pop3 {
  if (%pop.us) && (%pop.ps) && (pop.serv) {
    .timer 5 0 mm.pop.dataout 
    sockclose pop 
    unset %pop.sel
    set %pop.started no
    sockopen pop %pop.serv 110
    mm.type $mm.get.lan(95) %pop.serv $+ ... 
    did -ra mail 86,88,89 -
  }
  else { mm.type $mm.get.lan(96) | did -ra mail 86,88,89 - } 
}
on 1:sockread:pop.r:{
  sockread %popr
  tokenize 32 %popr
  if ($gettok(%popr,1,32) isnum 1-150) {
    inc %mm.countr
  }
  if ($gettok(%popr,1,32) == $chr(46)) {
    pop.remove %pop.sel
  }
  if (%pop.un == on) {
    set %pop.un off
    ident.pop.r %popr

  }
}
alias pop.remove {
  var %times = $calc($gettok(%pop.sel,0,35) + 1)
  var %sel = %pop.sel
  var %l = 1
  :go
  if (%l != %times) {
    sockwrite -tn pop.r dele $calc($gettok(%sel,%l,35) - 1)
    .remove $findfile($mm.folder $+ temp, *.html, $calc($gettok(%sel,%l,35) - 1))
    inc %l 
    goto go
  }
  if (%l == %times) {
    sockwrite -tn pop.r quit
    sockclose pop.r
    did -ra mail 12 4 $mm.get.lan(97) 
    unset %mm.countr
    .timer 1 1 set %pop.un on
    pop3
  }
}

alias -l ident.pop.r {
  sockwrite -tn pop.r user %pop.us
  sockwrite -tn pop.r pass %pop.ps
  sockwrite -tn pop.r list
}

alias -l ident.pop {
  set %pop.started yes
  pope user %pop.us
  pope pass %pop.ps
  pope list
}
alias -l mm.pop.read {
  .timerdata off
  .timerdata 1 1 mm.pop.data
  .timerdat off
  .timerdat 1 1 mm.taip
  if (%mm.p.st == on) { 
    $iif($1 != $chr(32), write $mm.folder $+ temp $+ $chr(92) $+ %mm.msg $1-, write $mm.folder $+ temp $+ $chr(92) $+ %mm.msg $chr(32))
  }
  if ($1 == $chr(46)) && (!$2) { set %mm.yeah off }
  if ($1 == From:) && ($2) { write -il1 $mm.folder $+ $chr(92) $+ temp $+ $chr(92) $+ %mm.msg $chr(60) $+ $chr(33) $+ $chr(45) $+ $chr(45) $2- $chr(47) $+ $chr(47) $chr(45) $+ $chr(45) $+  $chr(62) }
  if ($1 == From:) && (!$2) { write -il1 $mm.folder $+ $chr(92) $+ temp $+ $chr(92) $+ %mm.msg $chr(60) $+ $chr(33) $+ $chr(45) $+ $chr(45) Not found $chr(47) $+ $chr(47) $chr(45) $+ $chr(45) $+ $chr(62) }
  if ($1 == Subject:) && ($2) { write -il2 $mm.folder $+ $chr(92) $+ temp $+ $chr(92) $+ %mm.msg $chr(60) $+ $chr(33) $+ $chr(45) $+ $chr(45) $2- $chr(47) $+ $chr(47) $chr(45) $+ $chr(45) $+ $chr(62) }
  if ($1 == Subject:) && (!$2) { write -il2 $mm.folder $+ $chr(92) $+ temp $+ $chr(92) $+ %mm.msg $chr(60) $+ $chr(33) $+ $chr(45) $+ $chr(45) Not found $chr(47) $+ $chr(47) $chr(45) $+ $chr(45) $+ $chr(62) }
  if ($1 == Date:) && ($2) { write -il3 $mm.folder $+ $chr(92) $+ temp $+ $chr(92) $+ %mm.msg $chr(60) $+ $chr(33) $+ $chr(45) $+ $chr(45) $remove($2-,Date:) $chr(47) $+ $chr(47) $chr(45) $+ $chr(45) $+ $chr(62) | set %mm.right on  }
  if ($1 == Date:) && (!$2) { write -il3 $mm.folder $+ $chr(92) $+ temp $+ $chr(92) $+ %mm.msg $chr(60) $+ $chr(33) $+ $chr(45) $+ $chr(45) Not found $chr(47) $+ $chr(47) $chr(45) $+ $chr(45) $+ $chr(62) | set %mm.right on }
  if (%mm.right == on) && (Message-id: isin $1-) { set %mm.p.st on  }
}
alias -l web.pop {
  window -ph @pop
  $dll($wdll,attach,$window(@pop).hwnd)
  $dll($wdll,navigate, $+ $mm.folder $+ graphics $+ $chr(92) $+ nomsg.html)
}
alias -l e_invalid_window { return }

alias -l pop.sel {
  if (!%pop.sel) { set %pop.sel $+($chr(35),$1) | halt }
  if ($1 !isin %pop.sel) { set %pop.sel %pop.sel $+ $+($chr(35),$1) | halt }
  if ($1 isin %pop.sel) { set %pop.sel $remove(%pop.sel,$+($chr(35),$1)) | halt }
} 
alias -l mm.lectura {
  if ($1 == 0) { .timer 1 4 mm.type $mm.get.lan(98) | halt }
  var %x = $calc($1 + 1)
  var %i = 1
  :go
  if (%i != %x) {
    pope retr %i
    inc %i
    goto go
  }
}
alias -l mm.get.pop { return $iif(!$gettok($read($findfile($mm.folder $+ $chr(92) $+ temp,*.html,$1),1),1-,60),Not Found,$gettok($read($findfile($mm.folder $+ $chr(92) $+ temp,*.html,$1),1),1-,60)) $+ $chr(9) $+ $iif(!$gettok($read($findfile($mm.folder $+ $chr(92) $+ temp,*.html,$1),2),1-,60), Not Found, $gettok($read($findfile($mm.folder $+ $chr(92) $+ temp,*.html,$1),2),1,60)) $+ $chr(9) $+ $iif(!$gettok($read($findfile($mm.folder $+ $chr(92) $+ temp,*.html,$1),3),1-,60), Not Found, $gettok($read($findfile($mm.folder $+ $chr(92) $+ temp,*.html,$1),3),1-,60))  }
alias -l mm.pop.dataout {
  $dll($wdll,navigate, $+ $mm.folder $+ graphics $+ $chr(92) $+ nomsg.html)
  did -r mail 75
  var %n = 1
  var %max = $calc($findfile($mm.folder $+ temp,*.html,0) + 1)
  :i
  if (%n != %max) {
    $iif($findfile($mm.folder $+ temp,*.html,%n), .timer 5 0 .remove $findfile($mm.folder $+ temp,*.html,%n))  
    inc %n
    goto i
  }
}
alias -l mm.pop.data {
  did -r mail 75
  var %n = 1
  var %max = $calc(%mm.count + 1)
  :i
  if (%n != %max) {
    did -a mail 75 1 $remove($mm.get.pop(%n),<!,--,/,!,$chr(32) $+ >)
    inc %n
    goto i
  }
}

on 1:sockread:pop:{
  sockread %pop
  tokenize %pop 32
  if (%pop.started == no) { ident.pop  }
  if ($gettok(%pop,1,32) == -ERR) { sockclose pop | set %pop.started no | mm.type $mm.get.lan(96) }
  if (list isin $gettok(%pop,3,32)) {
    mm.type $mm.get.lan(99) 
    set %mm.count %mm.count.last 
    set %mm.count 0
    set %mm.maildrop on
  }
  if (%mm.maildrop == on) {
    if ($gettok(%pop,1,32) == $chr(46)) && (!$2) { set %mm.maildrop off | mm.lectura %mm.count }
    if ($gettok(%pop,1,32) isnum 1-150) {
      inc %mm.count
    }
  }
  if ($gettok(%pop,3,32) == octets) {
    set %mm.yeah on
    set %mm.p.st off    
    set %mm.right off
    set %mm.msg $gettok(%pop,2,32) $+ .html
    .remove $mm.folder $+ temp $+ $chr(92) $+ %mm.msg
  }
  if ($gettok(%pop,3,32) != octets) && (%mm.yeah == on) {
    { 
      mm.pop.read %pop
    }
  }
}
on 1:sockopen:mail:{ 
  if ($sockerr > 0) { mm.type $mm.get.lan(100) | sockclose mail }
}
on 1:sockopen:pop:{ 
  if ($sockerr > 0) { mm.type $mm.get.lan(100) | sockclose pop }
}
on 1:sockopen:pop.r:{ 
  if ($sockerr > 0) { mm.type $mm.get.lan(100) | sockclose pop.r }
}
alias mdx-info {
  var %dname, %did
  if ($0 = 1) {
    set %dname $dname
    set %did $1
  }
  else {
    set %dname $1
    set %did $2
  }
  did -i %dname %did 1 page $prop
  return $gettok($did(%dname, %did, 1), 3-, 32)
}
alias -l mm.taip { mm.type $mm.get.lan(38) - ( $+ %pop.serv $+ ) - $time | did -f mail 65 }
alias -l pope { sockwrite -tn pop $1- }
