diff --git a/mailq/parser.go b/mailq/parser.go index e030acd..89ac5a8 100644 --- a/mailq/parser.go +++ b/mailq/parser.go @@ -10,7 +10,7 @@ import ( "time" ) -func ParseMailQ(dataSource io.Reader) (MailQ, error) { +func ParseFromReader(dataSource io.Reader) (MailQ, error) { const dateFormat = "2006 Mon Jan _2 15:04:05" var messageIdStart = regexp.MustCompile("^[0-9A-Za-z]+[*!]? ") scanner := bufio.NewScanner(dataSource) diff --git a/mailq/string.go b/mailq/string.go index 67c390a..56e8eba 100644 --- a/mailq/string.go +++ b/mailq/string.go @@ -30,13 +30,13 @@ 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, reasonStr, m.Size, m.Sender, strings.Join(m.Recipients, ", ")) } -func (queue MailQ) PrintMachineReadable(writer io.Writer) { +func (queue MailQ) WriteMachineReadable(writer io.Writer) { for _, entry := range queue.Entries { fmt.Fprintf(writer, "%s\n", entry.MachineReadableString()) } } -func (queue MailQ) PrintHumanReadable(writer io.Writer) { +func (queue MailQ) WriteHumanReadable(writer io.Writer) { if len(queue.Entries) == 0 { fmt.Fprintf(writer, "Mail queue is empty\n") } else { @@ -54,7 +54,7 @@ func (queue MailQ) PrintHumanReadable(writer io.Writer) { } } -func (queue MailQ) PrintJSON(writer io.Writer) { +func (queue MailQ) WriteJSON(writer io.Writer) { bytes, err := json.Marshal(queue) if err != nil { fmt.Fprintf(writer, "Error encoding queue to JSON: %s\n", err.Error()) diff --git a/main.go b/main.go index 463c380..edc756d 100644 --- a/main.go +++ b/main.go @@ -66,11 +66,11 @@ func showQueue() { func printQueue(queue mailq.MailQ, writer io.Writer) { if settings["outputFormat"] == "human" { - queue.PrintHumanReadable(writer) + queue.WriteHumanReadable(writer) } else if settings["outputFormat"] == "machine" { - queue.PrintMachineReadable(writer) + queue.WriteMachineReadable(writer) } else if settings["outputFormat"] == "json" { - queue.PrintJSON(writer) + queue.WriteJSON(writer) } } @@ -105,7 +105,7 @@ func readFromCmd(cmd *exec.Cmd) (mailq.MailQ, error) { if err := cmd.Start(); err != nil { return mailq.MailQ{}, err } - result, resultError := mailq.ParseMailQ(stdout) + result, resultError := mailq.ParseFromReader(stdout) if err := cmd.Wait(); err != nil { return mailq.MailQ{}, err }