mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
SMTP server is running with new config engine
Web still not working
This commit is contained in:
31
datastore.go
31
datastore.go
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/robfig/revel"
|
||||
"io/ioutil"
|
||||
"net/mail"
|
||||
"os"
|
||||
@@ -38,16 +37,20 @@ type DataStore struct {
|
||||
mailPath string
|
||||
}
|
||||
|
||||
// NewDataStore creates a new DataStore object. It uses the Revel Config object to
|
||||
// NewDataStore creates a new DataStore object. It uses the inbucket.Config object to
|
||||
// construct it's path.
|
||||
func NewDataStore() *DataStore {
|
||||
path, found := rev.Config.String("datastore.path")
|
||||
if found {
|
||||
mailPath := filepath.Join(path, "mail")
|
||||
return &DataStore{path: path, mailPath: mailPath}
|
||||
path, err := Config.String("datastore", "path")
|
||||
if err != nil {
|
||||
Error("Error getting datastore path: %v", err)
|
||||
return nil
|
||||
}
|
||||
rev.ERROR.Printf("No value configured for datastore.path")
|
||||
return nil
|
||||
if path == "" {
|
||||
Error("No value configured for datastore path")
|
||||
return nil
|
||||
}
|
||||
mailPath := filepath.Join(path, "mail")
|
||||
return &DataStore{path: path, mailPath: mailPath}
|
||||
}
|
||||
|
||||
// Retrieves the Mailbox object for a specified email address, if the mailbox
|
||||
@@ -57,7 +60,7 @@ func (ds *DataStore) MailboxFor(emailAddress string) (*Mailbox, error) {
|
||||
dir := HashMailboxName(name)
|
||||
path := filepath.Join(ds.mailPath, dir)
|
||||
if err := os.MkdirAll(path, 0770); err != nil {
|
||||
rev.ERROR.Printf("Failed to create directory %v, %v", path, err)
|
||||
Error("Failed to create directory %v, %v", path, err)
|
||||
return nil, err
|
||||
}
|
||||
return &Mailbox{store: ds, name: name, dirName: dir, path: path}, nil
|
||||
@@ -83,7 +86,7 @@ func (mb *Mailbox) GetMessages() ([]*Message, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rev.TRACE.Printf("Scanning %v files for %v", len(files), mb)
|
||||
Trace("Scanning %v files for %v", len(files), mb)
|
||||
|
||||
messages := make([]*Message, 0, len(files))
|
||||
for _, f := range files {
|
||||
@@ -100,7 +103,7 @@ func (mb *Mailbox) GetMessages() ([]*Message, error) {
|
||||
}
|
||||
file.Close()
|
||||
msg.mailbox = mb
|
||||
rev.TRACE.Printf("Found: %v", msg)
|
||||
Trace("Found: %v", msg)
|
||||
messages = append(messages, msg)
|
||||
}
|
||||
}
|
||||
@@ -121,7 +124,7 @@ func (mb *Mailbox) GetMessage(id string) (*Message, error) {
|
||||
}
|
||||
file.Close()
|
||||
msg.mailbox = mb
|
||||
rev.TRACE.Printf("Found: %v", msg)
|
||||
Trace("Found: %v", msg)
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
@@ -157,8 +160,8 @@ func (m *Message) gobPath() string {
|
||||
}
|
||||
|
||||
func (m *Message) rawPath() string {
|
||||
rev.TRACE.Println(m.mailbox.path)
|
||||
rev.TRACE.Println(m.Id)
|
||||
Trace(m.mailbox.path)
|
||||
Trace(m.Id)
|
||||
return filepath.Join(m.mailbox.path, m.Id+".raw")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user