Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ protected function sendEmail(IShare $share, array $emails): void {
]
);
}
$message->setFrom([Util::getDefaultEmailAddress($instanceName) => $senderName]);
$message->setFrom([Util::getEmailAddressForUser($initiatorUser, $instanceName) => $senderName]);

// The "Reply-To" is set to the sharer if an mail address is configured
// also the default footer contains a "Do not reply" which needs to be adjusted.
Expand Down
32 changes: 32 additions & 0 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,38 @@ public static function getDefaultEmailAddress(string $user_part): string {
return $user_part . '@localhost.localdomain';
}

/**
* Returns the email address for the given user
* @param IUser|null $user
* @param string $fallback_user_part the fallback address part
* @return string the email address
*
* If mail providers are enabled, uses the specified user's email address.
* If disabled or the user has no valid email, falls back to the system default.
* @since 31.0.12
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @since 31.0.12
* @since 33.0.0

*/
public static function getEmailAddressForUser(?IUser $user, string $fallback_user_part): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

The check $user !== null should be done outside for a cleaner api.

if ($user === null) {
return self::getDefaultEmailAddress($fallback_user_part);
}

$config = \OCP\Server::get(serviceName: IConfig::class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use IAppConfig


$mailProvidersEnabled = $config->getAppValue('core', 'mail_providers_enabled', '0') === '1';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$mailProvidersEnabled = $config->getAppValue('core', 'mail_providers_enabled', '0') === '1';
$mailProvidersEnabled = $appConfig->getValueBool('core', 'mail_providers_enabled', true)


if ($mailProvidersEnabled) {
$userEmail = $user->getEMailAddress();

if ($userEmail !== null) {
$emailValidator = \OCP\Server::get(IEmailValidator::class);
if ($emailValidator->isValid($userEmail)) {
return $userEmail;
}
}
}
return self::getDefaultEmailAddress($fallback_user_part);
}

/**
* Converts string to int of float depending on if it fits an int
* @param numeric-string|float|int $number numeric string
Expand Down