utils: Re-work is_valid_email_address()

The main issue was that it would not allow an email address if it did
not contain a '.'. However it seems that could be valid e.g

    me@com

We now make sure the address is at least 3 characters long, doesn't end
with a '.' and contains an '@', but doesn't have '@.'

e.g

    @a
    @.com
    .@.
    user@example.com.

would be treated as invalid.

Signed-off-by: Andrew Clayton <andrew@dnsandmx.com>
utils: is_valid_hostname: Use NI_MAXHOST for length check

This function may be checking either a hostname or FQDN, previously we
were using 63 for the max hostname length, but for a FQDN this may be
too short.

Make the length check >= NI_MAXHOST (it includes space for the nul
byte). NI_MAXHOST is defined in netdb.h and is used by functions like
getnameinfo(3).

Signed-off-by: Andrew Clayton <andrew@dnsandmx.com>
url_handlers: add_mail_domain: Sanity check the domain name

Use is_valid_hostname() to see if it looks reasonable.

Had a case where someone had entered something like

    name@sub.domain.tld

Signed-off-by: Andrew Clayton <andrew@dnsandmx.com>
url_handlers: add_dns_domain: Sanity check the domain name

Use is_valid_hostname() to see if it looks reasonable.

Signed-off-by: Andrew Clayton <andrew@dnsandmx.com>
url_handlers: Remove possible SQL injection in delete_mail_fwd_record

In /mail_forwarding/ we list the forwarding rules for the given domain,
we also provide a delete button for each record that does a POST to
/delete_mail_fwd_record/

Previously this was passing the domain id and the source forwarding rule
(essentially an email address). This source parameter was just being
used in the SQL DELETE query as is, it would be quite simple for someone
to craft a source= that contained some nasty SQL.

Remove this problem altogether by using the record_id, which is a simple
integer instead of source.

Signed-off-by: Andrew Clayton <andrew@dnsandmx.com>