Skip to content

Commit

Permalink
New: added subscribeMailbox (imap) method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruud68 committed Oct 9, 2024
1 parent 2b47a91 commit 02679a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Ddeboer\Imap\Exception\ImapNumMsgException;
use Ddeboer\Imap\Exception\ImapQuotaException;
use Ddeboer\Imap\Exception\MailboxDoesNotExistException;
use Ddeboer\Imap\Exception\SubscribeMailboxException;

/**
* A connection to an IMAP server that is authenticated for a user.
Expand Down Expand Up @@ -177,4 +178,11 @@ private function initMailboxNames(): void
$this->mailboxNames[$name] = $mailboxInfo;
}
}

public function subscribeMailbox(string $name): void

Check warning on line 182 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L182

Added line #L182 was not covered by tests
{
if (false === \imap_subscribe($this->resource->getStream(), $this->server . \mb_convert_encoding($name, 'UTF7-IMAP', 'UTF-8'))) {
throw new SubscribeMailboxException(\sprintf('Can not subscribe to "%s" mailbox at "%s"', $name, $this->server));

Check warning on line 185 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L184-L185

Added lines #L184 - L185 were not covered by tests
}
}
}
8 changes: 8 additions & 0 deletions src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ddeboer\Imap\Exception\CreateMailboxException;
use Ddeboer\Imap\Exception\DeleteMailboxException;
use Ddeboer\Imap\Exception\MailboxDoesNotExistException;
use Ddeboer\Imap\Exception\SubscribeMailboxException;

/**
* A connection to an IMAP server that is authenticated for a user.
Expand Down Expand Up @@ -76,4 +77,11 @@ public function createMailbox(string $name): MailboxInterface;
* @throws DeleteMailboxException
*/
public function deleteMailbox(MailboxInterface $mailbox): void;

/**
* Subscribe to mailbox.
*
* @throws SubscribeMailboxException
*/
public function subscribeMailbox(string $name): void;
}
7 changes: 7 additions & 0 deletions src/Exception/SubscribeMailboxException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

final class SubscribeMailboxException extends AbstractException {}

0 comments on commit 02679a0

Please sign in to comment.