Skip to content

Conversation

@frederic34
Copy link
Member

No description provided.

@eldy eldy added the PR to fix - Conflict or CI error to solve The PHP unit tests return something wrong. Check details to know what to fix or solve the conflicts. label Nov 9, 2025
@frederic34 frederic34 removed the PR to fix - Conflict or CI error to solve The PHP unit tests return something wrong. Check details to know what to fix or solve the conflicts. label Nov 9, 2025
* @var ?int $hidedesc
* @var ?int $hideref
* @var ?array<string,mixed> $moreparams
* @var ?string $from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining $from as a predefined value does not seem correct.
$from may not be defined because we have

if ($obj) {
$from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>';
}
(if ($obj) { $from = ... }) in one of the conditions and then $from is not defined when using it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕
Bigger picture:

if ($fromtype === 'user') {
$from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>';
} elseif ($fromtype === 'company') {
$from = getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . ' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>';
} elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
$tmp = explode(',', $user->email_aliases);
$from = trim($tmp[((int) $reg[1] - 1)]);
} elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
$tmp = explode(',', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'));
$from = trim($tmp[((int) $reg[1] - 1)]);
} elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
$sql = "SELECT rowid, label, email FROM ".MAIN_DB_PREFIX."c_email_senderprofile WHERE rowid = ".(int) $reg[1];
$resql = $db->query($sql);
$obj = $db->fetch_object($resql);
if ($obj) {
$from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>';
}
} else {
$from = GETPOST('fromname').' <'.GETPOST('frommail').'>';
}
$replyto = $from;

After the if/elseif sequence, $from may not be defined.
One method would be:

$from = null;
if (...) ... else if() .. .
if ($from === null) {
    $from = GETPOST('fromname').' <'.GETPOST('frommail').'>';
}

or

$from = GETPOST('fromname').' <'.GETPOST('frommail').'>';
if (...) ... else if() .. .

And remove

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 75 was removed

@eldy eldy merged commit 4334797 into Dolibarr:develop Nov 9, 2025
2 of 3 checks passed
aummind pushed a commit to aummind/dolibarr that referenced this pull request Nov 13, 2025
* clean code

* clean code

* fix

* fix

* fix

* fix

* fix

---------

Co-authored-by: Laurent Destailleur <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants