Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I specify a single folder? #48

Closed
Amos1st opened this issue Dec 12, 2017 · 3 comments
Closed

How can I specify a single folder? #48

Amos1st opened this issue Dec 12, 2017 · 3 comments

Comments

@Amos1st
Copy link

Amos1st commented Dec 12, 2017

Hello,
I can get all folders through $client->getFolders() , but if I would like to specify a single one, example INBOX, how can I do for it? like this: foreach the mailboxes and then judge the condition if ($mailbox->name === 'INBOX') ? pls give me some advise!

look forward your reply, thanks in advance

@GuiAndra
Copy link

GuiAndra commented Dec 12, 2017

Hello, I did it that way, maybe it would help you.

    $oClient->connect();

    $folder = new Folder($oClient, (object)['name' => '{$host/imap/novalidate-cert/ssl}INBOX', 'attributes' => 32, 'delimiter' => '.']);

    $messages = $oClient->getMessages($folder, 'SINCE '.Carbon::parse(date('Y-m-d'))->subDays(5)->format('Y-m-d'));

@Webklex
Copy link
Owner

Webklex commented Dec 12, 2017

Hi @Amos1st ,
I don't think its currently possible but I would like to implement a feature which would allow such a behavior.

Inspired by @GuiAndra it might look like something similar to this:

$oClient->connect();
$oFolder = \Webklex\Facade\Folder::get('INBOX.sample');
$aMessage = $oClient->getMessages($folder, ....);

Best regards

@Webklex
Copy link
Owner

Webklex commented Jan 1, 2018

Hi @Amos1st ,
please update to v. 1.0.3.11 and take a look at the new README.md. I added a new Funktion to the Client class in order to get a folder instance by name.

Short description:

use Webklex\IMAP\Facades\Client;

/** @var \Webklex\IMAP\Client $oClient */
$oClient = Client::account('default');
$oClient->connect();

/** @var \Webklex\IMAP\Folder $oFolder */
$oFolder = $oClient->getFolder('INBOX.name');

/** @var \Webklex\IMAP\Message $oMessage */
foreach($oFolder->getMessages() as $oMessage){
    echo $oMessage->subject.'<br />';
}

Best regards

@Webklex Webklex closed this as completed Jan 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants