func fetchFullText(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { mail := fmt.Sprintf("%s\r\n%s\r\n", util.MIMEHeaderToString(m.Header()), m.Body()) mailLen := len(mail) return fmt.Sprintf("BODY[] {%d}\r\n%s", mailLen, mail) }
func fetchHeaderSpecificFields(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { if !peekOnly { fmt.Printf("TODO: Peek not requested, mark all as non-recent\n") } fields := strings.Split(args[1], " ") hdrs := m.Header() requestedHeaders := make(textproto.MIMEHeader) replyFieldList := make([]string, len(fields)) for i, key := range fields { replyFieldList[i] = "\"" + key + "\"" // If the key exists in the headers, copy it over v := hdrs.Get(key) if v != "" { requestedHeaders.Add(key, v) } } hdr := util.MIMEHeaderToString(requestedHeaders) hdrLen := len(hdr) return fmt.Sprintf("BODY[HEADER.FIELDS (%s)] {%d}\r\n%s", strings.Join(replyFieldList, " "), hdrLen, hdr) }
func fetchBody(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { body := fmt.Sprintf("%s\r\n", m.Body()) bodyLen := len(body) return fmt.Sprintf("BODY[TEXT] {%d}\r\n%s", bodyLen, body) }
func fetchHeaders(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { hdr := fmt.Sprintf("%s\r\n", util.MIMEHeaderToString(m.Header())) hdrLen := len(hdr) peekStr := "" if peekOnly { peekStr = ".PEEK" } return fmt.Sprintf("BODY%s[HEADER] {%d}\r\n%s", peekStr, hdrLen, hdr) }
func fetchInternalDate(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { dateStr := m.InternalDate().Format(util.InternalDate) return fmt.Sprintf("INTERNALDATE \"%s\"", dateStr) }
func fetchRfcSize(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { return fmt.Sprintf("RFC822.SIZE %d", m.Size()) }
func fetchFlags(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { flags := append(m.Flags().Strings(), m.Keywords()...) flagList := strings.Join(flags, " ") return fmt.Sprintf("FLAGS (%s)", flagList) }
// Fetch the UID of the mail message func fetchUID(args []string, c *Conn, m mailstore.Message, peekOnly bool) string { return fmt.Sprintf("UID %d", m.UID()) }