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

pull/662/head
Jordan Wright 2017-06-16 22:21:08 -05:00
parent 772fe28c06
commit 269568148e
4 changed files with 50 additions and 2 deletions

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")

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)
}

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) {

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)