Done all that. Problem is still str_replace as it does a global match
This is hard to reproduce as depends on the order of records in the vpopmail table.
For the bug to appear two conditions must be meet.
1. The email name occurs in the domain name eg fred@frednerk.com
2. The email address it the last record for that domain in the vpopmail table
Here is a small proof of concept:
<?php
$name="firstname";
$path="/home/lxadmin/mail/domains/firstnamesurname.com/firstname";
echo "source path: ".$path."\n";
//Calculate path with str_replace
$newpath=str_replace("/" . $name, '', $path);
echo "str_replace method: ".$newpath."\n";
//Calculate path with str_replace
$newpath2=preg_replace('/\/' . $name.'$/', '', $path);
echo "preg_replace method: ".$newpath2."\n";
?>
output:
source path: /home/lxadmin/mail/domains/
firstnamesurname.com/firstname
str_replace method: /home/lxadmin/mail/
domainssurname.com
preg_replace method: /home/lxadmin/mail/domains/
firstnamesurname.com