don't print attachments that are text/plain
This commit is contained in:
parent
e816fe2f60
commit
036990f946
|
@ -119,7 +119,7 @@ func fetch(c *connection, ids []int) stateFunc {
|
|||
c.write(cmd(fmt.Sprintf("uid fetch %d body[]", id)))
|
||||
if c.err == nil {
|
||||
s := c.read("uid fetch of " + strconv.Itoa(id))
|
||||
s = strings.TrimRight(s, ")\n")
|
||||
s = strings.TrimRight(s, ")\r\n")
|
||||
if c.err == nil {
|
||||
mail, err := parseMail(s)
|
||||
if err == nil {
|
||||
|
|
|
@ -93,7 +93,8 @@ func getPlainParts(mail *mail.Message) ([]string, []error) {
|
|||
parts := make([]string, 0)
|
||||
errs := make([]error, 0)
|
||||
mediaType, params, err := mime.ParseMediaType(mail.Header.Get("Content-Type"))
|
||||
if err == nil && strings.HasPrefix(mediaType, "multipart/") {
|
||||
_, hasBoundary := params["boundary"]
|
||||
if err == nil && strings.HasPrefix(mediaType, "multipart/") && hasBoundary {
|
||||
mr := multipart.NewReader(mail.Body, params["boundary"])
|
||||
for {
|
||||
p, err := mr.NextPart()
|
||||
|
@ -104,16 +105,23 @@ func getPlainParts(mail *mail.Message) ([]string, []error) {
|
|||
errs = append(errs, err)
|
||||
}
|
||||
if contentType := p.Header.Get("Content-Type"); strings.HasPrefix(contentType, "text/plain") {
|
||||
body, _ := ioutil.ReadAll(p)
|
||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
||||
if encoding != "" {
|
||||
body, err = normalize(body, encoding)
|
||||
if err != nil {
|
||||
body = nil
|
||||
errs = append(errs, err)
|
||||
if contentDisposition := p.Header.Get("Content-Disposition"); !strings.HasPrefix(contentDisposition, "attachment") {
|
||||
body, _ := ioutil.ReadAll(p)
|
||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
||||
if encoding != "" {
|
||||
body, err = normalize(body, encoding)
|
||||
if err != nil {
|
||||
body = nil
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
parts = append(parts, string(body))
|
||||
} else {
|
||||
_, params, errDispo := mime.ParseMediaType(contentDisposition)
|
||||
if filename, ok := params["filename"]; errDispo == nil && ok {
|
||||
parts = append(parts, "Plain attachment: "+filename)
|
||||
}
|
||||
}
|
||||
parts = append(parts, string(body))
|
||||
} else {
|
||||
parts = append(parts, "Non-plain part: "+contentType)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user