mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-01-04 02:17:03 +00:00
Package reorganization part 2
End goal is to simplify build
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/jhillyerd/inbucket"
|
||||
"github.com/jhillyerd/inbucket/config"
|
||||
"github.com/jhillyerd/inbucket/log"
|
||||
"io/ioutil"
|
||||
"net/mail"
|
||||
@@ -42,7 +42,7 @@ type DataStore struct {
|
||||
// NewDataStore creates a new DataStore object. It uses the inbucket.Config object to
|
||||
// construct it's path.
|
||||
func NewDataStore() *DataStore {
|
||||
path, err := inbucket.Config.String("datastore", "path")
|
||||
path, err := config.Config.String("datastore", "path")
|
||||
if err != nil {
|
||||
log.Error("Error getting datastore path: %v", err)
|
||||
return nil
|
||||
|
||||
@@ -2,7 +2,7 @@ package smtpd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jhillyerd/inbucket"
|
||||
"github.com/jhillyerd/inbucket/config"
|
||||
"github.com/jhillyerd/inbucket/log"
|
||||
"net"
|
||||
)
|
||||
@@ -20,13 +20,13 @@ type Server struct {
|
||||
func New() *Server {
|
||||
ds := NewDataStore()
|
||||
// TODO Make more of these configurable
|
||||
return &Server{domain: inbucket.GetSmtpConfig().Domain, maxRecips: 100, maxIdleSeconds: 300,
|
||||
return &Server{domain: config.GetSmtpConfig().Domain, maxRecips: 100, maxIdleSeconds: 300,
|
||||
dataStore: ds, maxMessageBytes: 2048000}
|
||||
}
|
||||
|
||||
// Main listener loop
|
||||
func (s *Server) Start() {
|
||||
cfg := inbucket.GetSmtpConfig()
|
||||
cfg := config.GetSmtpConfig()
|
||||
addr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%v:%v",
|
||||
cfg.Ip4address, cfg.Ip4port))
|
||||
if err != nil {
|
||||
|
||||
@@ -3,7 +3,6 @@ package smtpd
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"html"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
@@ -26,11 +25,3 @@ func HashMailboxName(mailbox string) string {
|
||||
io.WriteString(h, mailbox)
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// TextToHtml takes plain text, escapes it and tries to pretty it up for
|
||||
// HTML display
|
||||
func TextToHtml(text string) string {
|
||||
text = html.EscapeString(text)
|
||||
replacer := strings.NewReplacer("\r\n", "<br/>\n", "\r", "<br/>\n", "\n", "<br/>\n")
|
||||
return replacer.Replace(text)
|
||||
}
|
||||
|
||||
@@ -6,38 +6,11 @@ import (
|
||||
)
|
||||
|
||||
func TestParseMailboxName(t *testing.T) {
|
||||
in, out := "MailBOX", "mailbox"
|
||||
if x := ParseMailboxName(in); x != out {
|
||||
t.Errorf("ParseMailboxName(%v) = %v, want %v", in, x, out)
|
||||
}
|
||||
|
||||
in, out = "MailBox@Host.Com", "mailbox"
|
||||
if x := ParseMailboxName(in); x != out {
|
||||
t.Errorf("ParseMailboxName(%v) = %v, want %v", in, x, out)
|
||||
}
|
||||
|
||||
in, out = "Mail+extra@Host.Com", "mail"
|
||||
if x := ParseMailboxName(in); x != out {
|
||||
t.Errorf("ParseMailboxName(%v) = %v, want %v", in, x, out)
|
||||
}
|
||||
assert.Equal(t, ParseMailboxName("MailBOX"), "mailbox")
|
||||
assert.Equal(t, ParseMailboxName("MailBox@Host.Com"), "mailbox")
|
||||
assert.Equal(t, ParseMailboxName("Mail+extra@Host.Com"), "mail")
|
||||
}
|
||||
|
||||
func TestHashMailboxName(t *testing.T) {
|
||||
in, out := "mail", "1d6e1cf70ec6f9ab28d3ea4b27a49a77654d370e"
|
||||
if x := HashMailboxName(in); x != out {
|
||||
t.Errorf("HashMailboxName(%v) = %v, want %v", in, x, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextToHtml(t *testing.T) {
|
||||
// Identity
|
||||
assert.Equal(t, TextToHtml("html"), "html")
|
||||
|
||||
// Check it escapes
|
||||
assert.Equal(t, TextToHtml("<html>"), "<html>")
|
||||
|
||||
// Check for linebreaks
|
||||
assert.Equal(t, TextToHtml("line\nbreak"), "line<br/>\nbreak")
|
||||
assert.Equal(t, TextToHtml("line\r\nbreak"), "line<br/>\nbreak")
|
||||
assert.Equal(t, TextToHtml("line\rbreak"), "line<br/>\nbreak")
|
||||
assert.Equal(t, HashMailboxName("mail"), "1d6e1cf70ec6f9ab28d3ea4b27a49a77654d370e")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user