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

All works except querying for specific message. #150

Closed
klukiyan opened this issue Sep 28, 2018 · 10 comments
Closed

All works except querying for specific message. #150

klukiyan opened this issue Sep 28, 2018 · 10 comments

Comments

@klukiyan
Copy link

This works:

$aMessage = $oFolder->query()->limit(10, 2)->get();

This refuses to work:

$aMessage = $oFolder->query()->text("whatever")->get();
$aMessage = $oFolder->query()->Subject("whatever")->get();
$aMessage = $oFolder->query()->Subject("whatever")->get();
$aMessage = $oFolder->query()->from('[email protected]')->get();
$aMessage = $oFolder->query()->unseen()->limit(10, 2)->get();

all the time getting empty arrays...
Any help please?
I'm using the "facade approach"

...
use Webklex\IMAP\Facades\Client;
...
$oClient = Client::account('default');
        $oClient->connect();
...
@Webklex
Copy link
Owner

Webklex commented Sep 28, 2018

Hi @klukiyan ,
just a basic question before I dive in deeper. Is there an email with the text "whatever" or the subject "whatever" or any unseen emails available? Might sound stupid, but I encountered a simular issue before ;)

Besides that your code looks fine (ecept WhereQuery::Subject() - this should be WhereQuery::subject()) to me.

Best regards

@klukiyan
Copy link
Author

klukiyan commented Sep 28, 2018

@Webklex
I have it with "Electra" in subject, and yes the folder contains it.

$aMessage = $oFolder->query()->subject('Electra')->limit(10, 2)->get();

empty array...
the querying simply doesn't seem to work.

I've just tried pure PHP and it returned me 3 messages. Something must be really wrong with query().
This returned me 3 messages:

        $imapEmails   = imap_search($imapResource, 'SUBJECT "Electra"');
        $contentItems = array();
        if ($imapEmails) {
            //Put newest emails on top
            rsort($imapEmails);
            foreach ($imapEmails as $Email) {
                //Loop through each email and return the content
                $email_overview = imap_fetch_overview($imapResource, $Email, 0);
                $email_header_info = imap_header($imapResource, $Email);
                $email_message = imap_fetchbody($imapResource, $Email, 1);
                echo $email_message."<hr>";
            }
        }
        imap_close($imapResource);

Update
It's very strange, but changing $charset = 'UTF-8' to $charset = null in Folder.php resolved the issue...

@Webklex
Copy link
Owner

Webklex commented Sep 28, 2018

$aMessage = $oFolder->query()->subject('Electra')->limit(10, 2)->get();

Is reffering to a second page where each page contains 10 messages. So in order to receive any message you would habe to have at least 11 mails matching that criteria.

Please try the following:

$aMessage = $oFolder->query(null)->subject('Electra')->limit(10, 1)->get();

Note you can parse an parameter $charset to Folder::query($charset = 'UTF-8').

Please take a look at #100 a user had an simular issue. Setting $charset to null seemed to do the trick :)

@klukiyan
Copy link
Author

@Webklex , thank you, with query(null) it wors.
My last concern is about the speed.

  • With above mentioned php code I'm getting the bodies of the 3 searched messages in 2 seconds (the inbox is really huge, it is on slow distant exchange server).
  • When using your package, code is simpler and shorter, but I get the response in 6-8 seconds.
    I've tried many times, the result is the same. I've tried to make the query as short as possible, it's still considerably slower.
    Can you give me a hint what I could optimize to get flawless experience for my users.
    This is the shortes option I could get:
//this gets me into 6-8 seconds.
$oClient->connect();
$aMessage = $oClient->getFolder('INBOX')->query(null)->text('Electra')->get();
foreach ($aMessage as $oMessage) {
    echo $oMessage->getHtmlBody(true);
}

I want to use your package, especially when it comes to working with attachments. But the speed is really a concern. Can you give me a hint how can I make it faster?

@Webklex
Copy link
Owner

Webklex commented Sep 29, 2018

If you want to decrease the loading time you could as well fetch bodys and attachments later.

$oFolder->query(null)->setFetchFlags(false) ->setFetchBody(false)->setFetchAttachment(false);

Your mentioned plain php code does'nt fetch all attachments, thats probably why its faster. This library also does some encoding etc which might take a few additional ms. However feel free to create a fork and remove everything you don't need - that's probably the best in order to get the most out of it :)

@klukiyan
Copy link
Author

@Webklex That's a good hint.
Now if I don't fetch the body/flags/attachments and I want to display the body + attachments when I click on the message, how to I query directly that single message please?
Sorry if this question is too silly.

@Webklex
Copy link
Owner

Webklex commented Sep 29, 2018

There are several possibilities. Here are two examples:

https://github.com/Webklex/laravel-imap#fetch-a-specific-message

$oMessage = $oFolder->getMessage($uid = 1);

..or by token if you want to be a bit more "bullet proof", since the uid isn't always unique:
#136

@klukiyan
Copy link
Author

Great
Thank you very much, @Webklex

@dharmendravirasat
Copy link

$oMessage = $oFolder->getMessage($uid = 1);
can't working please answer

@Webklex
Copy link
Owner

Webklex commented Nov 24, 2018

@dharmendravirasat that could be caused by a ton of things. Please provide more information and if it isn't related to this issue, please consider to open a new issue.

Best regards

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