throw away interfaces; mailbox will be a nmh mailbox client only
7 files changed, 36 insertions(+), 105 deletions(-)

M cmd/mb/main.go
M command.go
M edit.go
M list.go
R mailbox.go => 
R mh.go => 
M sequence.go
M cmd/mb/main.go +9 -7
@@ 18,7 18,7 @@ type Command struct {
 	Name string
 	// Run runs the command.
 	// The args are the arguments after the command name.
-	Run func(mbox mb.Mailbox, args []string) error
+	Run func(mbox *mh.Mailbox, args []string) error
 
 	// UsageLine is the one-line usage message.
 	UsageLine string

          
@@ 53,7 53,8 @@ func main() {
 		die("missing command")
 	}
 	var err error
-	mbox := mb.NewMHMailbox(mh.NewMailbox())
+	// todo: put account into mailbox ehre
+	mbox := mh.NewMailbox()
 	switch cmd := os.Args[1]; cmd {
 	case "parse": // for testing only
 		if len(os.Args) < 3 {

          
@@ 202,14 203,15 @@ func main() {
 		if folder, match, err = parseRegexpCmd(os.Args[2:]); err != nil {
 			break
 		}
-		var msgs []mb.Message
+		var msgs []*mh.Message
 		if msgs, err = mbox.ReadFolder(folder); err != nil {
 			break
 		}
 		var picked []string
 		for i := range msgs {
-			if match.Matches(msgs[i]) {
-				picked = append(picked, strconv.FormatInt(msgs[i].Id(), 10))
+			// todo: no *
+			if match.Matches(*msgs[i]) {
+				picked = append(picked, strconv.FormatInt(msgs[i].Id, 10))
 			}
 		}
 		if len(picked) > 0 {

          
@@ 378,7 380,7 @@ func main() {
 	}
 }
 
-func openMsg(mbox mb.Mailbox, msg string) (io.ReadCloser, error) {
+func openMsg(mbox *mh.Mailbox, msg string) (io.ReadCloser, error) {
 	f, b := path.Split(msg)
 	if len(f) == 0 {
 		f = mbox.Default()

          
@@ 386,7 388,7 @@ func openMsg(mbox mb.Mailbox, msg string
 	return mbox.Open(f, b)
 }
 
-func parseSequence(mbox mb.Mailbox, value string) (string, *mb.Sequence, error) {
+func parseSequence(mbox *mh.Mailbox, value string) (string, *mb.Sequence, error) {
 	folder, seq := path.Split(value)
 	if len(folder) == 0 {
 		folder = mbox.Default()

          
M command.go +7 -5
@@ 13,11 13,13 @@ import (
 	"strconv"
 	"strings"
 
+	"bitbucket.org/telesto/mailbox/mh"
+
 	"golang.org/x/text/transform"
 )
 
 // its not an error if no match is found.
-func walk(mbox Mailbox, folder string, seq *Sequence, proc func(string) error) error {
+func walk(mbox *mh.Mailbox, folder string, seq *Sequence, proc func(string) error) error {
 	// todo: let only sorted msgs out here
 	msgs, err := mbox.ReadFolder(folder)
 	if err != nil {

          
@@ 27,8 29,8 @@ func walk(mbox Mailbox, folder string, s
 	// in the correct time order
 	// todo: see above, need sorted list
 	for j := range msgs {
-		if seq.Matches(msgs[j].Id()) {
-			if err = proc(strconv.FormatInt(msgs[j].Id(), 10)); err != nil {
+		if seq.Matches(msgs[j].Id) {
+			if err = proc(strconv.FormatInt(msgs[j].Id, 10)); err != nil {
 				return err
 			}
 		}

          
@@ 36,14 38,14 @@ func walk(mbox Mailbox, folder string, s
 	return nil
 }
 
-func Move(mbox Mailbox, srcFolder string, msgs *Sequence, dst string) error {
+func Move(mbox *mh.Mailbox, srcFolder string, msgs *Sequence, dst string) error {
 	proc := func(id string) error {
 		return mbox.Move(srcFolder, dst, id)
 	}
 	return walk(mbox, srcFolder, msgs, proc)
 }
 
-func Remove(mbox Mailbox, folder string, msgs *Sequence) error {
+func Remove(mbox *mh.Mailbox, folder string, msgs *Sequence) error {
 	proc := func(id string) error {
 		return mbox.Remove(folder, id)
 	}

          
M edit.go +8 -6
@@ 22,6 22,8 @@ import (
 	"time"
 
 	"golang.org/x/text/transform"
+
+	"bitbucket.org/telesto/mailbox/mh"
 )
 
 type quoteMessage struct {

          
@@ 54,28 56,28 @@ func (qm *quoteMessage) Transform(dst, s
 type formatMsg func(io.Writer, string, *mail.Message) error
 
 // todo:
-func Edit(mb Mailbox, msg *mail.Message) (string, error) {
+func Edit(mb *mh.Mailbox, msg *mail.Message) (string, error) {
 	return edit(mb, msg, fmtEditMsg)
 }
 
-func Create(mb Mailbox) (string, error) {
+func Create(mb *mh.Mailbox) (string, error) {
 	// todo: this is ugly
 	return edit(mb, &mail.Message{Header: make(map[string][]string)}, fmtNewMessage)
 }
 
-func Forward(mb Mailbox, msg *mail.Message) (string, error) {
+func Forward(mb *mh.Mailbox, msg *mail.Message) (string, error) {
 	return edit(mb, msg, forwardMsg)
 }
 
 // todo: wouldnt make a reader or a filename make more sense here?
 // we have to rethink the whola api
-func Reply(mb Mailbox, msg *mail.Message) (string, error) {
+func Reply(mb *mh.Mailbox, msg *mail.Message) (string, error) {
 	return edit(mb, msg, fmtReply)
 }
 
 // todo: in case of an error we need to inform the callee about the
 // tmp file that is still existing
-func edit(mbox Mailbox, msg *mail.Message, format formatMsg) (string, error) {
+func edit(mbox *mh.Mailbox, msg *mail.Message, format formatMsg) (string, error) {
 	tmp, err := ioutil.TempFile("", "mailbox")
 	if err != nil {
 		return "", err

          
@@ 334,7 336,7 @@ func boundary(hdr textproto.MIMEHeader) 
 	return "", nil
 }
 
-func Attach(mbox Mailbox, dst io.Writer, src io.Reader, filename string) error {
+func Attach(mbox *mh.Mailbox, dst io.Writer, src io.Reader, filename string) error {
 
 	att, err := os.Open(filename)
 	if err != nil {

          
M list.go +6 -4
@@ 7,13 7,15 @@ import (
 	"net/mail"
 	"strings"
 	"time"
+
+	"bitbucket.org/telesto/mailbox/mh"
 )
 
 var sixMonthPast = time.Now().Add(-6 * 30 * 24 * time.Hour)
 var oneDayAhead = time.Now().Add(24 * time.Hour)
 
 // todo: delim as param
-func List(mbox Mailbox, dst io.Writer, folder string, pick *Sequence) error {
+func List(mbox *mh.Mailbox, dst io.Writer, folder string, pick *Sequence) error {
 	msgs, err := mbox.ReadFolder(folder)
 	if err != nil && msgs == nil {
 		// don't leave if we have msgs, show as much as we can

          
@@ 27,10 29,10 @@ func List(mbox Mailbox, dst io.Writer, f
 		fType = defaultFolderType
 	}
 	for _, msg := range msgs {
-		if !pick.Matches(msg.Id()) {
+		if !pick.Matches(msg.Id) {
 			continue
 		}
-		header := msg.Header()
+		header := msg.Header
 		// ignore error, we can't do anything about it
 		date, _ := header.Date()
 		format := "Jan _2 15:04"

          
@@ 39,7 41,7 @@ func List(mbox Mailbox, dst io.Writer, f
 		}
 		// this was a deleted flag, we dont need that for now
 		flags := " "
-		fmt.Fprintf(out, formats[fType], msg.Id(), flags,
+		fmt.Fprintf(out, formats[fType], msg.Id, flags,
 			date.Format(format),
 			decodeAddressList(header.Get("From")),
 			decodeAddressList(header.Get("To")),

          
R mailbox.go =>  +0 -34
@@ 1,34 0,0 @@ 
-package mailbox
-
-import (
-	"io"
-	"net/mail"
-)
-
-type Message interface {
-	Id() int64
-	Header() mail.Header
-	Body() io.Reader
-}
-
-type Mailbox interface {
-	Pack(folder string) error
-	// todo: sorted list returned
-	ReadFolder(folder string) ([]Message, error)
-
-	// shouldnt this return the name of the new file?
-	Move(src, dst, msgid string) error
-	Remove(folder, msgid string) error
-
-	Open(folder, msg string) (io.ReadCloser, error)
-	Append(folder string, data io.Reader) (msgid string, err error)
-
-	MkFolder(folder string) error
-	FolderType(string) (int, bool)
-	// todo: these methods are rather for the client, put them somewhere else?
-	Default() string
-	Draft() string
-	Sent() string
-	From() string
-	// Trash() string	todo?
-}

          
R mh.go =>  +0 -45
@@ 1,45 0,0 @@ 
-package mailbox
-
-import (
-	"io"
-	"net/mail"
-
-	"bitbucket.org/telesto/mailbox/mh"
-)
-
-type mhMailbox struct {
-	*mh.Mailbox
-}
-
-func NewMHMailbox(mbox *mh.Mailbox) Mailbox {
-	return mhMailbox{mbox}
-
-}
-
-type mhMessage struct {
-	*mh.Message
-}
-
-func (mbox mhMessage) Id() int64 {
-	return mbox.Message.Id
-}
-
-func (mbox mhMessage) Header() mail.Header {
-	return mbox.Message.Header
-}
-
-func (mbox mhMessage) Body() io.Reader {
-	return mbox.Message.Body
-}
-
-func (mb mhMailbox) ReadFolder(folder string) ([]Message, error) {
-	mhMsgs, err := mb.Mailbox.ReadFolder(folder)
-	if mhMsgs == nil {
-		return nil, err
-	}
-	msgs := make([]Message, len(mhMsgs))
-	for i := range msgs {
-		msgs[i] = mhMessage{mhMsgs[i]}
-	}
-	return msgs, nil
-}

          
M sequence.go +6 -4
@@ 7,6 7,8 @@ import (
 	"strconv"
 	"strings"
 	"unicode/utf8"
+
+	"bitbucket.org/telesto/mailbox/mh"
 )
 
 type Sequence struct {

          
@@ 68,17 70,17 @@ type Regexp struct {
 	r           *rgxp.Regexp
 }
 
-func (s Regexp) Matches(m Message) bool {
+func (s Regexp) Matches(m mh.Message) bool {
 	dec := newDecoder()
-	for key := range m.Header() {
-		if s.matchHeader(key) && s.r.MatchString(dec.safeDecodeHeader(m.Header().Get(key))) {
+	for key := range m.Header {
+		if s.matchHeader(key) && s.r.MatchString(dec.safeDecodeHeader(m.Header.Get(key))) {
 			return true
 		}
 	}
 	if !s.matchBody {
 		return false
 	}
-	return s.r.MatchReader(&readRune{reader: m.Body()})
+	return s.r.MatchReader(&readRune{reader: m.Body})
 }
 
 func ParseRegexp(s string) (*Regexp, error) {