I found that if i connect to the Trash and then use an asterix to get the last message it works as intended.
public function undo($email) {
// check if message id exists and is numeric
if ($email !== '' && is_numeric($email)) {
// set hostname to trash
$hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/Trash';
$this->inbox = imap_open($hostname,$this->username,$this->password) or die('Cannot connect to Gmail: ' . imap_last_error());
// return true if the message was moved
if (imap_mail_move($this->inbox, '*', 'Inbox')) {
return true;
} else {
return false;
}
} else {
return false;
}
imap_close($this->inbox,CL_EXPUNGE);
}