Skip to content

Commit

Permalink
feat: mail provider backend
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Aug 28, 2024
1 parent d90ef40 commit 2fc934d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
3 changes: 0 additions & 3 deletions lib/Provider/Command/MessageSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
//$localMessage->setEditorBody($message->getBody());
$localMessage->setHtml(true);
$localMessage->setSendAt($this->time->getTime());

// convert all mail provider attachments to local attachments
$attachments = [];
if (count($message->getAttachments()) > 0) {
Expand Down Expand Up @@ -90,14 +89,12 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
$bcc,
$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') {
$localMessage = $this->outboxService->sendMessage($localMessage, $account);
}

return $localMessage;

}

/**
Expand Down
20 changes: 5 additions & 15 deletions lib/Provider/MailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public function hasServices(string $userId): bool {
* @return array<string,IService> collection of service id and object ['1' => IServiceObject]
*/
public function listServices(string $userId): array {

// retrieve service(s) details from data store
try {
// retrieve service(s) details from data store
$accounts = $this->accountService->findByUserId($userId);
} catch (\Throwable $e) {
$this->logger->error('Error occurred while retrieving mail account details', [ 'exception' => $e ]);
Expand All @@ -87,7 +86,6 @@ public function listServices(string $userId): array {
}
// return list of services for user
return $services;

}

/**
Expand All @@ -102,23 +100,19 @@ public function listServices(string $userId): array {
*
*/
public function findServiceById(string $userId, string $serviceId): IService|null {

// determine if a valid user and service id was submitted
if (empty($userId) && !ctype_digit($serviceId)) {
return null;
}

try {
// retrieve service details from data store
// retrieve service details from data store
try {
$account = $this->accountService->find($userId, (int)$serviceId);
} catch(\Throwable $e) {
$this->logger->error('Error occurred while retrieving mail account details', [ 'exception' => $e ]);
return null;
}

// return mail service object
return $this->serviceFromAccount($userId, $account);

}

/**
Expand All @@ -132,9 +126,8 @@ public function findServiceById(string $userId, string $serviceId): IService|nul
* @return IService|null returns service object or null if none found
*/
public function findServiceByAddress(string $userId, string $address): IService|null {

// retrieve service details from data store
try {
// retrieve service details from data store
$accounts = $this->accountService->findByUserIdAndAddress($userId, $address);
} catch(\Throwable $e) {
$this->logger->error('Error occurred while retrieving mail account details', [ 'exception' => $e ]);
Expand All @@ -147,7 +140,6 @@ public function findServiceByAddress(string $userId, string $address): IService|
}

return null;

}

/**
Expand All @@ -167,19 +159,17 @@ public function initiateService(): IService {
* @since 4.0.0
*
* @param string $userId system user id
* @param string $account mail account
* @param Account $account mail account
*
* @return IService service object
*/
protected function serviceFromAccount(string $userId, Account $account): IService {

// extract values
$serviceId = (string)$account->getId();
$serviceLabel = $account->getName();
$serviceAddress = new MailAddress($account->getEmail(), $account->getName());
// return mail service object
return new MailService($this->container, $userId, $serviceId, $serviceLabel, $serviceAddress);

}

}

0 comments on commit 2fc934d

Please sign in to comment.