Menu Close

OSTicket v1.6: How to ensure lowercase email addresses

By default OSTicket lets users input their email addresses using upper, lower case, or mixed case. RFC 5322 states that the local part of an email can be either upper or lowercase (i.e. local-part@domain). In my experience most companies do not utilize this, or they generally accept iAMTMiB@ as iamtmib@ as iamTMiB@, etc. OSTicket by default lets the user type in iamTMiB@tmib.net when opening a ticket, and inserts it into the database as “iamTMiB@tmib.net”. This is fine behavior, but not the behavior that we want where I work.

Why not? Simply put, because when OST pulls up tickets if the user didn’t use the same capitalization every time they opened a ticket, they will not see tickets that have different mismatched case. For example, if I opened three (3) tickets as iamtmib@tmib.net and one (1) as iamTMiB@tmib.net and later went back to check on the status of my ticket and I enter iamtmib@tmib.net and the ticket number I would not see the iamTMiB@tmib.net ticket and vice versa. Presuming that we just want to change this for clients (non-staff) we would have to make changes to authentication (we don’t want login to fail because they use UseRNamE@), the input form (in case of errors), make sure the data is lowercase before inserting it into the database, and lastly update the information already in the database to be all lower case.

[document root] is the location of your installation.
so [document root]/includes would be the includes folder.

Authentication changes

Edit [document root]/login.php

circa line 28 locate the following:

$email=trim($_POST['lemail']);

and change it to

$email=strtolower(trim($_POST['lemail']));

Form changes

Edit [document root]/include/client/open.inc.php

circa line 36 through line 38 change

<input type="hidden" name="email" size="25" value="">
<?}else {?>             
<input type="text" name="email" size="25" value="">

to

<input type="hidden" name="email" size="25" value=""><?=strtolower($email)?>
<?}else {?>             
<input type="text" name="email" size="25" value="">

This makes sure that if they fill out the form wrong, that it echos back the lowercase email address.

Database insertion changes

Edit [document root]/include/class.ticket.php

circa line 1131 and 1320 change

',email='.db_input($var['email']).

to

',email='.db_input(strtolower($var['email'])).

This ensures that the email address is lower case when it is injected into the database.

Sorry for the delay.

Database Changes

Lastly we want to make sure that the data already in the database is all lower case (so it all matches). Using MySQL Work Bench or a mysql cli run the following:

connect <databasename>;

Make sure that you use the name of your database.

UPDATE ost_ticket SET email = LOWER(email);

This MySQL query literally take the value in email, converts it to lowercase and saves it where it was.

That’s it for now. Enjoy.