php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

delete method not working on Gmail

Open EthraZa opened this issue 4 years ago • 6 comments

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?

EthraZa avatar Feb 12 '21 21:02 EthraZa

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.

EthraZa avatar Feb 17 '21 02:02 EthraZa

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,

Webklex avatar Feb 17 '21 15:02 Webklex

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.

EthraZa avatar Feb 17 '21 16:02 EthraZa

Yeah I was wondering about this as well.. Perhaps $client->getConnection()->getCapabilities() has some interesting information?

Best regards,

Webklex avatar Feb 17 '21 16:02 Webklex

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?

EthraZa avatar Feb 17 '21 17:02 EthraZa

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,

Webklex avatar Nov 04 '21 15:11 Webklex