1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-27 06:27:04 +00:00

Started impl DELE

This commit is contained in:
James Hillyerd
2013-09-11 23:12:22 -07:00
parent 983b4f745a
commit 01f6ad514b
3 changed files with 256 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ package smtpd
import (
"github.com/jhillyerd/go.enmime"
"io"
"net/mail"
"time"
)
@@ -23,6 +24,7 @@ type Message interface {
From() string
Date() time.Time
Subject() string
RawReader() (reader io.ReadCloser, err error)
ReadHeader() (msg *mail.Message, err error)
ReadBody() (msg *mail.Message, body *enmime.MIMEBody, err error)
ReadRaw() (raw *string, err error)

View File

@@ -8,6 +8,7 @@ import (
"github.com/jhillyerd/go.enmime"
"github.com/jhillyerd/inbucket/config"
"github.com/jhillyerd/inbucket/log"
"io"
"io/ioutil"
"net/mail"
"os"
@@ -266,15 +267,23 @@ func (m *FileMessage) ReadBody() (msg *mail.Message, body *enmime.MIMEBody, err
return msg, mime, err
}
// ReadRaw opens the .raw portion of a Message and returns it as a string
func (m *FileMessage) ReadRaw() (raw *string, err error) {
// RawReader opens the .raw portion of a Message as an io.ReadCloser
func (m *FileMessage) RawReader() (reader io.ReadCloser, err error) {
file, err := os.Open(m.rawPath())
defer file.Close()
if err != nil {
return nil, err
}
reader := bufio.NewReader(file)
bodyBytes, err := ioutil.ReadAll(reader)
return file, nil
}
// ReadRaw opens the .raw portion of a Message and returns it as a string
func (m *FileMessage) ReadRaw() (raw *string, err error) {
reader, err := m.RawReader()
defer reader.Close()
if err != nil {
return nil, err
}
bodyBytes, err := ioutil.ReadAll(bufio.NewReader(reader))
if err != nil {
return nil, err
}