55 lines
815 B
Go
55 lines
815 B
Go
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Message struct {
|
|
ID string
|
|
RepTo string
|
|
EchoArea string
|
|
Date time.Time
|
|
From string
|
|
Addr string
|
|
MsgTo string
|
|
Subject string
|
|
Message string
|
|
}
|
|
|
|
func (m *Message) Bundle() string {
|
|
tags := "ii/ok"
|
|
if m.RepTo != "" {
|
|
tags = "ii/ok/repto/" + m.RepTo
|
|
}
|
|
lines := []string{
|
|
tags,
|
|
m.EchoArea,
|
|
strconv.Itoa(int(m.Date.Unix())),
|
|
m.From,
|
|
m.Addr,
|
|
string(m.MsgTo),
|
|
m.Subject,
|
|
"",
|
|
m.Message,
|
|
}
|
|
|
|
return strings.Join(lines, "\n")
|
|
}
|
|
|
|
func (m *Message) PointMessage() string {
|
|
lines := []string{
|
|
m.EchoArea,
|
|
string(m.MsgTo),
|
|
m.Subject,
|
|
"",
|
|
}
|
|
if m.RepTo != "" {
|
|
lines = append(lines, fmt.Sprintf("@repto:%s", m.RepTo))
|
|
}
|
|
lines = append(lines, m.Message)
|
|
|
|
return strings.Join(lines, "\n")
|
|
}
|