If UIDs from an earlier session fail to persist in this session, the UIDVALIDITY value MUST be greater than the one used in the earlier session.
Thus, the client should remembervalue of each folder and compare the saved value and new value on next session. If new value is larger, it means the mail server is not capable of keeping UIDs unchanged between sessions. In this case, the client cannot make any assumptions that UIDs obtained during the previous session correspond to UIDs of the same messages on this session.
Nowadays, IMAP4 servers which fail to persist UIDs between session are very uncommon, and the UIDVALIDITY value is usually the same accross sessions. Nevertheless, the client should still check the UIDVALIDITY value due to the following reason: if, between two sessions, the folder was deleted and the folder with the same name was recreated, and this new folder was filled with some mails, their UIDs may coincide with UIDs of the messages in the original folder (which is now deleted). To avoid confusion, the application should check if UIDVALIDITY had changed.