We now check all allowed chars in the address before the @ sign.
To check the fqdn of an email the function validfqdn has been adapted as well. Here a valid domain part is for example: user@ipfire or user@localhost.localdomain
Signed-off-by: Alexander Marx alexander.marx@ipfire.org --- config/cfgroot/general-functions.pl | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 2b5cd19..1bbcf85 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -653,9 +653,6 @@ sub validfqdn # Checks a fully qualified domain name against RFC1035 my $fqdn = $_[0]; my @parts = split (/./, $fqdn); # Split hostname at the '.' - if (scalar(@parts) < 2) { # At least two parts should - return 0;} # exist in a FQDN - # (i.e. hostname.domain) foreach $part (@parts) { # Each part should be at least one character in length # but no more than 63 characters @@ -747,14 +744,25 @@ sub ipcidr2msk { }
sub validemail { - my $mail = shift; - return 0 if ( $mail !~ /^[0-9a-zA-Z.-_]+@[0-9a-zA-Z.-]+$/ ); - return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/); - return 0 if ( $mail !~ /([0-9a-zA-Z]{1})@./ ); - return 0 if ( $mail !~ /.@([0-9a-zA-Z]{1})/ ); - return 0 if ( $mail =~ /..-.|.-..|....|.--./g ); - return 0 if ( $mail =~ /.._.|.-_.|._..|._-.|.__./g ); - return 0 if ( $mail !~ /.([a-zA-Z]{2,4})$/ ); + my $address = shift; + my @parts = split( /@/, $address ); + my $anz=@parts; + + #check if we have one part before and after '@' + return 0 if ( $anz != 2 ); + + #check if one of the parts starts or ends with a dot + return 0 if ( substr($parts[0],0,1) eq '.' ); + return 0 if ( substr($parts[0],-1,1) eq '.' ); + return 0 if ( substr($parts[1],0,1) eq '.' ); + return 0 if ( substr($parts[1],-1,1) eq '.' ); + + #check first addresspart (before '@' sign) + return 0 if ( $parts[0] !~ m/^[a-zA-Z0-9.!-+#]+$/ ); + + #check second addresspart (after '@' sign) + return 0 if ( !&validfqdn( $parts[1] ) ); + return 1; }