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 26, 2024
1 parent 22a2f68 commit 3ef1f9f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
16 changes: 8 additions & 8 deletions lib/Provider/Command/MessageSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function __construct(
*
* @since 4.0.0
*
* @param string $userId system user id
* @param string $serviceId mail account id
* @param IMessage $message mail message object with all required parameters to send a message
* @param array $options array of options reserved for future use
* @param string $userId system user id
* @param string $serviceId mail account id
* @param IMessage $message mail message object with all required parameters to send a message
* @param array $options array of options reserved for future use
*
* @return LocalMessage
*/
public function perform(string $userId, string $serviceId, IMessage $message, array $option = []): LocalMessage {
// find user mail account details
$account = $this->accountService->find($userId, (int) $serviceId);
$account = $this->accountService->find($userId, (int)$serviceId);
// convert mail provider message to mail app message
$localMessage = new LocalMessage();
$localMessage->setType($localMessage::TYPE_OUTGOING);
Expand All @@ -62,7 +62,7 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
foreach ($message->getAttachments() as $entry) {
// determine if required parameters are set
if (empty($entry->getName()) || empty($entry->getType()) || empty($entry->getContents())) {
throw new SendException("Invalid Attachment Parameter: MUST contain values for Name, Type and Contents");
throw new SendException('Invalid Attachment Parameter: MUST contain values for Name, Type and Contents');
}
// convert mail provider attachment to mail app attachment
$attachments[] = $this->attachmentService->addFileFromString(
Expand All @@ -75,7 +75,7 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
}
// determine if required To address is set
if (empty($message->getTo()) || empty($message->getTo()[0]->getAddress())) {
throw new SendException("Invalid Message Parameter: MUST contain at least one TO address with a valid address");
throw new SendException('Invalid Message Parameter: MUST contain at least one TO address with a valid address');
}
// convert recipient addresses
$to = $this->convertAddressArray($message->getTo());
Expand Down Expand Up @@ -105,7 +105,7 @@ public function perform(string $userId, string $serviceId, IMessage $message, ar
*
* @since 4.0.0
*
* @param array<int,IAddress> $addresses collection of IAddress objects
* @param array<int,IAddress> $addresses collection of IAddress objects
*
* @return array<int,array{email: string, label?: string}>
*/
Expand Down
38 changes: 19 additions & 19 deletions lib/Provider/MailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
*
* @since 4.0.0
*
* @return string id of this provider (e.g. UUID or 'IMAP/SMTP' or anything else)
* @return string id of this provider (e.g. UUID or 'IMAP/SMTP' or anything else)
*/
public function id(): string {
return 'mail-application';
Expand All @@ -41,7 +41,7 @@ public function id(): string {
*
* @since 4.0.0
*
* @return string label/name of this provider (e.g. Plain Old IMAP/SMTP)
* @return string label/name of this provider (e.g. Plain Old IMAP/SMTP)
*/
public function label(): string {
return 'Mail Application';
Expand All @@ -52,9 +52,9 @@ public function label(): string {
*
* @since 4.0.0
*
* @param string $userId system user id
* @param string $userId system user id
*
* @return bool true if any services are configure for the user
* @return bool true if any services are configure for the user
*/
public function hasServices(string $userId): bool {
return (count($this->listServices($userId)) > 0);
Expand All @@ -65,9 +65,9 @@ public function hasServices(string $userId): bool {
*
* @since 4.0.0
*
* @param string $userId system user id
* @param string $userId system user id
*
* @return array<string,IService> collection of service id and object ['1' => IServiceObject]
* @return array<string,IService> collection of service id and object ['1' => IServiceObject]
*/
public function listServices(string $userId): array {

Expand All @@ -82,7 +82,7 @@ public function listServices(string $userId): array {
// add services to collection
foreach ($accounts as $entry) {
// extract values
$serviceId = (string) $entry->getId();
$serviceId = (string)$entry->getId();
$label = $entry->getName();
$address = new MailAddress($entry->getEmail(), $entry->getName());
// add service to collection
Expand All @@ -98,13 +98,13 @@ public function listServices(string $userId): array {
*
* @since 4.0.0
*
* @param string $userId system user id
* @param string $serviceId mail account id
* @param string $userId system user id
* @param string $serviceId mail account id
*
* @return IService|null returns service object or null if none found
* @return IService|null returns service object or null if none found
*
*/
public function findServiceById(string $userId, string $serviceId): IService | null {
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)) {
Expand All @@ -113,13 +113,13 @@ public function findServiceById(string $userId, string $serviceId): IService | n

try {
// retrieve service details from data store
$account = $this->accountService->find($userId, (int) $serviceId);
$account = $this->accountService->find($userId, (int)$serviceId);
} catch(\Throwable $th) {
return null;
}

// extract values
$serviceId = (string) $account->getId();
$serviceId = (string)$account->getId();
$label = $account->getName();
$address = new MailAddress($account->getEmail(), $account->getName());
// return mail service object
Expand All @@ -132,12 +132,12 @@ public function findServiceById(string $userId, string $serviceId): IService | n
*
* @since 4.0.0
*
* @param string $userId system user id
* @param string $address mail address (e.g. [email protected])
* @param string $userId system user id
* @param string $address mail address (e.g. [email protected])
*
* @return IService|null returns service object or null if none found
* @return IService|null returns service object or null if none found
*/
public function findServiceByAddress(string $userId, string $address): IService | null {
public function findServiceByAddress(string $userId, string $address): IService|null {

try {
// retrieve service details from data store
Expand All @@ -148,7 +148,7 @@ public function findServiceByAddress(string $userId, string $address): IService
// evaluate if service details where found
if (isset($accounts[0])) {
// extract values
$serviceId = (string) $accounts[0]->getId();
$serviceId = (string)$accounts[0]->getId();
$serviceLabel = $accounts[0]->getName();
$serviceAddress = new MailAddress($accounts[0]->getEmail(), $accounts[0]->getName());
// return mail service object
Expand All @@ -164,7 +164,7 @@ public function findServiceByAddress(string $userId, string $address): IService
*
* @since 4.0.0
*
* @return IService fresh service object
* @return IService fresh service object
*/
public function initiateService(): IService {

Expand Down
34 changes: 17 additions & 17 deletions lib/Provider/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
*
* @since 4.0.0
*
* @return string id of this service (e.g. 1 or service1 or anything else)
* @return string id of this service (e.g. 1 or service1 or anything else)
*/
public function id(): string {

Expand All @@ -50,15 +50,15 @@ public function id(): string {
*
* @since 4.0.0
*
* @param string $value required ability e.g. 'MessageSend'
* @param string $value required ability e.g. 'MessageSend'
*
* @return bool true/false if ability is supplied and found in collection
* @return bool true/false if ability is supplied and found in collection
*/
public function capable(string $value): bool {

// evaluate if required ability exists
if (isset($this->serviceAbilities[$value])) {
return (bool) $this->serviceAbilities[$value];
return (bool)$this->serviceAbilities[$value];
}

return false;
Expand All @@ -70,7 +70,7 @@ public function capable(string $value): bool {
*
* @since 4.0.0
*
* @return array collection of abilities otherwise empty collection
* @return array collection of abilities otherwise empty collection
*/
public function capabilities(): array {

Expand All @@ -83,7 +83,7 @@ public function capabilities(): array {
*
* @since 4.0.0
*
* @return string label/name of service (e.g. ACME Company Mail Service)
* @return string label/name of service (e.g. ACME Company Mail Service)
*/
public function getLabel(): string {

Expand All @@ -96,9 +96,9 @@ public function getLabel(): string {
*
* @since 4.0.0
*
* @param string $value label/name of service (e.g. ACME Company Mail Service)
* @param string $value label/name of service (e.g. ACME Company Mail Service)
*
* @return self return this object for command chaining
* @return self return this object for command chaining
*/
public function setLabel(string $value): self {

Expand All @@ -112,7 +112,7 @@ public function setLabel(string $value): self {
*
* @since 4.0.0
*
* @return IAddress mail address object
* @return IAddress mail address object
*/
public function getPrimaryAddress(): IAddress {

Expand All @@ -126,9 +126,9 @@ public function getPrimaryAddress(): IAddress {
*
* @since 4.0.0
*
* @param IAddress $value mail address object
* @param IAddress $value mail address object
*
* @return self return this object for command chaining
* @return self return this object for command chaining
*/
public function setPrimaryAddress(IAddress $value): self {

Expand All @@ -142,7 +142,7 @@ public function setPrimaryAddress(IAddress $value): self {
*
* @since 4.0.0
*
* @return array<int, IAddress> collection of mail address object [IAddress, IAddress]
* @return array<int, IAddress> collection of mail address object [IAddress, IAddress]
*/
public function getSecondaryAddresses(): array {

Expand All @@ -156,9 +156,9 @@ public function getSecondaryAddresses(): array {
*
* @since 4.0.0
*
* @param IAddress ...$value collection of one or more mail address object
* @param IAddress ...$value collection of one or more mail address object
*
* @return self return this object for command chaining
* @return self return this object for command chaining
*/
public function setSecondaryAddresses(IAddress ...$value): self {

Expand All @@ -172,7 +172,7 @@ public function setSecondaryAddresses(IAddress ...$value): self {
*
* @since 30.0.0
*
* @return IMessage fresh message object
* @return IMessage fresh message object
*/
public function initiateMessage(): IMessage {

Expand All @@ -185,8 +185,8 @@ public function initiateMessage(): IMessage {
*
* @since 4.0.0
*
* @param IMessage $message mail message object with all required parameters to send a message
* @param array $options array of options reserved for future use
* @param IMessage $message mail message object with all required parameters to send a message
* @param array $options array of options reserved for future use
*
* @throws \OCP\Mail\Provider\Exception\SendException on failure, check message for reason
*/
Expand Down

0 comments on commit 3ef1f9f

Please sign in to comment.