12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package mail
- import (
- "io/ioutil"
- "strings"
- "testing"
- )
- func TestMimeHeaderDecode(t *testing.T) {
- str := MimeHeaderDecode("=?ISO-2022-JP?B?GyRCIVo9dztSOWJAOCVBJWMbKEI=?=")
- if i := strings.Index(str, "【女子高生チャ"); i != 0 {
- t.Error("expecting 【女子高生チャ, got:", str)
- }
- str = MimeHeaderDecode("=?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]>")
- if strings.Index(str, "André Pirard") != 0 {
- t.Error("expecting André Pirard, got:", str)
- }
- }
- func TestNewAddress(t *testing.T) {
- addr, err := NewAddress("<hoop>")
- if err == nil {
- t.Error("there should be an error:", addr)
- }
- addr, err = NewAddress(`Gogh Fir <[email protected]>`)
- if err != nil {
- t.Error("there should be no error:", addr.Host, err)
- }
- }
- func TestEnvelope(t *testing.T) {
- e := NewEnvelope("127.0.0.1", 22)
- e.QueuedId = "abc123"
- e.Helo = "helo.example.com"
- e.MailFrom = Address{User: "test", Host: "example.com"}
- e.TLS = true
- e.RemoteIP = "222.111.233.121"
- to := Address{User: "test", Host: "example.com"}
- e.PushRcpt(to)
- if to.String() != "[email protected]" {
- t.Error("to does not equal [email protected], it was:", to.String())
- }
- e.Data.WriteString("Subject: Test\n\nThis is a test nbnb nbnb hgghgh nnnbnb nbnbnb nbnbn.")
- addHead := "Delivered-To: " + to.String() + "\n"
- addHead += "Received: from " + e.Helo + " (" + e.Helo + " [" + e.RemoteIP + "])\n"
- e.DeliveryHeader = addHead
- r := e.NewReader()
- data, _ := ioutil.ReadAll(r)
- if len(data) != e.Len() {
- t.Error("e.Len() is inccorrect, it shown ", e.Len(), " but we wanted ", len(data))
- }
- e.ParseHeaders()
- if e.Subject != "Test" {
- t.Error("Subject expecting: Test, got:", e.Subject)
- }
- }
|