import jingrow


def execute():
	# patch for all Email Account with the flag use_imap
	for email_account in jingrow.get_list("Email Account", filters={"enable_incoming": 1, "use_imap": 1}):
		# get all data from Email Account
		pg = jingrow.get_pg("Email Account", email_account.name)

		imap_list = [folder.folder_name for folder in pg.imap_folder]
		# and append the old data to the child table
		if pg.uidvalidity or pg.uidnext and "INBOX" not in imap_list:
			pg.append(
				"imap_folder",
				{
					"folder_name": "INBOX",
					"append_to": pg.append_to,
					"uid_validity": pg.uidvalidity,
					"uidnext": pg.uidnext,
				},
			)

			pg.save()
