From cffd3cd13a5abc00f2d7639612d798eb1ff50e28 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 29 Jan 2020 14:39:30 +0100 Subject: [PATCH] protonmail: add Client.ListLabels --- protonmail/labels.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/protonmail/labels.go b/protonmail/labels.go index b019981..fcd567b 100644 --- a/protonmail/labels.go +++ b/protonmail/labels.go @@ -1,5 +1,9 @@ package protonmail +import ( + "net/http" +) + const ( LabelInbox = "0" LabelAllDraft = "1" @@ -12,3 +16,38 @@ const ( LabelDraft = "8" LabelStarred = "10" ) + +type LabelType int + +const ( + LabelMessage LabelType = 1 + LabelContact LabelType = 2 +) + +type Label struct { + ID string + Name string + Color string + Display int + Type LabelType + Exclusive int + Notify int + Order int +} + +func (c *Client) ListLabels() ([]*Label, error) { + req, err := c.newRequest(http.MethodGet, "/labels", nil) + if err != nil { + return nil, err + } + + var respData struct { + resp + Labels []*Label + } + if err := c.doJSON(req, &respData); err != nil { + return nil, err + } + + return respData.Labels, nil +}