Gmail imap_search and imap_mail_move not working as expected

I am loading the list of emails from Gmail with imap. The list of ids return, they are just listed like 1, 2, 3, even though I am using “SE_UID” which is supposed to return a proper unique id.
$mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID, $this->serverEncoding);

Also, moving the mail does nothing. I have tried $mailBox=“[Gmail]/Trash”, $mailBox=“[Gmail]/Starred”, etc. I have tried both with and without CP_UID.

imap_mail_move($this->getImapStream(), $mailId, $mailBox, CP_UID);
imap_expunge($this->getImapStream());

Receiving the actual email body works fine:
imap_fetchstructure($this->getImapStream(), $mailId, FT_UID);

Welcome to SitePoint.

What does your imap_open command look like?

UID’s in imap are still integers.

It’s dynamically generated, but I did my best to recreate it:

imap_open({pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX,myemail@gmail.com,mypassword,0,0,Array())

and are you invoking imap_expunge to clean up after you’re done moving?

EDIT: I can read. derp.

Is getImapStream opening a new connection over and over? (My thoughts: If getImapStream is opening a new stream every time, then your expunge call isnt operating on the same thread as the move, which may be causing problems.)

That doesn’t seem to be the case.

Is there another reason imap_mail_move() would not work on Gmail? The $mailBox that I am trying is what I could find online for what should work for Gmail.

My suspicion was the $mailId was the issue as the ids returned didn’t look correct, but I could be way off. I’m getting the actual email contents fine, so who knows.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.