If you need to use the uid instead of msgno use
imap_clearflag_full($stream, implode(',', $flags), '\\DELETED', ST_UID);(PHP 4, PHP 5, PHP 7, PHP 8)
imap_undelete — 削除マークがついているメッセージのマークをはずす
指定したメッセージについて、 imap_delete() または imap_mail_move() で設定された削除フラグをはずします。
imapIMAP\Connection クラスのインスタンス。
message_nums
       IMAP4 形式のシーケンスフォーマット
       ("n", "n:m", またはそれらをカンマで区切ったもの)
       で表現された、ひとつ以上のメッセージを表す文字列。
      
flags
   常に true を返します。
  
| バージョン | 説明 | 
|---|---|
| 8.1.0 | 引数 imapは、IMAP\Connection
  クラスのインスタンスを期待するようになりました。
  これより前のバージョンでは、有効なimapresource が期待されていました。 | 
If you need to use the uid instead of msgno use
imap_clearflag_full($stream, implode(',', $flags), '\\DELETED', ST_UID);The imap_delete function allows the option to use a UID for the message number but the imap_undelete function does not.