|
@@ -213,7 +213,11 @@ func (c CatMsgCmd) Func(args []string) error {
|
|
|
Log.Debug("enter info display-message")
|
|
|
}
|
|
|
var idList []uint32
|
|
|
+ var withHeaders, withBody, markRead bool
|
|
|
flagset := flag.NewFlagSet(args[0], flag.ExitOnError)
|
|
|
+ flagset.BoolVar(&withHeaders, "headers", false, "toggle headers display")
|
|
|
+ flagset.BoolVar(&withBody, "no-body", false, "hide body")
|
|
|
+ flagset.BoolVar(&markRead, "seen", false, "mark as seen if not yet seen")
|
|
|
flagset.Usage = func() { c.Help(os.Stdout, flagset) }
|
|
|
flagset.Parse(args[1:])
|
|
|
|
|
@@ -236,13 +240,24 @@ func (c CatMsgCmd) Func(args []string) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- messages, err := imaputils.FetchMessages(Session.Config, mailbox, idList, Session.Info.Opts.Debug)
|
|
|
+ opts := &imaputils.FetchOpts{
|
|
|
+ Mailbox: mailbox,
|
|
|
+ IdList: idList,
|
|
|
+ WithHeaders: withHeaders,
|
|
|
+ WithBody: !withBody,
|
|
|
+ Peek: !markRead,
|
|
|
+ }
|
|
|
+ if Session.Info.Opts.Debug {
|
|
|
+ Log.Debug(opts)
|
|
|
+ }
|
|
|
+
|
|
|
+ messages, err := imaputils.FetchMessages(Session.Config, opts, Session.Info.Opts.Debug)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
for _, m := range messages {
|
|
|
- err = printMessage(m)
|
|
|
+ err = printMessage(m, opts)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -271,24 +286,37 @@ func parseToUint32(s string) (uint32, error) {
|
|
|
return uint32(out), nil
|
|
|
}
|
|
|
|
|
|
-func printMessage(m *imap.Message) error {
|
|
|
+func printMessage(m *imap.Message, opts *imaputils.FetchOpts) error {
|
|
|
var out string
|
|
|
|
|
|
- out += fmt.Sprintln(formatAddresses(m.Envelope.From, "From"))
|
|
|
- out += fmt.Sprintln(formatAddresses(m.Envelope.Sender, "Sender"))
|
|
|
- out += fmt.Sprintln(formatAddresses(m.Envelope.Cc, "Cc"))
|
|
|
- out += fmt.Sprintln(formatAddresses(m.Envelope.Bcc, "Bcc"))
|
|
|
- out += fmt.Sprintln(formatAddresses(m.Envelope.ReplyTo, "ReplyTo"))
|
|
|
- out += fmt.Sprintf("InReplyTo: %s\n", m.Envelope.InReplyTo)
|
|
|
- out += fmt.Sprintf("Date: %v\n", m.Envelope.Date)
|
|
|
- out += fmt.Sprintf("Subject: %s\n", m.Envelope.Subject)
|
|
|
-
|
|
|
- bodyReader := m.GetBody(&imap.BodySectionName{BodyPartName: imap.BodyPartName{}, Peek: true})
|
|
|
- body, err := ioutil.ReadAll(bodyReader)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ if opts.WithHeaders {
|
|
|
+ out += fmt.Sprintln(formatAddresses(m.Envelope.From, "From"))
|
|
|
+ out += fmt.Sprintln(formatAddresses(m.Envelope.Sender, "Sender"))
|
|
|
+ out += fmt.Sprintln(formatAddresses(m.Envelope.Cc, "Cc"))
|
|
|
+ out += fmt.Sprintln(formatAddresses(m.Envelope.Bcc, "Bcc"))
|
|
|
+ out += fmt.Sprintln(formatAddresses(m.Envelope.ReplyTo, "ReplyTo"))
|
|
|
+ out += fmt.Sprintf("InReplyTo: %s\n", m.Envelope.InReplyTo)
|
|
|
+ out += fmt.Sprintf("Date: %v\n", m.Envelope.Date)
|
|
|
+ out += fmt.Sprintf("Subject: %s\n", m.Envelope.Subject)
|
|
|
+
|
|
|
+ headersSec := &imap.BodySectionName{Peek: opts.Peek, BodyPartName: imap.BodyPartName{Specifier: imap.HeaderSpecifier}}
|
|
|
+ headersReader := m.GetBody(headersSec)
|
|
|
+ headers, err := ioutil.ReadAll(headersReader)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ out += fmt.Sprintln(string(headers))
|
|
|
+ }
|
|
|
+
|
|
|
+ if opts.WithBody {
|
|
|
+ bodySec := &imap.BodySectionName{Peek: opts.Peek, BodyPartName: imap.BodyPartName{Specifier: imap.TextSpecifier}}
|
|
|
+ bodyReader := m.GetBody(bodySec)
|
|
|
+ body, err := ioutil.ReadAll(bodyReader)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ out += fmt.Sprintln(string(body))
|
|
|
}
|
|
|
- out += fmt.Sprintln(string(body))
|
|
|
|
|
|
fmt.Println(out)
|
|
|
return nil
|