Lumail - The console email client


Lua primitives: get_signature()

NOTE: Lumail-legacy has been superseded by Lumail 2.x, which has a wholly unified Lua API.

lumail will launch your editor when you compose a new mail, and if the function get_signature is defined it will be called.

The get_signature function is expected to return a string which will be inserted in the new mail that your editor shows you.

This is a basic example:

--
-- Return the contents of the given (text) file.
--
-- Note: Called by get_signature()
--
function file_contents(file)
    local f = io.open(file, "rb")
    if ( f ) then
       local content = f:read("*all")
       f:close()
       return( content );
    else
       return( "Error reading file: \"" .. file .. "\"" )
    end
end


--
-- This function is called when you compose an email, the return value
-- is the signature text to insert at the end of the new mail.
--
function get_signature( from, to, subject )
   --
   -- Return the contents of ~/.signature if present
   --
   home = os.getenv( "HOME" )

   if ( file_exists( home .. "/.signature" ) ) then
      return( file_contents( home .. "/.signature" ) )
   else
      --
      -- No signature found.  Return empty text.
      --
      return ""
   end
end

A more flexible solution is shown in the get_signature example.

Availability

This function has been available since version 0.09.

See Also

See also compose, editor.