Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function schedule(Message $iTipMessage) {
$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
return;
}
$this->imipService->setL10n($attendee);
$this->imipService->setL10nFromAttendee($attendee);

// Build the sender name.
// Due to a bug in sabre, the senderName property for an iTIP message can actually also be a VObject Property
Expand Down
37 changes: 28 additions & 9 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IEMailTemplate;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function __construct(
private ISecureRandom $random,
private L10NFactory $l10nFactory,
private ITimeFactory $timeFactory,
private readonly IUserManager $userManager,
) {
$language = $this->l10nFactory->findGenericLanguage();
$locale = $this->l10nFactory->findLocale($language);
Expand Down Expand Up @@ -870,18 +872,35 @@ public function getLastOccurrence(VCalendar $vObject) {
}

/**
* @param Property|null $attendee
* @param Property $attendee
*/
public function setL10n(?Property $attendee = null) {
if ($attendee === null) {
return;
public function setL10nFromAttendee(Property $attendee) {
$language = null;
$locale = null;
// check if the attendee is a system user
$userAddress = $attendee->getValue();
if (str_starts_with($userAddress, 'mailto:')) {
$userAddress = substr($userAddress, 7);
}

$lang = $attendee->offsetGet('LANGUAGE');
if ($lang instanceof Parameter) {
$lang = $lang->getValue();
$this->l10n = $this->l10nFactory->get('dav', $lang);
$users = $this->userManager->getByEmail($userAddress);
if ($users !== []) {
$user = array_shift($users);
$language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
$locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null);
}
// fallback to attendee LANGUAGE parameter if language not set
if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IDE is giving me some warnings about $attendee might be null. Could we maybe wrap every code that depends on $attendee != null in a if block? That would make it easier to understand the whole flow.

Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that we are initializing $this->l10n in the constructor with the defaults. Could we change setL10n to setL10nByAttendeed and make $attendeed not nullable and check if not null one level above?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I've made the attendee property a required one.

$language = $attendee['LANGUAGE']->getValue();
Copy link
Member

Choose a reason for hiding this comment

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

Note that LANGUAGE parameters are RFC5646 language tags (e.g de-DE), while our language system seems to be using ISO 15897 (e.g de_DE). We should do best effort to try to convert those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, We will address this in a separate PR, the L10n should automatically determine the format and pick the correct language

Copy link
Member

Choose a reason for hiding this comment

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

Is there a ticket/PR for that @SebastianKrupinski?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ticket: #56624

}
// fallback to system language if language not set
if ($language === null) {
$language = $this->l10nFactory->findGenericLanguage();
}
// fallback to system locale if locale not set
if ($locale === null) {
$locale = $this->l10nFactory->findLocale($language);
}
$this->l10n = $this->l10nFactory->get('dav', $language, $locale);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\IDBConnection;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
Expand Down Expand Up @@ -55,6 +56,7 @@ class IMipPluginCharsetTest extends TestCase {
private IUrlGenerator&MockObject $urlGenerator;
private IUserSession&MockObject $userSession;
private LoggerInterface $logger;
private IUserManager&MockObject $userManager;

// Services
private EventComparisonService $eventComparisonService;
Expand Down Expand Up @@ -86,13 +88,16 @@ protected function setUp(): void {
->willReturn('en_US');
$this->l10nFactory->method('get')
->willReturn($l10n);
$this->userManager = $this->createMock(IUserManager::class);
$this->userManager->method('getByEmail')->willReturn([]);
$this->imipService = new IMipService(
$this->urlGenerator,
$this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
$this->userManager
);

// EventComparisonService
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -32,6 +33,7 @@ class IMipServiceTest extends TestCase {
private IL10N&MockObject $l10n;
private ITimeFactory&MockObject $timeFactory;
private IMipService $service;
private IUserManager&MockObject $userManager;


private VCalendar $vCalendar1a;
Expand All @@ -51,6 +53,7 @@ protected function setUp(): void {
$this->l10nFactory = $this->createMock(IFactory::class);
$this->l10n = $this->createMock(IL10N::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->l10nFactory->expects(self::once())
->method('findGenericLanguage')
->willReturn('en');
Expand All @@ -64,7 +67,8 @@ protected function setUp(): void {
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory
$this->timeFactory,
$this->userManager
);

// construct calendar with a 1 hour event and same start/end time zones
Expand Down
Loading