Skip to content

Commit

Permalink
feature: mail provider backend
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
  • Loading branch information
SebastianKrupinski committed Jun 6, 2024
1 parent d221ede commit ac83ff7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
5 changes: 4 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ public function register(IRegistrationContext $context): void {
}

// register mail provider
$context->registerMailProvider(MailProvider::class);
// TODO: drop condition if nextcloud < 30 is not supported anymore
if (interface_exists(MailProvider::class)) {
$context->registerMailProvider(MailProvider::class);

Check failure on line 182 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedInterfaceMethod

lib/AppInfo/Application.php:182:14: UndefinedInterfaceMethod: Method OCP\AppFramework\Bootstrap\IRegistrationContext::registerMailProvider does not exist (see https://psalm.dev/181)

Check failure on line 182 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

UndefinedInterfaceMethod

lib/AppInfo/Application.php:182:14: UndefinedInterfaceMethod: Method OCP\AppFramework\Bootstrap\IRegistrationContext::registerMailProvider does not exist (see https://psalm.dev/181)

Check failure on line 182 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedInterfaceMethod

lib/AppInfo/Application.php:182:14: UndefinedInterfaceMethod: Method OCP\AppFramework\Bootstrap\IRegistrationContext::registerMailProvider does not exist (see https://psalm.dev/181)

Check failure on line 182 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable27

UndefinedInterfaceMethod

lib/AppInfo/Application.php:182:14: UndefinedInterfaceMethod: Method OCP\AppFramework\Bootstrap\IRegistrationContext::registerMailProvider does not exist (see https://psalm.dev/181)
}

$context->registerNotifierService(Notifier::class);

Expand Down
34 changes: 13 additions & 21 deletions lib/Provider/Command/MessageSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@
use OCA\Mail\Service\Attachment\AttachmentService;
use OCA\Mail\Service\OutboxService;
use OCA\Mail\Service\SmimeService;
use OCP\IConfig;
use OCP\Mail\Provider\IMessage;

class MessageSend {

public function __construct(
AccountService $accountService,
OutboxService $outboxService,
AttachmentService $attachmentService,
SmimeService $smimeService
protected IConfig $config,
protected AccountService $accountService,
protected OutboxService $outboxService,
protected AttachmentService $attachmentService,
protected SmimeService $smimeService
) {
$this->accountService = $accountService;
$this->outboxService = $outboxService;
$this->attachmentService = $attachmentService;
$this->smimeService = $smimeService;
}

public function perform(string $userId, string $serviceId, IMessage $message, array $option = []): void {

Check failure on line 47 in lib/Provider/Command/MessageSend.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Provider/Command/MessageSend.php:47:61: UndefinedClass: Class, interface or enum named OCP\Mail\Provider\IMessage does not exist (see https://psalm.dev/019)

Check failure on line 47 in lib/Provider/Command/MessageSend.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

UndefinedClass

lib/Provider/Command/MessageSend.php:47:61: UndefinedClass: Class, interface or enum named OCP\Mail\Provider\IMessage does not exist (see https://psalm.dev/019)

Check failure on line 47 in lib/Provider/Command/MessageSend.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Provider/Command/MessageSend.php:47:61: UndefinedClass: Class, interface or enum named OCP\Mail\Provider\IMessage does not exist (see https://psalm.dev/019)

Check failure on line 47 in lib/Provider/Command/MessageSend.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable27

UndefinedClass

lib/Provider/Command/MessageSend.php:47:61: UndefinedClass: Class, interface or enum named OCP\Mail\Provider\IMessage does not exist (see https://psalm.dev/019)
Expand All @@ -55,20 +53,9 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
$lm->setAccountId($account->getId());
$lm->setSubject($message->getSubject());
$lm->setBody($message->getBody());
//$lm->setEditorBody($editorBody);
$lm->setHtml(true);
//$lm->setInReplyToMessageId($inReplyToMessageId);
$lm->setSendAt(time());
//$lm->setSmimeSign($smimeSign);
//$lm->setSmimeEncrypt($smimeEncrypt);

/*
if (!empty($smimeCertificateId)) {
$smimeCertificate = $this->smimeService->findCertificate($smimeCertificateId, $this->userId);
$lm->setSmimeCertificateId($smimeCertificate->getId());
}
*/


// convert all mail provider attachments to local attachments
$attachments = [];
if (count($message->getAttachments()) > 0) {
Expand All @@ -86,7 +73,7 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
$to = $this->convertAddressArray($message->getTo());
$cc = $this->convertAddressArray($message->getCc());
$bcc = $this->convertAddressArray($message->getBcc());
// save/send message
// save message for sending
$lm = $this->outboxService->saveMessage(
$account,
$lm,
Expand All @@ -96,6 +83,11 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
$attachments
);

// evaluate if job scheduler is NOT cron, send message right away otherwise let cron job handle it
if ($this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') !== 'cron') {
$lm = $this->outboxService->sendMessage($lm, $account);
}

}

protected function convertAddressArray(array|null $in) {
Expand Down

0 comments on commit ac83ff7

Please sign in to comment.