From ea188ff1331f37c9f67279465749f62ea136e411 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 14 Sep 2020 12:46:22 +0200 Subject: [PATCH] protonmail: add Client.GetConversation --- protonmail/conversations.go | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 protonmail/conversations.go diff --git a/protonmail/conversations.go b/protonmail/conversations.go new file mode 100644 index 0000000..423ec2f --- /dev/null +++ b/protonmail/conversations.go @@ -0,0 +1,44 @@ +package protonmail + +import ( + "net/http" + "net/url" +) + +type Conversation struct { + ID string + Order int64 + Subject string + Senders []*MessageAddress + Recipients []*MessageAddress + NumMessages int + NumUnread int + NumAttachments int + ExpirationTime Timestamp + TotalSize int64 + AddressID string + LabelIDs []string +} + +func (c *Client) GetConversation(id, msgID string) (*Conversation, []*Message, error) { + v := url.Values{} + if msgID != "" { + v.Set("MessageID", msgID) + } + + req, err := c.newRequest(http.MethodGet, "/conversations/"+id+"?"+v.Encode(), nil) + if err != nil { + return nil, nil, err + } + + var respData struct { + resp + Conversation *Conversation + Messages []*Message + } + if err := c.doJSON(req, &respData); err != nil { + return nil, nil, err + } + + return respData.Conversation, respData.Messages, nil +}