From 6e2cb00008cbf09e556b00f87603797fcaa47e09 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 16 Apr 2018 05:37:14 -0700 Subject: Depenancy upgrades and movign to dep. (#8630) --- vendor/gopkg.in/gomail.v2/auth_test.go | 156 -------- vendor/gopkg.in/gomail.v2/example_test.go | 215 ---------- vendor/gopkg.in/gomail.v2/message_test.go | 630 ------------------------------ vendor/gopkg.in/gomail.v2/send_test.go | 80 ---- vendor/gopkg.in/gomail.v2/smtp_test.go | 254 ------------ 5 files changed, 1335 deletions(-) delete mode 100644 vendor/gopkg.in/gomail.v2/auth_test.go delete mode 100644 vendor/gopkg.in/gomail.v2/example_test.go delete mode 100644 vendor/gopkg.in/gomail.v2/message_test.go delete mode 100644 vendor/gopkg.in/gomail.v2/send_test.go delete mode 100644 vendor/gopkg.in/gomail.v2/smtp_test.go (limited to 'vendor/gopkg.in/gomail.v2') diff --git a/vendor/gopkg.in/gomail.v2/auth_test.go b/vendor/gopkg.in/gomail.v2/auth_test.go deleted file mode 100644 index 20b477214..000000000 --- a/vendor/gopkg.in/gomail.v2/auth_test.go +++ /dev/null @@ -1,156 +0,0 @@ -package gomail - -import ( - "net/smtp" - "testing" -) - -const ( - testUser = "user" - testPwd = "pwd" - testHost = "smtp.example.com" -) - -var testAuth = &plainAuth{ - username: testUser, - password: testPwd, - host: testHost, -} - -type plainAuthTest struct { - auths []string - challenges []string - tls bool - wantProto string - wantData []string - wantError bool -} - -func TestNoAdvertisement(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{}, - challenges: []string{"Username:", "Password:"}, - tls: false, - wantProto: "PLAIN", - wantError: true, - }) -} - -func TestNoAdvertisementTLS(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{}, - challenges: []string{"Username:", "Password:"}, - tls: true, - wantProto: "PLAIN", - wantData: []string{"\x00" + testUser + "\x00" + testPwd}, - }) -} - -func TestPlain(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{"PLAIN"}, - challenges: []string{"Username:", "Password:"}, - tls: false, - wantProto: "PLAIN", - wantData: []string{"\x00" + testUser + "\x00" + testPwd}, - }) -} - -func TestPlainTLS(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{"PLAIN"}, - challenges: []string{"Username:", "Password:"}, - tls: true, - wantProto: "PLAIN", - wantData: []string{"\x00" + testUser + "\x00" + testPwd}, - }) -} - -func TestPlainAndLogin(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{"PLAIN", "LOGIN"}, - challenges: []string{"Username:", "Password:"}, - tls: false, - wantProto: "PLAIN", - wantData: []string{"\x00" + testUser + "\x00" + testPwd}, - }) -} - -func TestPlainAndLoginTLS(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{"PLAIN", "LOGIN"}, - challenges: []string{"Username:", "Password:"}, - tls: true, - wantProto: "PLAIN", - wantData: []string{"\x00" + testUser + "\x00" + testPwd}, - }) -} - -func TestLogin(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{"LOGIN"}, - challenges: []string{"Username:", "Password:"}, - tls: false, - wantProto: "LOGIN", - wantData: []string{"", testUser, testPwd}, - }) -} - -func TestLoginTLS(t *testing.T) { - testPlainAuth(t, &plainAuthTest{ - auths: []string{"LOGIN"}, - challenges: []string{"Username:", "Password:"}, - tls: true, - wantProto: "LOGIN", - wantData: []string{"", testUser, testPwd}, - }) -} - -func testPlainAuth(t *testing.T, test *plainAuthTest) { - auth := &plainAuth{ - username: testUser, - password: testPwd, - host: testHost, - } - server := &smtp.ServerInfo{ - Name: testHost, - TLS: test.tls, - Auth: test.auths, - } - proto, toServer, err := auth.Start(server) - if err != nil && !test.wantError { - t.Fatalf("plainAuth.Start(): %v", err) - } - if err != nil && test.wantError { - return - } - if proto != test.wantProto { - t.Errorf("invalid protocol, got %q, want %q", proto, test.wantProto) - } - - i := 0 - got := string(toServer) - if got != test.wantData[i] { - t.Errorf("Invalid response, got %q, want %q", got, test.wantData[i]) - } - - if proto == "PLAIN" { - return - } - - for _, challenge := range test.challenges { - i++ - if i >= len(test.wantData) { - t.Fatalf("unexpected challenge: %q", challenge) - } - - toServer, err = auth.Next([]byte(challenge), true) - if err != nil { - t.Fatalf("plainAuth.Auth(): %v", err) - } - got = string(toServer) - if got != test.wantData[i] { - t.Errorf("Invalid response, got %q, want %q", got, test.wantData[i]) - } - } -} diff --git a/vendor/gopkg.in/gomail.v2/example_test.go b/vendor/gopkg.in/gomail.v2/example_test.go deleted file mode 100644 index 8d9c6c293..000000000 --- a/vendor/gopkg.in/gomail.v2/example_test.go +++ /dev/null @@ -1,215 +0,0 @@ -package gomail_test - -import ( - "fmt" - "html/template" - "io" - "log" - "time" - - "gopkg.in/gomail.v2" -) - -func Example() { - m := gomail.NewMessage() - m.SetHeader("From", "alex@example.com") - m.SetHeader("To", "bob@example.com", "cora@example.com") - m.SetAddressHeader("Cc", "dan@example.com", "Dan") - m.SetHeader("Subject", "Hello!") - m.SetBody("text/html", "Hello Bob and Cora!") - m.Attach("/home/Alex/lolcat.jpg") - - d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456") - - // Send the email to Bob, Cora and Dan. - if err := d.DialAndSend(m); err != nil { - panic(err) - } -} - -// A daemon that listens to a channel and sends all incoming messages. -func Example_daemon() { - ch := make(chan *gomail.Message) - - go func() { - d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456") - - var s gomail.SendCloser - var err error - open := false - for { - select { - case m, ok := <-ch: - if !ok { - return - } - if !open { - if s, err = d.Dial(); err != nil { - panic(err) - } - open = true - } - if err := gomail.Send(s, m); err != nil { - log.Print(err) - } - // Close the connection to the SMTP server if no email was sent in - // the last 30 seconds. - case <-time.After(30 * time.Second): - if open { - if err := s.Close(); err != nil { - panic(err) - } - open = false - } - } - } - }() - - // Use the channel in your program to send emails. - - // Close the channel to stop the mail daemon. - close(ch) -} - -// Efficiently send a customized newsletter to a list of recipients. -func Example_newsletter() { - // The list of recipients. - var list []struct { - Name string - Address string - } - - d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456") - s, err := d.Dial() - if err != nil { - panic(err) - } - - m := gomail.NewMessage() - for _, r := range list { - m.SetHeader("From", "no-reply@example.com") - m.SetAddressHeader("To", r.Address, r.Name) - m.SetHeader("Subject", "Newsletter #1") - m.SetBody("text/html", fmt.Sprintf("Hello %s!", r.Name)) - - if err := gomail.Send(s, m); err != nil { - log.Printf("Could not send email to %q: %v", r.Address, err) - } - m.Reset() - } -} - -// Send an email using a local SMTP server. -func Example_noAuth() { - m := gomail.NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetHeader("Subject", "Hello!") - m.SetBody("text/plain", "Hello!") - - d := gomail.Dialer{Host: "localhost", Port: 587} - if err := d.DialAndSend(m); err != nil { - panic(err) - } -} - -// Send an email using an API or postfix. -func Example_noSMTP() { - m := gomail.NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetHeader("Subject", "Hello!") - m.SetBody("text/plain", "Hello!") - - s := gomail.SendFunc(func(from string, to []string, msg io.WriterTo) error { - // Implements you email-sending function, for example by calling - // an API, or running postfix, etc. - fmt.Println("From:", from) - fmt.Println("To:", to) - return nil - }) - - if err := gomail.Send(s, m); err != nil { - panic(err) - } - // Output: - // From: from@example.com - // To: [to@example.com] -} - -var m *gomail.Message - -func ExampleSetCopyFunc() { - m.Attach("foo.txt", gomail.SetCopyFunc(func(w io.Writer) error { - _, err := w.Write([]byte("Content of foo.txt")) - return err - })) -} - -func ExampleSetHeader() { - h := map[string][]string{"Content-ID": {""}} - m.Attach("foo.jpg", gomail.SetHeader(h)) -} - -func ExampleMessage_AddAlternative() { - m.SetBody("text/plain", "Hello!") - m.AddAlternative("text/html", "

Hello!

") -} - -func ExampleMessage_AddAlternativeWriter() { - t := template.Must(template.New("example").Parse("Hello {{.}}!")) - m.AddAlternativeWriter("text/plain", func(w io.Writer) error { - return t.Execute(w, "Bob") - }) -} - -func ExampleMessage_Attach() { - m.Attach("/tmp/image.jpg") -} - -func ExampleMessage_Embed() { - m.Embed("/tmp/image.jpg") - m.SetBody("text/html", `My image`) -} - -func ExampleMessage_FormatAddress() { - m.SetHeader("To", m.FormatAddress("bob@example.com", "Bob"), m.FormatAddress("cora@example.com", "Cora")) -} - -func ExampleMessage_FormatDate() { - m.SetHeaders(map[string][]string{ - "X-Date": {m.FormatDate(time.Now())}, - }) -} - -func ExampleMessage_SetAddressHeader() { - m.SetAddressHeader("To", "bob@example.com", "Bob") -} - -func ExampleMessage_SetBody() { - m.SetBody("text/plain", "Hello!") -} - -func ExampleMessage_SetDateHeader() { - m.SetDateHeader("X-Date", time.Now()) -} - -func ExampleMessage_SetHeader() { - m.SetHeader("Subject", "Hello!") -} - -func ExampleMessage_SetHeaders() { - m.SetHeaders(map[string][]string{ - "From": {m.FormatAddress("alex@example.com", "Alex")}, - "To": {"bob@example.com", "cora@example.com"}, - "Subject": {"Hello"}, - }) -} - -func ExampleSetCharset() { - m = gomail.NewMessage(gomail.SetCharset("ISO-8859-1")) -} - -func ExampleSetEncoding() { - m = gomail.NewMessage(gomail.SetEncoding(gomail.Base64)) -} diff --git a/vendor/gopkg.in/gomail.v2/message_test.go b/vendor/gopkg.in/gomail.v2/message_test.go deleted file mode 100644 index fdd9ff9bd..000000000 --- a/vendor/gopkg.in/gomail.v2/message_test.go +++ /dev/null @@ -1,630 +0,0 @@ -package gomail - -import ( - "bytes" - "encoding/base64" - "io" - "io/ioutil" - "path/filepath" - "regexp" - "strconv" - "strings" - "testing" - "time" -) - -func init() { - now = func() time.Time { - return time.Date(2014, 06, 25, 17, 46, 0, 0, time.UTC) - } -} - -type message struct { - from string - to []string - content string -} - -func TestMessage(t *testing.T) { - m := NewMessage() - m.SetAddressHeader("From", "from@example.com", "Señor From") - m.SetHeader("To", m.FormatAddress("to@example.com", "Señor To"), "tobis@example.com") - m.SetAddressHeader("Cc", "cc@example.com", "A, B") - m.SetAddressHeader("X-To", "ccbis@example.com", "à, b") - m.SetDateHeader("X-Date", now()) - m.SetHeader("X-Date-2", m.FormatDate(now())) - m.SetHeader("Subject", "¡Hola, señor!") - m.SetHeaders(map[string][]string{ - "X-Headers": {"Test", "Café"}, - }) - m.SetBody("text/plain", "¡Hola, señor!") - - want := &message{ - from: "from@example.com", - to: []string{ - "to@example.com", - "tobis@example.com", - "cc@example.com", - }, - content: "From: =?UTF-8?q?Se=C3=B1or_From?= \r\n" + - "To: =?UTF-8?q?Se=C3=B1or_To?= , tobis@example.com\r\n" + - "Cc: \"A, B\" \r\n" + - "X-To: =?UTF-8?b?w6AsIGI=?= \r\n" + - "X-Date: Wed, 25 Jun 2014 17:46:00 +0000\r\n" + - "X-Date-2: Wed, 25 Jun 2014 17:46:00 +0000\r\n" + - "X-Headers: Test, =?UTF-8?q?Caf=C3=A9?=\r\n" + - "Subject: =?UTF-8?q?=C2=A1Hola,_se=C3=B1or!?=\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "=C2=A1Hola, se=C3=B1or!", - } - - testMessage(t, m, 0, want) -} - -func TestBodyWriter(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.AddAlternativeWriter("text/plain", func(w io.Writer) error { - _, err := w.Write([]byte("Test message")) - return err - }) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "Test message", - } - - testMessage(t, m, 0, want) -} - -func TestCustomMessage(t *testing.T) { - m := NewMessage(SetCharset("ISO-8859-1"), SetEncoding(Base64)) - m.SetHeaders(map[string][]string{ - "From": {"from@example.com"}, - "To": {"to@example.com"}, - "Subject": {"Café"}, - }) - m.SetBody("text/html", "¡Hola, señor!") - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Subject: =?ISO-8859-1?b?Q2Fmw6k=?=\r\n" + - "Content-Type: text/html; charset=ISO-8859-1\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - "wqFIb2xhLCBzZcOxb3Ih", - } - - testMessage(t, m, 0, want) -} - -func TestUnencodedMessage(t *testing.T) { - m := NewMessage(SetEncoding(Unencoded)) - m.SetHeaders(map[string][]string{ - "From": {"from@example.com"}, - "To": {"to@example.com"}, - "Subject": {"Café"}, - }) - m.SetBody("text/html", "¡Hola, señor!") - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Subject: =?UTF-8?q?Caf=C3=A9?=\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: 8bit\r\n" + - "\r\n" + - "¡Hola, señor!", - } - - testMessage(t, m, 0, want) -} - -func TestRecipients(t *testing.T) { - m := NewMessage() - m.SetHeaders(map[string][]string{ - "From": {"from@example.com"}, - "To": {"to@example.com"}, - "Cc": {"cc@example.com"}, - "Bcc": {"bcc1@example.com", "bcc2@example.com"}, - "Subject": {"Hello!"}, - }) - m.SetBody("text/plain", "Test message") - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com", "cc@example.com", "bcc1@example.com", "bcc2@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Cc: cc@example.com\r\n" + - "Subject: Hello!\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "Test message", - } - - testMessage(t, m, 0, want) -} - -func TestAlternative(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", "¡Hola, señor!") - m.AddAlternative("text/html", "¡Hola, señor!") - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: multipart/alternative; boundary=_BOUNDARY_1_\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "=C2=A1Hola, se=C3=B1or!\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "=C2=A1Hola, se=C3=B1or!\r\n" + - "--_BOUNDARY_1_--\r\n", - } - - testMessage(t, m, 1, want) -} - -func TestAttachmentOnly(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.Attach(mockCopyFile("/tmp/test.pdf")) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: application/pdf; name=\"test.pdf\"\r\n" + - "Content-Disposition: attachment; filename=\"test.pdf\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.pdf")), - } - - testMessage(t, m, 0, want) -} - -func TestAttachment(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", "Test") - m.Attach(mockCopyFile("/tmp/test.pdf")) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: multipart/mixed; boundary=_BOUNDARY_1_\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "Test\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: application/pdf; name=\"test.pdf\"\r\n" + - "Content-Disposition: attachment; filename=\"test.pdf\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.pdf")) + "\r\n" + - "--_BOUNDARY_1_--\r\n", - } - - testMessage(t, m, 1, want) -} - -func TestAttachmentsOnly(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.Attach(mockCopyFile("/tmp/test.pdf")) - m.Attach(mockCopyFile("/tmp/test.zip")) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: multipart/mixed; boundary=_BOUNDARY_1_\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: application/pdf; name=\"test.pdf\"\r\n" + - "Content-Disposition: attachment; filename=\"test.pdf\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.pdf")) + "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: application/zip; name=\"test.zip\"\r\n" + - "Content-Disposition: attachment; filename=\"test.zip\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.zip")) + "\r\n" + - "--_BOUNDARY_1_--\r\n", - } - - testMessage(t, m, 1, want) -} - -func TestAttachments(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", "Test") - m.Attach(mockCopyFile("/tmp/test.pdf")) - m.Attach(mockCopyFile("/tmp/test.zip")) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: multipart/mixed; boundary=_BOUNDARY_1_\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "Test\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: application/pdf; name=\"test.pdf\"\r\n" + - "Content-Disposition: attachment; filename=\"test.pdf\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.pdf")) + "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: application/zip; name=\"test.zip\"\r\n" + - "Content-Disposition: attachment; filename=\"test.zip\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.zip")) + "\r\n" + - "--_BOUNDARY_1_--\r\n", - } - - testMessage(t, m, 1, want) -} - -func TestEmbedded(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.Embed(mockCopyFileWithHeader(m, "image1.jpg", map[string][]string{"Content-ID": {""}})) - m.Embed(mockCopyFile("image2.jpg")) - m.SetBody("text/plain", "Test") - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: multipart/related; boundary=_BOUNDARY_1_\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "Test\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: image/jpeg; name=\"image1.jpg\"\r\n" + - "Content-Disposition: inline; filename=\"image1.jpg\"\r\n" + - "Content-ID: \r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of image1.jpg")) + "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: image/jpeg; name=\"image2.jpg\"\r\n" + - "Content-Disposition: inline; filename=\"image2.jpg\"\r\n" + - "Content-ID: \r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of image2.jpg")) + "\r\n" + - "--_BOUNDARY_1_--\r\n", - } - - testMessage(t, m, 1, want) -} - -func TestFullMessage(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", "¡Hola, señor!") - m.AddAlternative("text/html", "¡Hola, señor!") - m.Attach(mockCopyFile("test.pdf")) - m.Embed(mockCopyFile("image.jpg")) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: multipart/mixed; boundary=_BOUNDARY_1_\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: multipart/related; boundary=_BOUNDARY_2_\r\n" + - "\r\n" + - "--_BOUNDARY_2_\r\n" + - "Content-Type: multipart/alternative; boundary=_BOUNDARY_3_\r\n" + - "\r\n" + - "--_BOUNDARY_3_\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "=C2=A1Hola, se=C3=B1or!\r\n" + - "--_BOUNDARY_3_\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "=C2=A1Hola, se=C3=B1or!\r\n" + - "--_BOUNDARY_3_--\r\n" + - "\r\n" + - "--_BOUNDARY_2_\r\n" + - "Content-Type: image/jpeg; name=\"image.jpg\"\r\n" + - "Content-Disposition: inline; filename=\"image.jpg\"\r\n" + - "Content-ID: \r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of image.jpg")) + "\r\n" + - "--_BOUNDARY_2_--\r\n" + - "\r\n" + - "--_BOUNDARY_1_\r\n" + - "Content-Type: application/pdf; name=\"test.pdf\"\r\n" + - "Content-Disposition: attachment; filename=\"test.pdf\"\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - base64.StdEncoding.EncodeToString([]byte("Content of test.pdf")) + "\r\n" + - "--_BOUNDARY_1_--\r\n", - } - - testMessage(t, m, 3, want) - - want = &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - "Test reset", - } - m.Reset() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", "Test reset") - testMessage(t, m, 0, want) -} - -func TestQpLineLength(t *testing.T) { - m := NewMessage() - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", - strings.Repeat("0", 76)+"\r\n"+ - strings.Repeat("0", 75)+"à\r\n"+ - strings.Repeat("0", 74)+"à\r\n"+ - strings.Repeat("0", 73)+"à\r\n"+ - strings.Repeat("0", 72)+"à\r\n"+ - strings.Repeat("0", 75)+"\r\n"+ - strings.Repeat("0", 76)+"\n") - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - strings.Repeat("0", 75) + "=\r\n0\r\n" + - strings.Repeat("0", 75) + "=\r\n=C3=A0\r\n" + - strings.Repeat("0", 74) + "=\r\n=C3=A0\r\n" + - strings.Repeat("0", 73) + "=\r\n=C3=A0\r\n" + - strings.Repeat("0", 72) + "=C3=\r\n=A0\r\n" + - strings.Repeat("0", 75) + "\r\n" + - strings.Repeat("0", 75) + "=\r\n0\r\n", - } - - testMessage(t, m, 0, want) -} - -func TestBase64LineLength(t *testing.T) { - m := NewMessage(SetCharset("UTF-8"), SetEncoding(Base64)) - m.SetHeader("From", "from@example.com") - m.SetHeader("To", "to@example.com") - m.SetBody("text/plain", strings.Repeat("0", 58)) - - want := &message{ - from: "from@example.com", - to: []string{"to@example.com"}, - content: "From: from@example.com\r\n" + - "To: to@example.com\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - strings.Repeat("MDAw", 19) + "\r\nMA==", - } - - testMessage(t, m, 0, want) -} - -func testMessage(t *testing.T, m *Message, bCount int, want *message) { - err := Send(stubSendMail(t, bCount, want), m) - if err != nil { - t.Error(err) - } -} - -func stubSendMail(t *testing.T, bCount int, want *message) SendFunc { - return func(from string, to []string, m io.WriterTo) error { - if from != want.from { - t.Fatalf("Invalid from, got %q, want %q", from, want.from) - } - - if len(to) != len(want.to) { - t.Fatalf("Invalid recipient count, \ngot %d: %q\nwant %d: %q", - len(to), to, - len(want.to), want.to, - ) - } - for i := range want.to { - if to[i] != want.to[i] { - t.Fatalf("Invalid recipient, got %q, want %q", - to[i], want.to[i], - ) - } - } - - buf := new(bytes.Buffer) - _, err := m.WriteTo(buf) - if err != nil { - t.Error(err) - } - got := buf.String() - wantMsg := string("Mime-Version: 1.0\r\n" + - "Date: Wed, 25 Jun 2014 17:46:00 +0000\r\n" + - want.content) - if bCount > 0 { - boundaries := getBoundaries(t, bCount, got) - for i, b := range boundaries { - wantMsg = strings.Replace(wantMsg, "_BOUNDARY_"+strconv.Itoa(i+1)+"_", b, -1) - } - } - - compareBodies(t, got, wantMsg) - - return nil - } -} - -func compareBodies(t *testing.T, got, want string) { - // We cannot do a simple comparison since the ordering of headers' fields - // is random. - gotLines := strings.Split(got, "\r\n") - wantLines := strings.Split(want, "\r\n") - - // We only test for too many lines, missing lines are tested after - if len(gotLines) > len(wantLines) { - t.Fatalf("Message has too many lines, \ngot %d:\n%s\nwant %d:\n%s", len(gotLines), got, len(wantLines), want) - } - - isInHeader := true - headerStart := 0 - for i, line := range wantLines { - if line == gotLines[i] { - if line == "" { - isInHeader = false - } else if !isInHeader && len(line) > 2 && line[:2] == "--" { - isInHeader = true - headerStart = i + 1 - } - continue - } - - if !isInHeader { - missingLine(t, line, got, want) - } - - isMissing := true - for j := headerStart; j < len(gotLines); j++ { - if gotLines[j] == "" { - break - } - if gotLines[j] == line { - isMissing = false - break - } - } - if isMissing { - missingLine(t, line, got, want) - } - } -} - -func missingLine(t *testing.T, line, got, want string) { - t.Fatalf("Missing line %q\ngot:\n%s\nwant:\n%s", line, got, want) -} - -func getBoundaries(t *testing.T, count int, m string) []string { - if matches := boundaryRegExp.FindAllStringSubmatch(m, count); matches != nil { - boundaries := make([]string, count) - for i, match := range matches { - boundaries[i] = match[1] - } - return boundaries - } - - t.Fatal("Boundary not found in body") - return []string{""} -} - -var boundaryRegExp = regexp.MustCompile("boundary=(\\w+)") - -func mockCopyFile(name string) (string, FileSetting) { - return name, SetCopyFunc(func(w io.Writer) error { - _, err := w.Write([]byte("Content of " + filepath.Base(name))) - return err - }) -} - -func mockCopyFileWithHeader(m *Message, name string, h map[string][]string) (string, FileSetting, FileSetting) { - name, f := mockCopyFile(name) - return name, f, SetHeader(h) -} - -func BenchmarkFull(b *testing.B) { - discardFunc := SendFunc(func(from string, to []string, m io.WriterTo) error { - _, err := m.WriteTo(ioutil.Discard) - return err - }) - - m := NewMessage() - b.ResetTimer() - for n := 0; n < b.N; n++ { - m.SetAddressHeader("From", "from@example.com", "Señor From") - m.SetHeaders(map[string][]string{ - "To": {"to@example.com"}, - "Cc": {"cc@example.com"}, - "Bcc": {"bcc1@example.com", "bcc2@example.com"}, - "Subject": {"¡Hola, señor!"}, - }) - m.SetBody("text/plain", "¡Hola, señor!") - m.AddAlternative("text/html", "

¡Hola, señor!

") - m.Attach(mockCopyFile("benchmark.txt")) - m.Embed(mockCopyFile("benchmark.jpg")) - - if err := Send(discardFunc, m); err != nil { - panic(err) - } - m.Reset() - } -} diff --git a/vendor/gopkg.in/gomail.v2/send_test.go b/vendor/gopkg.in/gomail.v2/send_test.go deleted file mode 100644 index ba59cd3dc..000000000 --- a/vendor/gopkg.in/gomail.v2/send_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package gomail - -import ( - "bytes" - "io" - "reflect" - "testing" -) - -const ( - testTo1 = "to1@example.com" - testTo2 = "to2@example.com" - testFrom = "from@example.com" - testBody = "Test message" - testMsg = "To: " + testTo1 + ", " + testTo2 + "\r\n" + - "From: " + testFrom + "\r\n" + - "Mime-Version: 1.0\r\n" + - "Date: Wed, 25 Jun 2014 17:46:00 +0000\r\n" + - "Content-Type: text/plain; charset=UTF-8\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + - "\r\n" + - testBody -) - -type mockSender SendFunc - -func (s mockSender) Send(from string, to []string, msg io.WriterTo) error { - return s(from, to, msg) -} - -type mockSendCloser struct { - mockSender - close func() error -} - -func (s *mockSendCloser) Close() error { - return s.close() -} - -func TestSend(t *testing.T) { - s := &mockSendCloser{ - mockSender: stubSend(t, testFrom, []string{testTo1, testTo2}, testMsg), - close: func() error { - t.Error("Close() should not be called in Send()") - return nil - }, - } - if err := Send(s, getTestMessage()); err != nil { - t.Errorf("Send(): %v", err) - } -} - -func getTestMessage() *Message { - m := NewMessage() - m.SetHeader("From", testFrom) - m.SetHeader("To", testTo1, testTo2) - m.SetBody("text/plain", testBody) - - return m -} - -func stubSend(t *testing.T, wantFrom string, wantTo []string, wantBody string) mockSender { - return func(from string, to []string, msg io.WriterTo) error { - if from != wantFrom { - t.Errorf("invalid from, got %q, want %q", from, wantFrom) - } - if !reflect.DeepEqual(to, wantTo) { - t.Errorf("invalid to, got %v, want %v", to, wantTo) - } - - buf := new(bytes.Buffer) - _, err := msg.WriteTo(buf) - if err != nil { - t.Fatal(err) - } - compareBodies(t, buf.String(), wantBody) - - return nil - } -} diff --git a/vendor/gopkg.in/gomail.v2/smtp_test.go b/vendor/gopkg.in/gomail.v2/smtp_test.go deleted file mode 100644 index c8503489b..000000000 --- a/vendor/gopkg.in/gomail.v2/smtp_test.go +++ /dev/null @@ -1,254 +0,0 @@ -package gomail - -import ( - "bytes" - "crypto/tls" - "io" - "net" - "net/smtp" - "reflect" - "testing" -) - -const ( - testPort = 587 - testSSLPort = 465 -) - -var ( - testTLSConn = &tls.Conn{} - testConfig = &tls.Config{InsecureSkipVerify: true} -) - -func TestDialer(t *testing.T) { - d := NewPlainDialer(testHost, testPort, "user", "pwd") - testSendMail(t, d, []string{ - "Extension STARTTLS", - "StartTLS", - "Extension AUTH", - "Auth", - "Mail " + testFrom, - "Rcpt " + testTo1, - "Rcpt " + testTo2, - "Data", - "Write message", - "Close writer", - "Quit", - "Close", - }) -} - -func TestDialerSSL(t *testing.T) { - d := NewPlainDialer(testHost, testSSLPort, "user", "pwd") - testSendMail(t, d, []string{ - "Extension AUTH", - "Auth", - "Mail " + testFrom, - "Rcpt " + testTo1, - "Rcpt " + testTo2, - "Data", - "Write message", - "Close writer", - "Quit", - "Close", - }) -} - -func TestDialerConfig(t *testing.T) { - d := NewPlainDialer(testHost, testPort, "user", "pwd") - d.TLSConfig = testConfig - testSendMail(t, d, []string{ - "Extension STARTTLS", - "StartTLS", - "Extension AUTH", - "Auth", - "Mail " + testFrom, - "Rcpt " + testTo1, - "Rcpt " + testTo2, - "Data", - "Write message", - "Close writer", - "Quit", - "Close", - }) -} - -func TestDialerSSLConfig(t *testing.T) { - d := NewPlainDialer(testHost, testSSLPort, "user", "pwd") - d.TLSConfig = testConfig - testSendMail(t, d, []string{ - "Extension AUTH", - "Auth", - "Mail " + testFrom, - "Rcpt " + testTo1, - "Rcpt " + testTo2, - "Data", - "Write message", - "Close writer", - "Quit", - "Close", - }) -} - -func TestDialerNoAuth(t *testing.T) { - d := &Dialer{ - Host: testHost, - Port: testPort, - } - testSendMail(t, d, []string{ - "Extension STARTTLS", - "StartTLS", - "Mail " + testFrom, - "Rcpt " + testTo1, - "Rcpt " + testTo2, - "Data", - "Write message", - "Close writer", - "Quit", - "Close", - }) -} - -type mockClient struct { - t *testing.T - i int - want []string - addr string - auth smtp.Auth - config *tls.Config -} - -func (c *mockClient) Extension(ext string) (bool, string) { - c.do("Extension " + ext) - return true, "" -} - -func (c *mockClient) StartTLS(config *tls.Config) error { - assertConfig(c.t, config, c.config) - c.do("StartTLS") - return nil -} - -func (c *mockClient) Auth(a smtp.Auth) error { - assertAuth(c.t, a, c.auth) - c.do("Auth") - return nil -} - -func (c *mockClient) Mail(from string) error { - c.do("Mail " + from) - return nil -} - -func (c *mockClient) Rcpt(to string) error { - c.do("Rcpt " + to) - return nil -} - -func (c *mockClient) Data() (io.WriteCloser, error) { - c.do("Data") - return &mockWriter{c: c, want: testMsg}, nil -} - -func (c *mockClient) Quit() error { - c.do("Quit") - return nil -} - -func (c *mockClient) Close() error { - c.do("Close") - return nil -} - -func (c *mockClient) do(cmd string) { - if c.i >= len(c.want) { - c.t.Fatalf("Invalid command %q", cmd) - } - - if cmd != c.want[c.i] { - c.t.Fatalf("Invalid command, got %q, want %q", cmd, c.want[c.i]) - } - c.i++ -} - -type mockWriter struct { - want string - c *mockClient - buf bytes.Buffer -} - -func (w *mockWriter) Write(p []byte) (int, error) { - if w.buf.Len() == 0 { - w.c.do("Write message") - } - w.buf.Write(p) - return len(p), nil -} - -func (w *mockWriter) Close() error { - compareBodies(w.c.t, w.buf.String(), w.want) - w.c.do("Close writer") - return nil -} - -func testSendMail(t *testing.T, d *Dialer, want []string) { - testClient := &mockClient{ - t: t, - want: want, - addr: addr(d.Host, d.Port), - auth: testAuth, - config: d.TLSConfig, - } - - smtpDial = func(addr string) (smtpClient, error) { - assertAddr(t, addr, testClient.addr) - return testClient, nil - } - - tlsDial = func(network, addr string, config *tls.Config) (*tls.Conn, error) { - if network != "tcp" { - t.Errorf("Invalid network, got %q, want tcp", network) - } - assertAddr(t, addr, testClient.addr) - assertConfig(t, config, testClient.config) - return testTLSConn, nil - } - - newClient = func(conn net.Conn, host string) (smtpClient, error) { - if conn != testTLSConn { - t.Error("Invalid TLS connection used") - } - if host != testHost { - t.Errorf("Invalid host, got %q, want %q", host, testHost) - } - return testClient, nil - } - - if err := d.DialAndSend(getTestMessage()); err != nil { - t.Error(err) - } -} - -func assertAuth(t *testing.T, got, want smtp.Auth) { - if !reflect.DeepEqual(got, want) { - t.Errorf("Invalid auth, got %#v, want %#v", got, want) - } -} - -func assertAddr(t *testing.T, got, want string) { - if got != want { - t.Errorf("Invalid addr, got %q, want %q", got, want) - } -} - -func assertConfig(t *testing.T, got, want *tls.Config) { - if want == nil { - want = &tls.Config{ServerName: testHost} - } - if got.ServerName != want.ServerName { - t.Errorf("Invalid field ServerName in config, got %q, want %q", got.ServerName, want.ServerName) - } - if got.InsecureSkipVerify != want.InsecureSkipVerify { - t.Errorf("Invalid field InsecureSkipVerify in config, got %v, want %v", got.InsecureSkipVerify, want.InsecureSkipVerify) - } -} -- cgit v1.2.3-1-g7c22