Lumail - The console email client


Examples: spam()

This example can be called against a message which is spam, and append the IP to a local blacklist file:

--
-- Append the IP address of the message to a blacklist.
--
-- NOTE - This only works because my mailserver is configured to write
-- the IP address of the sender to the header.
--
function spam()
   mode = global_mode()
   mode = string.lower( mode );
   val  = ""

   if ( string.find( mode, "message" ) ) then
      val = header( "X-Remote-IP" )
   elseif (string.find(mode, "index" ) ) then
      val = header( "X-Remote-IP" )
   else
      msg( "spam() not present for mode:" .. mode );
   end

   if ( val == "" ) then
      msg( "IP address not found in message." );
   else
      ff = io.open( "/etc/blacklist.d/smtp" , "a");
      ff:write( val .. "\n" )
      ff:close();
      msg( "blacklisted IP: " .. val );
   end
end

NOTE: This only works because my mail-server is configured to log the remote IP of the sending host in such a header.