Skip to content

Commit

Permalink
update names
Browse files Browse the repository at this point in the history
  • Loading branch information
matst80 committed Oct 22, 2024
1 parent 1a0bf58 commit be6707d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions content-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"strings"
)

func (s *session) textContent(r rcpt, c *ClassificationResult) string {
func (s *session) textContent(r Recipient, c *ClassificationResult) string {
var sb strings.Builder
if s.HasValidDkim {
sb.WriteString(fmt.Sprintf("Subject: %s\nFrom: %s\n", s.Email.Headers.Subject, s.From))

if r.extraInfo {
sb.WriteString(fmt.Sprintf("To: %s\nIp: %s\n", r.address, s.Client))
if r.WantsDebugInfo {
sb.WriteString(fmt.Sprintf("To: %s\nIp: %s\n", r.Address, s.Client))
}

if c != nil {
Expand All @@ -26,7 +26,7 @@ func (s *session) textContent(r rcpt, c *ClassificationResult) string {
}
}

userData, ok := s.StoredData[r.chatId]
userData, ok := s.StoredData[r.ChatId]
if ok && s.backend.HashGenerator != nil {

sb.WriteString(fmt.Sprintf("\n\nRead original: %s", userData.Html.WebUrl(s.backend.Config.BaseUrl, s.backend.HashGenerator)))
Expand Down
16 changes: 8 additions & 8 deletions content-generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func TestContentGenerator(t *testing.T) {
},
},
}
content := s.textContent(rcpt{
extraInfo: true,
address: "test@example.com",
chatId: 1,
content := s.textContent(Recipient{
WantsDebugInfo: true,
Address: "test@example.com",
ChatId: 1,
}, &ClassificationResult{
SpamRating: 0.5,
Summary: "AI SUMMARY",
Expand Down Expand Up @@ -104,10 +104,10 @@ func TestContentGeneratorNoDkim(t *testing.T) {
},
},
}
content := s.textContent(rcpt{
extraInfo: true,
address: "test@example.com",
chatId: 1,
content := s.textContent(Recipient{
WantsDebugInfo: true,
Address: "test@example.com",
ChatId: 1,
}, &ClassificationResult{
SpamRating: 0.5,
Summary: "AI SUMMARY",
Expand Down
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ type session struct {
Client net.Addr
HasValidDkim bool
From string
To []rcpt
To []Recipient
Email letters.Email
MailId string
StoredData map[int64]StorageResult
}

type rcpt struct {
extraInfo bool
address string
chatId int64
type Recipient struct {
WantsDebugInfo bool
Address string
ChatId int64
}

func (bkd *backend) NewSession(c *smtp.Conn) (smtp.Session, error) {
Expand All @@ -52,7 +52,7 @@ func (bkd *backend) NewSession(c *smtp.Conn) (smtp.Session, error) {
return &session{
Client: client,
backend: bkd,
To: []rcpt{},
To: []Recipient{},
Email: letters.Email{},
StoredData: map[int64]StorageResult{},
}, nil
Expand All @@ -79,7 +79,7 @@ func (s *session) Mail(from string, opts *smtp.MailOptions) error {
func (s *session) Rcpt(to string, opts *smtp.RcptOptions) error {
for _, u := range s.backend.Config.Users {
if to == u.Email {
s.To = append(s.To, rcpt{chatId: u.ChatId, extraInfo: u.DebugInfo, address: to})
s.To = append(s.To, Recipient{ChatId: u.ChatId, WantsDebugInfo: u.DebugInfo, Address: to})
return nil
}
}
Expand Down Expand Up @@ -118,11 +118,11 @@ func (s *session) Data(r io.Reader) error {

s.MailId = mailId
for _, userId := range s.To {
data, err := saveMail(mailId, userId.chatId, s.Email)
data, err := saveMail(mailId, userId.ChatId, s.Email)
if err != nil {
log.Printf("Error saving email: %v", err)
} else {
s.StoredData[userId.chatId] = data
s.StoredData[userId.ChatId] = data
}
}

Expand Down Expand Up @@ -157,14 +157,14 @@ func (s *session) handleMail() error {

content := s.textContent(r, result)

msg := botapi.NewMessage(r.chatId, content)
msg := botapi.NewMessage(r.ChatId, content)

if r.extraInfo {
if r.WantsDebugInfo {
msg.ReplyMarkup = botapi.NewReplyKeyboard(botapi.NewKeyboardButtonRow(botapi.NewKeyboardButton("/block " + ip)))
}

_, err = s.backend.Bot.Send(msg)
log.Printf("Sent email to %d", r.chatId)
log.Printf("Sent email to %d (%s)", r.ChatId, r.Address)

}
} else {
Expand Down

0 comments on commit be6707d

Please sign in to comment.