imap: implement fetch body structure

This commit is contained in:
emersion 2018-01-08 10:30:45 +01:00
parent cfc1b44824
commit ac788ac3e1
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 52 additions and 3 deletions

View File

@ -172,8 +172,56 @@ func getFlags(msg *protonmail.Message) []string {
return flags
}
func (mbox *mailbox) getBodyStructure(id string, extended bool) (*imap.BodyStructure, error) {
// TODO
func splitMIMEType(t string) (string, string) {
parts := strings.SplitN(t, "/", 2)
if len(parts) < 2 {
return "text", "plain"
}
return parts[0], parts[1]
}
func (mbox *mailbox) getBodyStructure(msg *protonmail.Message, extended bool) (*imap.BodyStructure, error) {
if msg.NumAttachments > 0 {
var err error
msg, err = mbox.u.c.GetMessage(msg.ID)
if err != nil {
return nil, err
}
}
inlineType, inlineSubType := splitMIMEType(msg.MIMEType)
parts := []*imap.BodyStructure{
&imap.BodyStructure{
MIMEType: inlineType,
MIMESubType: inlineSubType,
Encoding: "quoted-printable",
Size: uint32(len(msg.Body)),
Extended: extended,
Disposition: "inline",
},
}
for _, att := range msg.Attachments {
attType, attSubType := splitMIMEType(att.MIMEType)
parts = append(parts, &imap.BodyStructure{
MIMEType: attType,
MIMESubType: attSubType,
Encoding: "base64",
Size: uint32(att.Size),
Extended: extended,
Disposition: "attachment",
DispositionParams: map[string]string{"filename": att.Name},
})
}
return &imap.BodyStructure{
MIMEType: "multipart",
MIMESubType: "mixed",
// TODO: Params: map[string]string{"boundary": ...},
// TODO: Size
Parts: parts,
Extended: extended,
}, nil
}
func (mbox *mailbox) getBodySection(id string, section *imap.BodySectionName) (imap.Literal, error) {
@ -208,7 +256,7 @@ func (mbox *mailbox) getMessage(isUid bool, id uint32, items []imap.FetchItem) (
case imap.FetchEnvelope:
fetched.Envelope = getEnvelope(msg)
case imap.FetchBody, imap.FetchBodyStructure:
bs, err := mbox.getBodyStructure(msg.ID, item == imap.FetchBodyStructure)
bs, err := mbox.getBodyStructure(msg, item == imap.FetchBodyStructure)
if err != nil {
return nil, err
}

View File

@ -56,6 +56,7 @@ type Message struct {
ToList []*MessageAddress
Time int64
Size int64
NumAttachments int
IsEncrypted MessageEncryption
ExpirationTime int64
IsReplied int