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)))
|
c.write(cmd(fmt.Sprintf("uid fetch %d body[]", id)))
|
||||||
if c.err == nil {
|
if c.err == nil {
|
||||||
s := c.read("uid fetch of " + strconv.Itoa(id))
|
s := c.read("uid fetch of " + strconv.Itoa(id))
|
||||||
s = strings.TrimRight(s, ")\n")
|
s = strings.TrimRight(s, ")\r\n")
|
||||||
if c.err == nil {
|
if c.err == nil {
|
||||||
mail, err := parseMail(s)
|
mail, err := parseMail(s)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -93,7 +93,8 @@ func getPlainParts(mail *mail.Message) ([]string, []error) {
|
||||||
parts := make([]string, 0)
|
parts := make([]string, 0)
|
||||||
errs := make([]error, 0)
|
errs := make([]error, 0)
|
||||||
mediaType, params, err := mime.ParseMediaType(mail.Header.Get("Content-Type"))
|
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"])
|
mr := multipart.NewReader(mail.Body, params["boundary"])
|
||||||
for {
|
for {
|
||||||
p, err := mr.NextPart()
|
p, err := mr.NextPart()
|
||||||
|
@ -104,16 +105,23 @@ func getPlainParts(mail *mail.Message) ([]string, []error) {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
if contentType := p.Header.Get("Content-Type"); strings.HasPrefix(contentType, "text/plain") {
|
if contentType := p.Header.Get("Content-Type"); strings.HasPrefix(contentType, "text/plain") {
|
||||||
body, _ := ioutil.ReadAll(p)
|
if contentDisposition := p.Header.Get("Content-Disposition"); !strings.HasPrefix(contentDisposition, "attachment") {
|
||||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
body, _ := ioutil.ReadAll(p)
|
||||||
if encoding != "" {
|
encoding := p.Header.Get("Content-Transfer-Encoding")
|
||||||
body, err = normalize(body, encoding)
|
if encoding != "" {
|
||||||
if err != nil {
|
body, err = normalize(body, encoding)
|
||||||
body = nil
|
if err != nil {
|
||||||
errs = append(errs, err)
|
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 {
|
} else {
|
||||||
parts = append(parts, "Non-plain part: "+contentType)
|
parts = append(parts, "Non-plain part: "+contentType)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user