Change how mail queue entries can be displayed

This commit is contained in:
Jan Philipp Timme 2018-12-29 23:28:58 +01:00
parent 1e33d3669c
commit 24afa08970
2 changed files with 13 additions and 5 deletions

View File

@ -36,14 +36,12 @@ func main() {
flag.PrintDefaults() flag.PrintDefaults()
os.Exit(1) os.Exit(1)
} }
if err != nil { if err != nil {
fmt.Printf("Error reading: %s\n", err.Error()) fmt.Printf("Error reading: %s\n", err.Error())
os.Exit(1) os.Exit(1)
} }
for _, entry := range entries {
for _, line := range entries { fmt.Printf("%s\n", entry.String())
fmt.Printf("Read: %s", line)
} }
} }

View File

@ -21,8 +21,18 @@ type QEntry struct {
reason string reason string
} }
const sortableDateFormat = "2006-01-02 15:04:05"
func (m QEntry) ShortString() string {
return fmt.Sprintf("[%s] %s <%s> -> %d recipients (%d bytes)", m.date.Format(sortableDateFormat), m.id, m.sender, len(m.recipients), m.size)
}
func (m QEntry) String() string { func (m QEntry) String() string {
return fmt.Sprintf("ID: %s, Status: %s, Size: %d bytes, Sender: %s, Recipients: %d", m.id, m.status, m.size, m.sender, len(m.recipients)) return fmt.Sprintf("[%s] %s <%s> -> %d recipients (%s, %d bytes)", m.date.Format(sortableDateFormat), m.id, m.sender, len(m.recipients), m.status, m.size)
}
func (m QEntry) DetailedString() string {
return fmt.Sprintf("Id: %s\nDate: %s\nStatus: %s\nReason: %s\nSize: %d\nSender: %s\nRecipients: %s", m.id, m.date.Format(sortableDateFormat), m.status, m.reason, m.size, m.sender, strings.Join(m.recipients, ", "))
} }
func ParseMailQ(dataSource io.Reader) ([]QEntry, error) { func ParseMailQ(dataSource io.Reader) ([]QEntry, error) {