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

since() query returning empty response #215

Closed
alen125 opened this issue Apr 30, 2019 · 9 comments
Closed

since() query returning empty response #215

alen125 opened this issue Apr 30, 2019 · 9 comments

Comments

@alen125
Copy link

alen125 commented Apr 30, 2019

Hello,

I have an issue while querying messages by date from the server, and I get an empty result when there should be new messages.
Here is the example of it:

$messages = $this->emailClient  
                 ->getFolder("Inbox")  
                 ->query()  
                 ->since('28.04.2019')  
                 ->get();  

I've tried several ways of doing this. Some of them are:

  • sending Carbon instance in since() method e.g. ->since(Carbon::now()->subDays(2))
  • building custom query using where() method with SINCE key e.g. ->where(['SINCE', Carbon::parse('15.03.2018')])

but none of them work. In the above example, if I remove since() method everything works and I get all messages from that folder.

The only way that I could do this now is to get all messages from that folder and then parse it, which takes a lot of time since there are many messages in that folder.

I'm connecting to IMAP Outlook server for this purpose.
IMAP Package version is "1.4.1".
Running PHP 7.2 on Ubuntu.

Is there another way or am I doing something wrong?

Other than that, everything works fine.

@JonahKlimack
Copy link

same problem here as well:

		$date = date('d.m.Y', time()-(86400*1));
		$mailsIds = $mailbox->searchMailbox('UNSEEN SINCE "'.$date.'"');
		dump($mailsIds);
		foreach($mailsIds as $key => $mailId)
		{
			dump($key);
			// dump($mailId);

			$message = $mailbox->getMail($mailId, true);
			dump($message);
		}

if the date is in a different format, like 14 May 2019 then i'll get an error message:

  2103 => 1649513
  2104 => 1649514
  2105 => 1649515
  2106 => 1649516
  2107 => 1649517
  2108 => 1649518
]
0
Whoops, looks like something went wrong.
1/1
ErrorException in Mailbox.php line 539:
imap_fetchheader(): Bad message number

@todorowww
Copy link
Contributor

todorowww commented Jun 19, 2019

Date format for SINCE should be DD-MMM-YYYY, IMAP protocol doesn't accept just any format.

From IMAP specs:

date = date-text / DQUOTE date-text DQUOTE

date-day = 1*2DIGIT
; Day of month

date-month = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /
"Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"

date-text = date-day "-" date-month "-" date-year

date-year = 4DIGIT

This works for me:
$messages = $folder->query(null)->since($since->format('d-M-Y'))->get();

@Webklex
Copy link
Owner

Webklex commented Jun 19, 2019

Hi @todorowww ,
I've experienced that only "d M y" works for me. Guess there are multiple "correct" formats?

If you take a look at https://tools.ietf.org/html/rfc2822 section "3.3. Date and Time Specification" which is referred by https://tools.ietf.org/html/rfc1064 "d M y" should be used but rfc1064 provides an example with "d-M-y". Now it seems like "d-M-Y" is valid as well. Where didi you find "d-M-Y"? :)

Best regards

Update:
Btw if you parse Query::since() a carbon object it will be converted into a rfc2822 compliant string.

Update II:
@todorowww are you using a windows based mail server? Windows seems to be special in many ways regarding any mail related rfc standard.

@alen125
Copy link
Author

alen125 commented Jun 19, 2019

@todorowww solution worked for me

This works for me:
$messages = $folder->query(null)->since($since->format('d-M-Y'))->get();

I've tested this by sending request on Outlook server and got the correct response

Also I've added time according to rfc1064 like this

$messages = $folder->query(null)->since($since->format('d-M-Y H:i:s-z'))->get();

Thanks :)

@lomotech
Copy link
Contributor

lomotech commented Jun 20, 2019

I have this problem too;
If I'm using query() it will return empty response.
But query(null) is work for me, but why?

@Webklex
Copy link
Owner

Webklex commented Jun 20, 2019

Hi @lomotech ,
that's a windows feature :)

If you want to know more about it, please head over to these issues: #153 #100 #78

Best regards

@todorowww
Copy link
Contributor

Hey @Webklex
Yes, Windows/Outlook implementations of IMAP are indeed fun, and full of "features". My latest project has to connect to Office365 servers, and it was quite the ride. For all the projects where we had the need for IMAP, we used d-M-Y and it always worked only with this format. I guess it really does come down to IMAP implementation, and there are multiple correct formats.

I've found the data in the RFC3501 - IMAP v4r1 (page 84 has the date spec)

What I think is the "issue", is that SINCE uses internal date, instead of RFC2822 date in the headers. And obviously, some implementations are perhaps stricter, or looser, in upholding the standard.

SENTSINCE <date> Messages whose [RFC-2822] Date: header (disregarding time and timezone) is within or later than the specified date.

SINCE <date> Messages whose internal date (disregarding time and timezone) is within or later than the specified date.

2.3.3. Internal Date Message Attribute
The internal date and time of the message on the server. This is not the date and time in the [RFC-2822] header, but rather a date and time which reflects when the message was received.

@Webklex Webklex added this to the v. 1.4.2 milestone Jun 20, 2019
@jagoanmamah
Copy link

same problem -_-

@Webklex
Copy link
Owner

Webklex commented Jun 27, 2019

I've added a new config parameter so everyone is free to choose what ever works best :) Please take a look at the current config/imap.php file for more information.

@Webklex Webklex closed this as completed Jun 27, 2019
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

6 participants