<commit_before>package readraptor

import (
	"bytes"
	"fmt"
	"os"
	"text/template"
	"time"

	"github.com/sirsean/go-mailgun/mailgun"
)

type NewAccountEmailJob struct {
	AccountId int64
}

func (j *NewAccountEmailJob) Perform() error {
	account, err := FindAccount(j.AccountId)
	if err != nil {
		return err
	}

	token := genKey("confirm" + account.Email)
	account.ConfirmationToken = &token

	message, err := j.CreateMessage(account)
	if err != nil {
		return err
	}

	_, err = dbmap.Exec(
		"update accounts set confirmation_token = $1, confirmation_sent_at = $2 where id = $3",
		token,
		time.Now(),
		j.AccountId,
	)
	if err != nil {
		return err
	}

	if os.Getenv("MAILGUN_API_KEY") != "" {
		mg := mailgun.NewClient(os.Getenv("MAILGUN_API_KEY"), os.Getenv("MAILGUN_DOMAIN"))
		_, err := mg.Send(message)
		if err != nil {
			return err
		}
	} else {
		fmt.Println(message)
	}

	return nil
}

func (j *NewAccountEmailJob) CreateMessage(account *Account) (*mailgun.Message, error) {
	template, err := template.ParseFiles(os.Getenv("RR_ROOT") + "/templates/new_account_email.tmpl")
	if err != nil {
		return nil, err
	}

	var buf bytes.Buffer
	err = template.Execute(&buf, account)
	if err != nil {
		return nil, err
	}

	message := &mailgun.Message{
		FromName:    "Read Raptor",
		FromAddress: "<EMAIL>",
		ToAddress:   account.Email,
		Subject:     "Get started with Read Raptor",
		Body:        buf.String(),
	}

	return message, nil
}<commit_msg>update to email address that works :)<commit_after>package readraptor

import (
	"bytes"
	"fmt"
	"os"
	"text/template"
	"time"

	"github.com/sirsean/go-mailgun/mailgun"
)

type NewAccountEmailJob struct {
	AccountId int64
}

func (j *NewAccountEmailJob) Perform() error {
	account, err := FindAccount(j.AccountId)
	if err != nil {
		return err
	}

	token := genKey("confirm" + account.Email)
	account.ConfirmationToken = &token

	message, err := j.CreateMessage(account)
	if err != nil {
		return err
	}

	_, err = dbmap.Exec(
		"update accounts set confirmation_token = $1, confirmation_sent_at = $2 where id = $3",
		token,
		time.Now(),
		j.AccountId,
	)
	if err != nil {
		return err
	}

	if os.Getenv("MAILGUN_API_KEY") != "" {
		mg := mailgun.NewClient(os.Getenv("MAILGUN_API_KEY"), os.Getenv("MAILGUN_DOMAIN"))
		_, err := mg.Send(message)
		if err != nil {
			return err
		}
	} else {
		fmt.Println(message)
	}

	return nil
}

func (j *NewAccountEmailJob) CreateMessage(account *Account) (*mailgun.Message, error) {
	template, err := template.ParseFiles(os.Getenv("RR_ROOT") + "/templates/new_account_email.tmpl")
	if err != nil {
		return nil, err
	}

	var buf bytes.Buffer
	err = template.Execute(&buf, account)
	if err != nil {
		return nil, err
	}

	message := &mailgun.Message{
		FromName:    "Read Raptor",
		FromAddress: "<EMAIL>",
		ToAddress:   account.Email,
		Subject:     "Get started with Read Raptor",
		Body:        buf.String(),
	}

	return message, nil
}
{'fraction_non_alphanumeric': 0.141785957736878, 'fraction_numerical': 0.0034083162917518746, 'mean_word_length': 3.71107544141252, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2240184', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1081, 'n_words': 256}