webmcp

diff framework/env/net/send_mail.lua @ 5:4fb227630097

Version 1.0.5

Changes in net.send_mail{...}
- Code cleanup
- A boolean success value is returned
author jbe
date Sat Jan 02 12:00:00 2010 +0100 (2010-01-02)
parents 9fdfb27f8e67
children 4f9f7fef80ee
line diff
     1.1 --- a/framework/env/net/send_mail.lua	Fri Dec 25 12:00:00 2009 +0100
     1.2 +++ b/framework/env/net/send_mail.lua	Sat Jan 02 12:00:00 2010 +0100
     1.3 @@ -1,4 +1,5 @@
     1.4  --[[--
     1.5 +success =                          -- true, if mail has been sent successfully, otherwise false
     1.6  net.send_mail{
     1.7    envelope_from = envelope_from,   -- envelope from address, not part of mail headers
     1.8    from          = from,            -- From     header address or table with 'name' and 'address' fields
     1.9 @@ -25,7 +26,7 @@
    1.10    }
    1.11  }
    1.12  
    1.13 -This function sends a mail using the /usr/sbin/sendmail command.
    1.14 +This function sends a mail using the /usr/sbin/sendmail command. It returns true on success, otherwise false.
    1.15  
    1.16  --]]--
    1.17  
    1.18 @@ -37,21 +38,21 @@
    1.19      mail = encode.mime.mail(args)
    1.20    end
    1.21    local envelope_from = args.envelope_from
    1.22 -  local command
    1.23 +  local command = {"/usr/sbin/sendmail", "-t", "-i"}
    1.24    if
    1.25      envelope_from and
    1.26      string.find(envelope_from, "^[0-9A-Za-z%.-_@0-9A-Za-z%.-_]+$")
    1.27    then
    1.28 -    command =
    1.29 -      "/usr/sbin/sendmail -t -i -f " ..
    1.30 -      envelope_from ..
    1.31 -      " > /dev/null 2> /dev/null"
    1.32 -  else
    1.33 -    command = "/usr/sbin/sendmail -t -i > /dev/null 2> /dev/null"
    1.34 +    command[#command+1] = "-f"
    1.35 +    comment[#command+1] = envelope_from
    1.36 +  end
    1.37 +  local stdout, errmsg, status = os.pfilter(mail, unpack(command))
    1.38 +  if not status then
    1.39 +    error("Error while calling sendmail: " .. errmsg)
    1.40    end
    1.41 -  trace.debug(command)
    1.42 -  -- TODO: use pfilter
    1.43 -  local sendmail = assert(io.popen(command, "w"))
    1.44 -  sendmail:write(mail)
    1.45 -  sendmail:close()
    1.46 +  if status == 0 then
    1.47 +    return true
    1.48 +  else
    1.49 +    return false
    1.50 +  end
    1.51  end

Impressum / About Us