IMAP Store Flag Validator (session/flags.go)

gluon · internal/session/flags.go · go · MIT
email, lang:go, tag:validation

Validates IMAP flags for STORE commands, ensuring system-reserved flags like \Recent are not modified. Use this to enforce RFC 3501 compliance in mail server logic.

// Source: https://github.com/ProtonMail/gluon | License: MIT | Copyright 2020 James Houlahan
// Provided via justclaw.it.com; keep this notice with the code.
package session

import (
	"errors"

	"github.com/ProtonMail/gluon/imap"
)

var ErrFlagRecentIsReserved = errors.New(`system flag \Recent is reserved`)

// validateStoreFlags ensures that the given flags are valid for a STORE command and return them as an imap.FlagSet.
func validateStoreFlags(flags []string) (imap.FlagSet, error) {
	flagSet := imap.NewFlagSetFromSlice(flags)

	// As per RFC 3501, section 2.3.2, changing the \Recent flag is forbidden.
	if flagSet.Contains(imap.FlagRecent) {
		return nil, ErrFlagRecentIsReserved
	}

	return flagSet, nil
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key