Mastering Nginx

(Ron) #1

Using the Mail Module


[ 56 ]

# want to get just the address from these two here
from = @env['HTTP_AUTH_SMTP_FROM'].split(/: /)[1]
to = @env['HTTP_AUTH_SMTP_TO'].split(/: /)[1]
@res["Auth-Status"] = "OK"
@res["Auth-Server"] = @mailhost
# return the correct port for this protocol
@res["Auth-Port"] = MailAuth::Port[proto]
@log.info("a mail from #{from} on #{helo} for #{to}")
# try to authenticate using the headers provided
elsif auth(user, pass)
@res["Auth-Status"] = "OK"
@res["Auth-Server"] = @mailhost
# return the correct port for this protocol
@res["Auth-Port"] = MailAuth::Port[proto]
# if we're using APOP, we need to return the password in
cleartext
if meth == 'apop' && proto == 'pop3'
@res["Auth-User"] = user
@res["Auth-Pass"] = pass
end
@log.info("+ #{user} from #{client}")
# the authentication attempt has failed
else
# if authentication was unsuccessful, we return an appropriate
response
@res["Auth-Status"] = "Invalid login or password"
# and set the wait time in seconds before the client may make
# another authentication attempt
@res["Auth-Wait"] = "3"
# we can also set the error code to be returned to the SMTP
client
@res["Auth-Error-Code"] = "535 5.7.8"
@log.info("! #{user} from #{client}")
end

end
Free download pdf