<commit_before>package main

import (
	"io/ioutil"

	"gopkg.in/macaron.v1"

	//"github.com/emersion/neutron/backend/memory"
	"github.com/emersion/neutron/backend/imap"
	"github.com/emersion/neutron/backend/smtp"
	"github.com/emersion/neutron/router/api"
)

func main() {
	publicDir := "public/build"
	indexFile := "app.html"

	//backend := memory.New()
	//backend.(*memory.Backend).Populate()

	imapConfig := &imap.Config{
		Hostname: "mail.gandi.net",
		Suffix: "@emersion.fr",
	}
	smtpConfig := &smtp.Config{
		Hostname: "mail.gandi.net",
		Port: 587,
		Suffix: "@emersion.fr",
	}

	backend := imap.New(imapConfig)
	backend.Set(smtp.New(smtpConfig, backend.(smtp.PasswordsBackend)))

	m := macaron.Classic()
	m.Use(macaron.Renderer())

	// API
	m.Group("/api", func() {
		api.New(m, backend)
	})

	// Serve static files
	m.Use(macaron.Static(publicDir, macaron.StaticOptions{
		IndexFile: indexFile,
		SkipLogging: true,
	}))

	// Fallback to index file
	m.NotFound(func(ctx *macaron.Context) {
		data, err := ioutil.ReadFile(publicDir + "/" + indexFile)
		if err != nil {
			ctx.PlainText(404, []byte("page not found"))
			return
		}

		ctx.Resp.Header().Set("Content-Type", "text/html")
		ctx.Resp.Write(data)
	})

	m.Run()
}
<commit_msg>Simplifies switching between memory & imap backends<commit_after>package main

import (
	"io/ioutil"

	"gopkg.in/macaron.v1"

	"github.com/emersion/neutron/backend"
	"github.com/emersion/neutron/backend/memory"
	"github.com/emersion/neutron/backend/imap"
	"github.com/emersion/neutron/backend/smtp"
	"github.com/emersion/neutron/router/api"
)

func main() {
	publicDir := "public/build"
	indexFile := "app.html"

	// Create backend
	backendName := "memory"
	var bkd backend.Backend
	switch backendName {
	case "memory":
		bkd = memory.New()
		bkd.(*memory.Backend).Populate()
	case "imap":
		imapConfig := &imap.Config{
			Hostname: "mail.gandi.net",
			Suffix: "@emersion.fr",
		}
		smtpConfig := &smtp.Config{
			Hostname: "mail.gandi.net",
			Port: 587,
			Suffix: "@emersion.fr",
		}

		bkd = imap.New(imapConfig)
		bkd.Set(smtp.New(smtpConfig, bkd.(smtp.PasswordsBackend)))
	}

	m := macaron.Classic()
	m.Use(macaron.Renderer())

	// API
	m.Group("/api", func() {
		api.New(m, bkd)
	})

	// Serve static files
	m.Use(macaron.Static(publicDir, macaron.StaticOptions{
		IndexFile: indexFile,
		SkipLogging: true,
	}))

	// Fallback to index file
	m.NotFound(func(ctx *macaron.Context) {
		data, err := ioutil.ReadFile(publicDir + "/" + indexFile)
		if err != nil {
			ctx.PlainText(404, []byte("page not found"))
			return
		}

		ctx.Resp.Header().Set("Content-Type", "text/html")
		ctx.Resp.Write(data)
	})

	m.Run()
}

{'fraction_non_alphanumeric': 0.1771106941838649, 'fraction_numerical': 0.00525328330206379, 'mean_word_length': 3.829710144927536, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '41917', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1061, 'n_words': 169}