<commit_before>package auth

import (
	"fmt"
	"os"
	"strings"

	"github.com/mailhog/MailHog-MTA/config"
	"github.com/mailhog/smtp"
)

// Service represents an authentication service implementation
type Service interface {
	Authenticate(mechanism string, args ...string) (identity Identity, errorReply *smtp.Reply, ok bool)
	Mechanisms() []string
}

// Identity represents an identity
type Identity interface {
	String() string
	IsValidSender(string) bool
}

// Load loads an auth backend
func Load(cfg *config.Config, server *config.Server) Service {
	// FIXME auth backend could be loaded multiple times, should cache this
	if a := server.Backends.Auth; a != nil {
		if len(a.Ref) > 0 {
			if a2, ok := cfg.Backends[a.Ref]; ok {
				a = &a2
			} else {<commit_msg>add fixme re auth mechanisms<commit_after>package auth

import (
	"fmt"
	"os"
	"strings"

	"github.com/mailhog/MailHog-MTA/config"
	"github.com/mailhog/smtp"
)

/*
  FIXME

  Consider whether mechanisms are defined per-backend or not.

  - Are all (available) mechanisms automatically supported by all backends, e.g. EXTERNAL?
  - Or, are the mechanisms supported specific to a particular backend?
  - Parsing is done in mailhog/smtp, does that make mechanism support a policy decision?
*/

// Service represents an authentication service implementation
type Service interface {
	Authenticate(mechanism string, args ...string) (identity Identity, errorReply *smtp.Reply, ok bool)
	Mechanisms() []string
}

// Identity represents an identity
type Identity interface {
	String() string
	IsValidSender(string) bool
}

// Load loads an auth backend
func Load(cfg *config.Config, server *config.Server) Service {
	// FIXME auth backend could be loaded multiple times, should cache this
	if a := server.Backends.Auth; a != nil {
		if len(a.Ref) > 0 {
			if a2, ok := cfg.Backends[a.Ref]; ok {
				a = &a2
			} else {
{'fraction_non_alphanumeric': 0.10666666666666667, 'fraction_numerical': 0.0032, 'mean_word_length': 3.910994764397906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2183483', 'n_tokens_mistral': 611, 'n_tokens_neox': 581, 'n_words': 203}