Here is a POP3 code:

Code:

alias dogetmail getmail EMAIL_1 smtp.first.com 110 myusername MyPassword $true email\first\

alias dochkmail getmail EMAIL_2 smtp.second.com 110 my.email@second.com ThisPassword $false email\second\

; /getmail [-e] <name> <server> <port> <username> <password> <transfer> <savepath>
;  <name>: Name for this connection, single word only
;  <server>: IP or server of POP3 server
;  <port>: Port of POP3 server
;  <username>: Username for logging into POP3 server
;  <password>: Password for logging into POP3 server
;  <transfer>: $true = Download&DeleteMessages; $false=LeaveOnServer
;  <savepath>: absolute or relative path to save downloaded emails

alias getmail {
  if (-* iswm $1) {
    var %sw = $1
    tokenize 32 $2-
  }

  var %dir = $7
  if (!$isdir(%dir)) mkdir %dir
  if (!$isdir(%dir)) {
    echo 4 -a POP3 $1 * ERROR: Unable to create path %dir
    return
  }

  :picksid
  var %SID = $+(pop.,$ticks,$rand(000,999))
  if ($exists($+($p3get($+(%SID,.path)),%SID,.txt))) goto picksid

  $+(.timer,.,%SID) 1 5 getmailcleanup %SID

  p3add $+(%SID,.name) $1
  p3add $+(%SID,.addr) $2
  p3add $+(%SID,.port) $3
  p3add $+(%SID,.user) $4
  p3add $+(%SID,.pass) $5
  p3add $+(%SID,.save) $6
  p3add $+(%SID,.path) $7

  p3add $+(%SID,.write) 0
  p3add $+(%SID,.state) 1
  if ($sock(%SID)) sockclose %SID
  sockopen $iif(e isin %sw,-e) %SID $p3get($+(%SID,.addr)) $p3get($+(%SID,.port))
}

on *:SOCKOPEN:pop.*:{
  var %SID = $sockname
  echo 3 -a POP3 $p3get($+(%SID,.name)) * Connected to $+($p3get($+(%SID,.addr)),:,$p3get($+(%SID,.port))) as $p3get($+(%SID,.user))
}

on *:SOCKREAD:pop.*:{
  var %s
  sockread %s
  tokenize 32 %s
  ;echo -a > $1-
  var %SID = $sockname
  $+(.timer,.,%SID) 1 5 getmailcleanup %SID

  if (-ERR isin $1) {
    echo 4 -a POP3 $p3get($+(%SID,.name)) * ERROR @ $+ $p3get($+(%SID,.state)) $+ : $1-
    sockwrite -n $sockname QUIT
    p3add $+(%SID,.state)) -1
  }
  elseif ($p3get($+(%SID,.state)) < 0) {
    sockclose $sockname
  }
  elseif ((OK isin $1) && (!$p3get($+(%SID,.write)))) {
    if ($p3get($+(%SID,.state)) == 1) {
      sockwrite -n $sockname USER $p3get($+(%SID,.user))
      p3add $+(%SID,.state)) 2
    }
    elseif ($p3get($+(%SID,.state)) == 2) {
      sockwrite -n $sockname PASS $p3get($+(%SID,.pass))
      p3add $+(%SID,.state)) 3
    }
    elseif ($p3get($+(%SID,.state)) == 3) {
      sockwrite -n $sockname STAT
      p3add $+(%SID,.state)) 4
    }
    elseif ($p3get($+(%SID,.state)) == 4) {
      echo 12 -a POP3 $p3get($+(%SID,.name)) * $2 $iif($2 == 1,message,messages)
      if (($2 > 0) && ($p3get($+(%SID,.save)))) {
        p3add $+(%SID,.count)) 1
        p3add $+(%SID,.state)) 5
        p3add $+(%SID,.num)) $2
        .remove $+($p3get($+(%SID,.path)),%SID,.tmp)
        sockwrite -n $sockname RETR $p3get($+(%SID,.count))
      }
      else {
        sockwrite -n $sockname QUIT
        p3add $+(%SID,.state)) 99
      }
    }
    elseif ($p3get($+(%SID,.state)) == 5) {
      p3add $+(%SID,.write)) 1
    }
    elseif ($p3get($+(%SID,.state)) == 6) {
      if ($p3get($+(%SID,.dele)) < $p3get($+(%SID,.num))) {
        p3add $+(%SID,.dele)) $calc($p3get($+(%SID,.dele)) + 1)
        sockwrite -n $sockname DELE $p3get($+(%SID,.dele))
      }
      else {
        sockwrite -n $sockname QUIT
        p3add $+(%SID,.state)) 99
      }
    }
    elseif ($p3get($+(%SID,.state)) == 99) {
      sockclose $sockname
      echo 3 -a POP3 $p3get($+(%SID,.name)) * Disconnected from server
      p3wdel $+(%SID,.*)
    }
  }
  elseif ($p3get($+(%SID,.state)) == 5) {
    if ($1- == .) {
      .rename $+($p3get($+(%SID,.path)),%SID,.tmp) $+($p3get($+(%SID,.path)),%SID,.txt)
      echo 7 -a POP3 $p3get($+(%SID,.name)) * Saved new message as $+($p3get($+(%SID,.path)),%SID,.txt)
      p3add $+(%SID,.write)) 0
      if ($p3get($+(%SID,.count)) < $p3get($+(%SID,.num))) {
        p3add $+(%SID,.count)) $calc($p3get($+(%SID,.count)) + 1)
        sockwrite -n $sockname RETR $p3get($+(%SID,.count))
      }
      else {
        p3add $+(%SID,.dele)) 1
        sockwrite -n $sockname DELE 1
        p3add $+(%SID,.state)) 6
      }
    }
    else {
      write $+($p3get($+(%SID,.path)),%SID,.tmp) $iif($1,$1-,$crlf)
    }
  }
}

alias p3add hadd -m pop3 $1 $2-
alias p3get return $hget(pop3,$1)
alias p3wdel hdel -w pop3 $1-

alias getmailcleanup {
  if ($sock($1)) {
    sockwrite -n $1 QUIT
    sockclose $1
  }
  if ($p3get($+($1,.name)) != $null) echo 3 -a POP3 $p3get($+($1,.name)) * Disconnected from server
  if ($hget(pop3)) p3wdel $1




Sample aliases /dogetmail and /dochkmail demonstrate how to call the /getmail alias. /dochkmail shows only checking whether new messages exist, and /dogetmail shows checking for new messages and downloading and deleting those messages. Downloaded messages are saved in the path that you specify for that connection.

This code has been tested on a non-SSL POP3 server. Theoretically, it can also connect to SSL POP3 servers, though I cannot test that functionality because I don't have SSL installed in my mIRC. To enable SSL, add the -e switch to the /getmail command. Example:

Code:

/getmail -e EMAIL_3 smtp.server.com 995 username password $true email\third



Let me know about any errors. Also, let me know if it works on SSL servers.

-genius_at_work