The concept may seem simple, but there are some issues that need explanation.
How is the UID identified initially? If it's a constant value, then why bother with the original message, when you could just look for the UID in the inbox? If not, how is it determined?
What do you want to do with the messages that contain the UID?
Because of the processes involved, this could take a long time to run if you have a lot of stored messages.