Preventing Email Flood¶
Warning
This chapter is a big TBD at the moment. Check back often!
Welcome to the second chapter of the Sobamail application tutorial! If you missed the first chapter, we suggest you give it a go. The concepts document is also useful.
This tutorial starts from where the previous chapter left off.
Hello world examples are fabulous, but they get boring pretty fast. In this chapter, we stop flooding our correspondents' inboxes with vacation notifications. To do that, we reply only to certain messages, and we do not reply too often to the messages that fit our criteria.
We draw inspiration from RFC 5230 where appropriate.
First thing to do is to record
State persistence¶
// ...
constructor() {
soba.schema.table({
name : "responded",
insertEvent : Seen,
deleteEvent : DeleteRow,
columns : [
{
name : 'sender',
checks : [
{op : '!=', value : null},
{op : '!=', value : ''},
{op : 'typeof', value : 'text'},
{op : 'regexp', value : soba.type.address.pattern},
]
},
{
name : 'timestamp',
checks : [
{op : '!=', value : null},
{op : 'typeof', value : 'text'},
{op : 'regexp', value : soba.type.uuid.pattern},
]
},
],
});
}
// ...
This snippet creates a table named seen with a single column named message. The message column contains the UUID of the message that the app processed. It emits the mutation event named MessageSeen.
The app uses the seen table to remember the messages it already responded to.