Browse Source

Phishing emails are now sent in "First Last <email@domain.com>" format.

pull/662/head
Jordan Wright 4 years ago
parent
commit
269568148e
4 changed files with 50 additions and 2 deletions
  1. +14
    -0
      models/group.go
  2. +19
    -0
      models/models_test.go
  3. +15
    -0
      models/result.go
  4. +2
    -2
      worker/worker.go

+ 14
- 0
models/group.go View File

@ -2,6 +2,7 @@ package models
import (
"errors"
"fmt"
"net/mail"
"time"
@ -50,6 +51,19 @@ type Target struct {
Position string `json:"position"`
}
// Returns the email address to use in the "To" header of the email
func (t *Target) FormatAddress() string {
addr := t.Email
if t.FirstName != "" && t.LastName != "" {
a := &mail.Address{
Name: fmt.Sprintf("%s %s", t.FirstName, t.LastName),
Address: t.Email,
}
addr = a.String()
}
return addr
}
// ErrNoEmailSpecified is thrown when no email is specified for the Target
var ErrEmailNotSpecified = errors.New("No email address specified")

+ 19
- 0
models/models_test.go View File

@ -1,6 +1,7 @@
package models
import (
"net/mail"
"regexp"
"strings"
"testing"
@ -348,3 +349,21 @@ func (s *ModelsSuite) TestGenerateResultId(c *check.C) {
c.Assert(err, check.Equals, nil)
c.Assert(match, check.Equals, true)
}
func (s *ModelsSuite) TestFormatAddress(c *check.C) {
r := Result{
FirstName: "John",
LastName: "Doe",
Email: "johndoe@example.com",
}
expected := &mail.Address{
Name: "John Doe",
Address: "johndoe@example.com",
}
c.Assert(r.FormatAddress(), check.Equals, expected.String())
r = Result{
Email: "johndoe@example.com",
}
c.Assert(r.FormatAddress(), check.Equals, r.Email)
}

+ 15
- 0
models/result.go View File

@ -2,9 +2,11 @@ package models
import (
"crypto/rand"
"fmt"
"log"
"math/big"
"net"
"net/mail"
"github.com/jinzhu/gorm"
"github.com/oschwald/maxminddb-golang"
@ -88,6 +90,19 @@ func (r *Result) GenerateId() error {
return nil
}
// Returns the email address to use in the "To" header of the email
func (r *Result) FormatAddress() string {
addr := r.Email
if r.FirstName != "" && r.LastName != "" {
a := &mail.Address{
Name: fmt.Sprintf("%s %s", r.FirstName, r.LastName),
Address: r.Email,
}
addr = a.String()
}
return addr
}
// GetResult returns the Result object from the database
// given the ResultId
func GetResult(rid string) (Result, error) {

+ 2
- 2
worker/worker.go View File

@ -168,7 +168,7 @@ func processCampaign(c *models.Campaign) {
}
e.SetHeader("Subject", subjBuff.String())
Logger.Println("Creating email using template")
e.SetHeader("To", t.Email)
e.SetHeader("To", t.FormatAddress())
if c.Template.Text != "" {
var textBuff bytes.Buffer
tmpl, err = template.New("text_template").Parse(c.Template.Text)
@ -302,7 +302,7 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
e.SetHeader(parsedHeader.Key.String(), parsedHeader.Value.String())
}
e.SetHeader("From", s.SMTP.FromAddress)
e.SetHeader("To", s.Email)
e.SetHeader("To", s.FormatAddress())
// Parse the templates
var subjBuff bytes.Buffer
tmpl, err := template.New("text_template").Parse(s.Template.Subject)

Loading…
Cancel
Save