Interesting question. The premise reminds me of a game, but I can't quite remember the name of it. I think the premise is you find a phone and have to find out about the owner by sending messages to their contacts, looking at their photos, etc.
Some of the requirements have parallels to a dialog system, which Laura has been writing a tutorial series about.
I would probably create a JSON file with the data for your emails in, something like this:
{
"first_email": {
"subject": "Welcome",
"from": "auto@ai.io"
"body": "Hello",
"responses": [
{
"body": "Hello to you too!,
"trigger": "second_email"
}
]
},
"second_email": { ... }
}
Each email is keyed with a textual ID, so you can easily look it up. Then the email object itself contains the various bits of text you would want to display on the screen but it also contains an array of response objects. The responses basically being a body of text and an ID of another email which the AI sends back to you. Allowing for a branching dialogue tree.
In terms of saving what emails are visible you just need an array of the email IDs which are visible. To "delete" an email remove it from the array. When an email is "received" add it to the list. You should be able to quite easily save that array to localstorage to persist the game state between sessions.