Periods or single quotes in aliases cause problems

Hi all.

I’m having some issues with the way email aliases are stored in the $USER_DATA/mail/$domain.conf files. In the current format, periods and single quotes in an alias will break things. Has anyone found a solution for the following two problems?

PROBLEM 1 – periods
Periods, of course, are allowed in the local-part of email addresses as long as they are not consecutive and not the first or last character. But the is_mail_new() function (in func/domain.sh) can’t handle an alias with a period.

Say I have a user with the following email aliases:

billbailey
bill_bailey
bill.bailey
bailey

The is_mail_new() function will return with an error: mail alias bailey is already exists. Why? Because in the grep -w $1 part of the check, the -w treats the period as a word boundary. So it sees bill.bailey as two different entries in the ALIAS list.

PROBLEM 2 – single quotes

Single quotes are also allowed in the local-part (along with many other special characters). But due to the way user data is stored in the $USER_DATA/mail/$domain.conf files, having a single quote in an alias completely breaks things.

Say I have a user with the following aliases:

patoreilly
pat_oreilly
pat_o'reilly
poreilly

The is_mail_new() function will fail in this case because the awk -F "ALIAS='" '{print $2}' $USER_DATA/mail/$domain.conf part of the check will return the following:

patoreilly,pat_oreilly,pat_o

Because the value of the ALIAS variable (and all the variables) in the $USER_DATA/mail/$domain.conf file is contained within single quotes, the awk command will ignore everything past the single quote in o'reilly. Unless code that deals with the values of other user data variables uses a different (and more robust) method of extracting the values, I imagine they must all break if a single quote is present.

Any ideas?

Cheers
–Dan

1 Like

Please create 2 bug reports at Github.

1 is for sure an bug the second is probally more difficult on the otherhand ’ are less used / not very common

Thanks @eris, I’ll do that.

In the mean time, I came up with a fix that solves both problems at once.

In the is_mail_new() function in the func/domain.sh script I replaced lines 630 and 631, which set the check_als variable, with the following single line:

check_als=$(perl -ne 'print $1 if /ALIAS=\x27(.*?)\x27 /' $USER_DATA/mail/$domain.conf | tr "," "\n" | grep -x $1)
  1. perl -ne 'print $1 if /ALIAS=\x27(.*?)\x27 /' $USER_DATA/mail/$domain.conf – extracts the full value inside the single quotes of the ALIAS variable. (This could be used anywhere a variable’s value needs to be extracted from mail/$domain.conf files, or any other files that use that format.)
  2. tr "," "\n" – splits the value into lines at the commas.
  3. grep -x $1 – checks for an entire line that contains the alias

That at least fixes the “.” issue, which is a fairly common character in email addresses. But the issue of not allowing all the valid characters for the local-part of email addresses is still an issue because the is_user_format_valid() function only tests for valid POSIX username characters ( a-z A-Z 0-9 . _ - ). We need a separate is_malias_format_valid() function that allows for all the valid local-part characters: a-z A-Z 0-9 ! # $ % & ’ * + – / = ? ^ _ ` . { | } ~

1 Like