Skip to content
Open
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
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@
'url' => '/api/settings/llm',
'verb' => 'PUT'
],
[
'name' => 'settings#setMessageIdPrefix',
'url' => '/api/settings/messageidprefix',
'verb' => 'POST'
],
[
'name' => 'settings#setImportanceClassificationEnabledByDefault',
'url' => '/api/settings/importance-classification-default',
Expand Down
7 changes: 7 additions & 0 deletions lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ConfigLexicon implements ILexicon {
public const MICROSOFT_OAUTH_TENANT_ID = 'microsoft_oauth_tenant_id';
public const ANTISPAM_REPORTING_SPAM = 'antispam_reporting_spam';
public const ANTISPAM_REPORTING_HAM = 'antispam_reporting_ham';
public const MESSAGE_ID_PREFIX = 'message_id_prefix';

#[\Override]
public function getStrictness(): Strictness {
Expand Down Expand Up @@ -113,6 +114,12 @@ public function getAppConfigs(): array {
ValueType::STRING,
definition: 'Email address ham (not spam) reports are forwarded to',
),
new Entry(
self::MESSAGE_ID_PREFIX,
ValueType::STRING,
defaultRaw: 'nextcloud-mail',
definition: 'Default message ID prefix to use for outgoing mail',
),
];
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public function setEnabledLlmProcessing(bool $enabled): JSONResponse {
$this->appConfig->setValueBool(Application::APP_ID, ConfigLexicon::LLM_PROCESSING, $enabled);
return new JSONResponse([]);
}

public function setMessageIdPrefix(string $prefix): JSONResponse {
$this->appConfig->setValueString(Application::APP_ID, ConfigLexicon::MESSAGE_ID_PREFIX, $prefix);
return new JSONResponse([]);
}

public function setLayoutMessageView(string $value): JSONResponse {
$this->appConfig->setValueString(Application::APP_ID, ConfigLexicon::LAYOUT_MESSAGE_VIEW, $value);
return new JSONResponse([]);
Expand Down
18 changes: 16 additions & 2 deletions lib/Service/MailTransmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use OCA\Mail\Account;
use OCA\Mail\Address;
use OCA\Mail\AddressList;
use OCA\Mail\AppInfo\Application;
use OCA\Mail\ConfigLexicon;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Contracts\IMailTransmission;
use OCA\Mail\Db\LocalMessage;
Expand All @@ -50,6 +52,7 @@
use OCA\Mail\Support\PerformanceLogger;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use Psr\Log\LoggerInterface;
use Throwable;

Expand All @@ -71,6 +74,7 @@ public function __construct(
private AliasesService $aliasesService,
private TransmissionService $transmissionService,
private IMailManager $mailManager,
private IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -114,7 +118,12 @@ public function sendMessage(Account $account, LocalMessage $localMessage): void
// approach used by Horde IMP and other clients (Evolution, Thunderbird).
$fccHeaders = new Horde_Mime_Headers();
$fccHeaders->addHeaderOb(Horde_Mime_Headers_Date::create());
$fccHeaders->addHeaderOb(Horde_Mime_Headers_MessageId::create());
$prefix = $this->appConfig->getValueString(
Application::APP_ID,
ConfigLexicon::MESSAGE_ID_PREFIX,
'nextcloud-mail',
);
$fccHeaders->addHeaderOb(Horde_Mime_Headers_MessageId::create($prefix));
$fccHeaders->addHeaderOb(new Horde_Mime_Headers_Addresses('From', $from->toHorde()));
$fccHeaders->addHeaderOb(new Horde_Mime_Headers_Addresses('To', $to->toHorde()));
if (count($cc) > 0) {
Expand Down Expand Up @@ -376,7 +385,12 @@ public function saveDraft(NewMessageData $message, ?Message $previousDraft = nul
private function buildMimeHeaders(Address $from, AddressList $to, AddressList $cc, AddressList $bcc, ?string $subject): Horde_Mime_Headers {
$headers = new Horde_Mime_Headers();
$headers->addHeaderOb(Horde_Mime_Headers_Date::create());
$headers->addHeaderOb(Horde_Mime_Headers_MessageId::create());
$prefix = $this->appConfig->getValueString(
Application::APP_ID,
ConfigLexicon::MESSAGE_ID_PREFIX,
'nextcloud-mail',
);
$headers->addHeaderOb(Horde_Mime_Headers_MessageId::create($prefix));
$headers->addHeaderOb(new Horde_Mime_Headers_Addresses('From', $from->toHorde()));
$headers->addHeaderOb(new Horde_Mime_Headers_Addresses('To', $to->toHorde()));
if (count($cc) > 0) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function getForm() {
$this->themingDefaults->buildDocLinkToKey('admin-groupware-oauth-microsoft'),
);

$this->initialStateService->provideInitialState(
'message_id_prefix',
$this->appConfig->getValueString(Application::APP_ID, ConfigLexicon::MESSAGE_ID_PREFIX, 'nextcloud-mail')
);

return new TemplateResponse(Application::APP_ID, 'settings-admin');
}

Expand Down
34 changes: 34 additions & 0 deletions src/components/settings/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,28 @@
</p>
</article>
</div>
<div class="app-description">
<h3>{{ t('mail', 'Message-ID prefix') }}</h3>
<article>
<p>
{{ t('mail', 'This setting is used to customize the prefix in the RFC 5322 compliant Message-ID header for outgoing mail.') }}
</p>
</article>
<br>
<article>
<form @submit.prevent="updateMessageIdPrefix">
<label for="mail-message-id-prefix"> {{ t('mail', 'Message-ID prefix') }} </label>
<input
id="mail-message-id-prefix"
v-model="messageIdPrefixVal"
:disabled="loading"
type="text">
<button type="submit" :disabled="loading" class="primary">
{{ t('mail', 'Update') }}
</button>
</form>
</article>
</div>
</NcSettingsSection>
</template>

Expand All @@ -302,6 +324,7 @@ import {
updateAllowNewMailAccounts,
updateEnabledSmartReply,
updateLlmEnabled,
updateMessageIdPrefix,
updateProvisioningSettings,
} from '../../service/SettingsService.js'

Expand Down Expand Up @@ -330,12 +353,19 @@ export default {
type: Array,
required: true,
},

messageIdPrefix: {
type: String,
required: true,
},
},

data() {
return {
addNew: false,
loading: false,
formKey: Math.random(),
messageIdPrefixVal: this.messageIdPrefix,
configs: this.provisioningSettings,
googleOauthClientId,
googleOauthRedirectUrl,
Expand Down Expand Up @@ -436,6 +466,10 @@ export default {
await updateLlmEnabled(checked)
},

async updateMessageIdPrefix() {
await updateMessageIdPrefix(this.messageIdPrefixVal)
},

async updateEnabledSmartReply(checked) {
await updateEnabledSmartReply(checked)
},
Expand Down
1 change: 1 addition & 0 deletions src/main-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ const View = Vue.extend(AdminSettings)
new View({
propsData: {
provisioningSettings: loadState('mail', 'provisioning_settings') || [],
messageIdPrefix: loadState('mail', 'message_id_prefix') || 'nextcloud-mail',
},
}).$mount('#mail-admin-settings')
9 changes: 9 additions & 0 deletions src/service/SettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ export async function updateLlmEnabled(enabled) {
return resp.data
}

export async function updateMessageIdPrefix(prefix) {
const url = generateUrl('/apps/mail/api/settings/messageidprefix')
const data = {
prefix,
}
const resp = await axios.post(url, data)
return resp.data
}

export async function updateEnabledSmartReply(enabled) {
const url = generateUrl('/apps/mail/api/settings/smartreply')
const data = {
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/ConfigLexiconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function appConfigProvider(): array {
ConfigLexicon::MICROSOFT_OAUTH_TENANT_ID => [ValueType::STRING, 'common'],
ConfigLexicon::ANTISPAM_REPORTING_SPAM => [ValueType::STRING, null],
ConfigLexicon::ANTISPAM_REPORTING_HAM => [ValueType::STRING, null],
ConfigLexicon::MESSAGE_ID_PREFIX => [ValueType::STRING, 'nextcloud-mail'],
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Service/MailTransmissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCA\Mail\Support\PerformanceLogger;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

Expand All @@ -51,6 +52,7 @@ class MailTransmissionTest extends TestCase {
private MailTransmission $transmission;
private AliasesService|MockObject $aliasService;
private TransmissionService $transmissionService;
private IAppConfig $appConfig;

protected function setUp(): void {
parent::setUp();
Expand All @@ -65,6 +67,7 @@ protected function setUp(): void {
$this->aliasService = $this->createMock(AliasesService::class);
$this->transmissionService = $this->createMock(TransmissionService::class);
$this->mailManager = $this->createMock(IMailManager::class);
$this->appConfig = $this->createMock(IAppConfig::class);

$this->transmission = new MailTransmission(
$this->imapClientFactory,
Expand All @@ -77,6 +80,7 @@ protected function setUp(): void {
$this->aliasService,
$this->transmissionService,
$this->mailManager,
$this->appConfig,
);
}

Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/Settings/AdminSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testGetSection() {
}

public function testGetForm() {
$this->serviceMock->getParameter('initialStateService')->expects($this->exactly(14))
$this->serviceMock->getParameter('initialStateService')->expects($this->exactly(15))
->method('provideInitialState')
->withConsecutive(
[
Expand Down Expand Up @@ -96,6 +96,10 @@ public function testGetForm() {
'microsoft_oauth_docs',
$this->anything()
],
[
'message_id_prefix',
$this->anything()
],
);
$expected = new TemplateResponse(Application::APP_ID, 'settings-admin');

Expand Down