php-imap
php-imap copied to clipboard
delete method not working on Gmail
At least on Gmail, I can't get delete to work. It returns true, but does nothing. Manually set 'Deleted' flag on a message does nothing as well.
Am I noobing here?
Here is a very good explanation on the why the "\Deleted" flag does nothing on Gmail: http://yz.mit.edu/wp/gmail-and-imap/
Resume: On Gmail, add "\Deleted" flag is not enough, you need to move the message to "[Gmail]/Trash" as well.
The main problem to me now is that if I move the message to Trash, I get hit by #105 problem.
Hi @EthraZa , thanks for the followup. I'll add it to the documentation. Any idea on where it could fit?
Ref.:
- https://www.php-imap.com/
- https://github.com/Webklex/php-imap-documentation
Best regards,
Do you have a reliable way to detect when you are connected to Gmail? Use the host is not reliable because people can use a cname DNS entry.
Edit: Humm, I guess the delete method can check if the "[Gmail]/Trash" or "[Gmail]/Bin" exists, if so, move the message there.
Yeah I was wondering about this as well..
Perhaps $client->getConnection()->getCapabilities() has some interesting information?
Best regards,
Also taking a look at Gmail IMAP Extensions
Maybe the delete method can look something like this:
public function delete($expunge = true, $trash_path = "[Gmail]/Trash", $force_move = false) {
$status = $this->setFlag("Deleted");
if($force_move || in_array("X-GM-EXT-1", $this->client->getConnection()->getCapabilities())) {
$status = $this->move($trash_path);
}
if($expunge) $this->client->expunge();
$event = $this->getEvent("message", "deleted");
$event::dispatch($this);
return $status;
}
What do you think?
Hi @EthraZa ,
many thanks for your suggestion. As of v3.0.0-alpha you can now use the Message::delete() method as suggested by you.
There is however one difference. If you don't provide a $trash_path, the default common folder path from options.common_folders.trash gets used instead.
Best regards,