Skip to content

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. Reading the concepts document would also prove to be useful.

This tutorial starts from where the previous chapter left off.

Hello world examples are fabulous but they get boring pretty fast. As part of this chapter, we will avoid flooding our correspondents' inboxes with vacation notifications. To do that, we need to reply only to certain messages as well as not reply too often to messages that fit our criteria.

We will 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 was processed. It emits the mutation event named MessageSeen.

The seen table is used to remember which messages have been responded to.