VrS (Variant realities Script) — File Browser
VrSVariantrealitiesScriptv2.0 / VrSVariantrealitiesScriptv2.0 / VrS / System / Modules / vMail / vmail.mrc
vmail.mrc — 6.42 KB — Download this file
;#[vHD@3.0 C!vMail@2.0.0;2001.7.18;Variant<variant@variantrealities.com>]
;#[SD ]
;#[Incl ]
;#[VrS' mail sending system]
;#[ ]
;#[ ]
alias vmail.send {
; syntax: /vmail.send <Handler> <Server> <FromAddress@> <ToAddress@ |or| BulkMailFile> <File>
; The Handler is the command called (/vmail.Process.<Handler>) for messages. The default handler is "Default"
; the bulk mail file option uses a file that should have email addresses one per line
; in the form Name@domain.XXX without <>, other brackets, or commas.
; prefix a email address with BCC: to hide it
; VARIANT REALITIES DOES NOT CONDONE NOR SUPPORT
; THE USE OF ANY FORM OF THIS ENGINE FOR UNSOLICITED MAIL (SPAM).
; USE AT YOUR OWN DISCRETION.
vmvar HandleProcess $1
if ($3 != FromAddress) { vmvar FromAddress $3 }
elseif ($vmvar(FromAddress) == $null) { vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Error: FromAddress variable not set - use /vmvar FromAddress <email address> <name> | return }
if ($5 == $null) { SEcho /vMail.Send <Handler> <Server> <FromAddress@> <ToAddress@ |or| BulkMailFile> <File> [Subject] | return }
if ($isfile($5-) != $true) { vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Error: Mail file does not exist. | return }
if (@ !isin $4) && ($isfile( [ " $+ [ $gettok($4,1,47) ] $+ " ] ) != $true) { vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Error: Bulk-Mail file does not exist. | return }
vmvar ToAddress $gettok($4,1,47) | vmvar File $5- | vmvar Subject $vmvar(Subject)
if ($chr(47) isin $4) { vmvar ToAddressSubj $replace($gettok($4,2-,47),$chr(58),$chr(32)) }
vmvar Status 0
vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Msg: Connecting...
sockopen vMail.SMTP $2 25
}
alias -l vMail.Process.Default {
; Default vMail Handler (echos text to the /vDebug window)
vecho 12vMail:14 $1-
}
on *:sockopen:vMail.SMTP: {
if ($sockerr) { vMail.SMTP.Protocol ConnectError $sockname | return }
vMail.SMTP.Protocol ConnectOpen $sockname
}
on *:sockclose:vMail.SMTP: {
if ($sockerr) { vMail.SMTP.Protocol ConnectError $sockname | return }
vMail.SMTP.Protocol ConnectClosed $sockname
}
on *:sockopen:vMail.SMTP: {
if ($sockerr) { vMail.SMTP.Protocol ConnectError $sockname | return }
vMail.SMTP.Protocol SockWrote $sockname
}
on *:sockread:vMail.SMTP: {
if ($sockerr) { vMail.SMTP.Protocol ConnectError $sockname | return }
var %Sockread
sockread %Sockread
while ($sockbr) {
vMail.SMTP.Protocol IncomingData $sockname %Sockread
sockread %Sockread
}
}
alias vMail.SMTP.Protocol {
;vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Debug: $1-
vecho $1-
if ($1 == IncomingData) {
if ($3 == 220) {
vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Msg: Connected.
vMail.SendData HELO $vMI.IP | vmvar status 1
}
elseif ($3 == 250) {
; 4 steps to a sent letter: who from? who to? what? and done.
if ($vmvar(Status) == 1) {
vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Msg: Sending email.
vMail.SendData MAIL FROM:< $+ $gettok($vmvar(FromAddress),1,32) $+ > $+ $crlf | vmvar Status 2
}
elseif ($vmvar(Status) == 2) {
if (@ isin $vmvar(ToAddress)) { vMail.SendData RCPT TO:< $+ $vmvar(ToAddress) $+ > $+ $crlf }
else {
vmvar Lines $lines($vmvar(ToAddress)) | vmvar ToFile $vmvar(ToAddress)
vmvar Recipients
while ($vmvar(Lines) > 0) {
vmvar Read $read($remove($vmvar(ToFile),"),n,$vmvar(Lines))
if ($left($vmvar(Read),4) == Bcc:) { vMail.SendData RCPT TO:< $+ $gettok($vmvar(Read),2,58) $+ > $+ $crlf }
else {
vMail.SendData RCPT TO:< $+ $vmvar(Read) $+ > $+ $crlf
}
hdec vMail Lines
}
}
vmvar Status 3
}
else if ($vmvar(Status) == 3) { vMail.SendData DATA $+ $crlf | vmvar status 4 }
else if ($vmvar(Status) == 5) { vMail.SendData QUIT $+ $crlf | vmunset Status }
}
elseif ($3 == 354) {
; The letter formatting
vMail.SendData FROM: $+ $gettok($vmvar(FromAddress),2-,32) < $+ $gettok($vmvar(FromAddress),1,32) $+ > $+ $crlf
if (@ isin $vmvar(ToAddress)) { vMail.SendData TO:< $+ $vmvar(ToAddress) $+ > $+ $crlf }
else {
vmvar Lines $lines($vmvar(ToAddress)) | vmvar ToFile $vmvar(ToAddress)
while ($vmvar(Lines) > 0) {
vmvar Read $read($remove($vmvar(ToFile),"),n,$vmvar(Lines))
if ($calc($len($vmvar(Recipients)) + $len($vmvar(Read))) > 500) { goto skip }
if ($left($vmvar(Read),4) != Bcc:) { vmvar Recipients $iif($vmvar(Recipients),$vmvar(Recipients), $+ $chr(44)) $vmvar(Read) }
hdec vMail Lines
}
if ($vmvar(Recipients)) && ($vmvar(ToAddressSubj) == $null) { vMail.SendData TO:< $+ $vmvar(Recipients) $+ > $+ $crlf | goto out }
elseif ($vmvar(ToAddressSubj) != $null) { vMail.SendData TO: $+ $vmvar(ToAddressSubj) <> $+ $crlf | goto out }
:skip
vMail.SendData TO: <> $+ $crlf
:out
}
vMail.SendData Subject: $+ $vmvar(Subject) $+ $crlf $+ $crlf
vmvar Lines $lines($vmvar(File)) | vmvar Count 1
while ($vmvar(Count) <= $vmvar(Lines)) {
vMail.SendData $read($remove($vmvar(File),"),n,$vmvar(Count)) $crlf
hinc vMail Count
}
vMail.SendData . $+ $crlf
vmvar status 5
}
elseif ($3 isin :521:571:) {
vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Error: Must authenticate.
vmail.close
}
elseif ($3 == 221) {
vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Msg: Complete.
vMail.Close
}
}
elseif ($1 == ConnectError) { vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Error: Unable to connect. | vMail.Close }
}
alias vMail.Close { sockclose vMail.SMTP | if ($vmvar(HandleProcess)) { vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Closed. } | vmunset * }
alias vMail.SendData { sockwrite -n vMail.SMTP $1- }
;Debug data: vMail.Process. [ $+ [ $vmvar(HandleProcess) ] ] Sending: $1- |
alias vmvar {
if ($hget(vMail) == $null) { .hmake vMail 10 }
if ($isid == $true) { return $hget(vMail,$1) }
else {
if ($2 != $null) { hadd vMail $1 $2- }
else { hdel vMail $1 }
}
}
alias vmunset {
if ($hget(vMail) == $null) { .hmake vMail 10 }
var %counter = 1
while (%counter <= $numtok($1-,32)) {
hdel -w vMail $gettok($1-,%counter,32)
inc %counter
}
}