Update routes to API v4

This commit is contained in:
Michal Horejsek
2020-08-27 10:13:28 +02:00
parent af89931f05
commit 9218598140
19 changed files with 41 additions and 48 deletions

View File

@ -179,7 +179,7 @@ func writeAttachment(w *multipart.Writer, att *Attachment, r io.Reader, sig io.R
//
// The returned created attachment contains the new attachment ID and its size.
func (c *client) CreateAttachment(att *Attachment, r io.Reader, sig io.Reader) (created *Attachment, err error) {
req, w, err := c.NewMultipartRequest("POST", "/attachments")
req, w, err := c.NewMultipartRequest("POST", "/mail/v4/attachments")
if err != nil {
return
}
@ -213,7 +213,7 @@ type UpdateAttachmentSignatureReq struct {
func (c *client) UpdateAttachmentSignature(attachmentID, signature string) (err error) {
updateReq := &UpdateAttachmentSignatureReq{signature}
req, err := c.NewJSONRequest("PUT", "/attachments/"+attachmentID+"/signature", updateReq)
req, err := c.NewJSONRequest("PUT", "/mail/v4/attachments/"+attachmentID+"/signature", updateReq)
if err != nil {
return
}
@ -228,7 +228,7 @@ func (c *client) UpdateAttachmentSignature(attachmentID, signature string) (err
// DeleteAttachment removes an attachment. message is the message ID, att is the attachment ID.
func (c *client) DeleteAttachment(attID string) (err error) {
req, err := c.NewRequest("DELETE", "/attachments/"+attID, nil)
req, err := c.NewRequest("DELETE", "/mail/v4/attachments/"+attID, nil)
if err != nil {
return
}
@ -249,7 +249,7 @@ func (c *client) GetAttachment(id string) (att io.ReadCloser, err error) {
return
}
req, err := c.NewRequest("GET", "/attachments/"+id, nil)
req, err := c.NewRequest("GET", "/mail/v4/attachments/"+id, nil)
if err != nil {
return
}

View File

@ -95,7 +95,7 @@ func TestAttachment_UnmarshalJSON(t *testing.T) {
func TestClient_CreateAttachment(t *testing.T) {
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Ok(t, checkMethodAndPath(r, "POST", "/attachments"))
Ok(t, checkMethodAndPath(r, "POST", "/mail/v4/attachments"))
contentType, params, err := pmmime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
@ -153,7 +153,7 @@ func TestClient_CreateAttachment(t *testing.T) {
func TestClient_DeleteAttachment(t *testing.T) {
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Ok(t, checkMethodAndPath(r, "DELETE", "/attachments/"+testAttachment.ID))
Ok(t, checkMethodAndPath(r, "DELETE", "/mail/v4/attachments/"+testAttachment.ID))
b := &bytes.Buffer{}
if n, _ := b.ReadFrom(r.Body); n != 0 {
@ -172,7 +172,7 @@ func TestClient_DeleteAttachment(t *testing.T) {
func TestClient_GetAttachment(t *testing.T) {
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Ok(t, checkMethodAndPath(r, "GET", "/attachments/"+testAttachment.ID))
Ok(t, checkMethodAndPath(r, "GET", "/mail/v4/attachments/"+testAttachment.ID))
fmt.Fprint(w, testAttachmentCleartext)
}))

View File

@ -236,7 +236,6 @@ func (c *client) doBuffered(req *http.Request, bodyBuffer []byte, retryUnauthori
req.Header.Set("User-Agent", c.cm.config.UserAgent)
req.Header.Set("x-pm-appversion", c.cm.config.AppVersion)
req.Header.Set("x-pm-apiversion", strconv.Itoa(Version))
if c.uid != "" {
req.Header.Set("x-pm-uid", c.uid)

View File

@ -74,9 +74,6 @@ func TestClient_Do(t *testing.T) {
if h.Get("x-pm-appversion") != testClientConfig.AppVersion {
t.Fatalf("Invalid app version header: expected %v, got %v", testClientConfig.AppVersion, h.Get("x-pm-appversion"))
}
if h.Get("x-pm-apiversion") != fmt.Sprintf("%v", Version) {
t.Fatalf("Invalid api version header: expected %v, got %v", Version, h.Get("x-pm-apiversion"))
}
if h.Get("x-pm-uid") != "" {
t.Fatalf("Expected no uid header when not authenticated, got %v", h.Get("x-pm-uid"))
}

View File

@ -32,7 +32,7 @@ type Conversation struct{}
// CountConversations counts conversations by label.
func (c *client) CountConversations(addressID string) (counts []*ConversationsCount, err error) {
reqURL := "/conversations/count"
reqURL := "/mail/v4/conversations/count"
if addressID != "" {
reqURL += ("?AddressID=" + addressID)
}

View File

@ -120,7 +120,7 @@ type ImportMsgRes struct {
func (c *client) Import(reqs []*ImportMsgReq) (resps []*ImportMsgRes, err error) {
importReq := &ImportReq{Messages: reqs}
req, w, err := c.NewMultipartRequest("POST", "/import")
req, w, err := c.NewMultipartRequest("POST", "/mail/v4/messages/import")
if err != nil {
return
}

View File

@ -55,7 +55,7 @@ var testImportRes = &ImportMsgRes{
func TestClient_Import(t *testing.T) { // nolint[funlen]
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Ok(t, checkMethodAndPath(r, "POST", "/import"))
Ok(t, checkMethodAndPath(r, "POST", "/mail/v4/messages/import"))
contentType, params, err := pmmime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {

View File

@ -500,7 +500,7 @@ type MessagesListRes struct {
// ListMessages gets message metadata.
func (c *client) ListMessages(filter *MessagesFilter) (msgs []*Message, total int, err error) {
req, err := c.NewRequest("GET", "/messages", nil)
req, err := c.NewRequest("GET", "/mail/v4/messages", nil)
if err != nil {
return
}
@ -528,7 +528,7 @@ type MessagesCountsRes struct {
// CountMessages counts messages by label.
func (c *client) CountMessages(addressID string) (counts []*MessagesCount, err error) {
reqURL := "/messages/count"
reqURL := "/mail/v4/messages/count"
if addressID != "" {
reqURL += ("?AddressID=" + addressID)
}
@ -554,7 +554,7 @@ type MessageRes struct {
// GetMessage retrieves a message.
func (c *client) GetMessage(id string) (msg *Message, err error) {
req, err := c.NewRequest("GET", "/messages/"+id, nil)
req, err := c.NewRequest("GET", "/mail/v4/messages/"+id, nil)
if err != nil {
return
}
@ -631,7 +631,7 @@ func (c *client) SendMessage(id string, sendReq *SendMessageReq) (sent, parent *
sendReq.Packages = []*MessagePackage{}
}
req, err := c.NewJSONRequest("POST", "/messages/"+id, sendReq)
req, err := c.NewJSONRequest("POST", "/mail/v4/messages/"+id, sendReq)
if err != nil {
return
}
@ -661,7 +661,7 @@ type DraftReq struct {
func (c *client) CreateDraft(m *Message, parent string, action int) (created *Message, err error) {
createReq := &DraftReq{Message: m, ParentID: parent, Action: action, AttachmentKeyPackets: []string{}}
req, err := c.NewJSONRequest("POST", "/messages", createReq)
req, err := c.NewJSONRequest("POST", "/mail/v4/messages", createReq)
if err != nil {
return
}
@ -720,7 +720,7 @@ func (c *client) doMessagesAction(action string, ids []string) (err error) {
// You should not call this directly unless you know what you are doing (it can overload the server).
func (c *client) doMessagesActionInner(action string, ids []string) (err error) {
actionReq := &MessagesActionReq{IDs: ids}
req, err := c.NewJSONRequest("PUT", "/messages/"+action, actionReq)
req, err := c.NewJSONRequest("PUT", "/mail/v4/messages/"+action, actionReq)
if err != nil {
return
}
@ -772,7 +772,7 @@ func (c *client) LabelMessages(ids []string, label string) (err error) {
func (c *client) labelMessages(ids []string, label string) (err error) {
labelReq := &LabelMessagesReq{LabelID: label, IDs: ids}
req, err := c.NewJSONRequest("PUT", "/messages/label", labelReq)
req, err := c.NewJSONRequest("PUT", "/mail/v4/messages/label", labelReq)
if err != nil {
return
}
@ -802,7 +802,7 @@ func (c *client) UnlabelMessages(ids []string, label string) (err error) {
func (c *client) unlabelMessages(ids []string, label string) (err error) {
labelReq := &LabelMessagesReq{LabelID: label, IDs: ids}
req, err := c.NewJSONRequest("PUT", "/messages/unlabel", labelReq)
req, err := c.NewJSONRequest("PUT", "/mail/v4/messages/unlabel", labelReq)
if err != nil {
return
}
@ -820,7 +820,7 @@ func (c *client) EmptyFolder(labelID, addressID string) (err error) {
if labelID == "" {
return errors.New("pmapi: labelID parameter is empty string")
}
reqURL := "/messages/empty?LabelID=" + labelID
reqURL := "/mail/v4/messages/empty?LabelID=" + labelID
if addressID != "" {
reqURL += ("&AddressID=" + addressID)
}

View File

@ -184,7 +184,7 @@ func TestMessage_Encrypt(t *testing.T) {
}
func routeLabelMessages(tb testing.TB, w http.ResponseWriter, r *http.Request) string {
Ok(tb, checkMethodAndPath(r, "PUT", "/messages/label"))
Ok(tb, checkMethodAndPath(r, "PUT", "/mail/v4/messages/label"))
return "messages/label/put_response.json"
}

View File

@ -134,9 +134,6 @@ func checkMethodAndPath(r *http.Request, method, path string) error {
if err := checkHeader(r.Header, "x-pm-appversion", "GoPMAPI_1.0.14"); err != nil {
result = multierror.Append(result, err)
}
if err := checkHeader(r.Header, "x-pm-apiversion", "3"); err != nil {
result = multierror.Append(result, err)
}
if r.Method != method {
err := fmt.Errorf("Invalid request method expected %v, got %v", method, r.Method)
result = multierror.Append(result, err)

View File

@ -104,7 +104,7 @@ const (
// GetMailSettings gets contact details specified by contact ID.
func (c *client) GetMailSettings() (settings MailSettings, err error) {
req, err := c.NewRequest("GET", "/settings/mail", nil)
req, err := c.NewRequest("GET", "/mail/v4/settings", nil)
if err != nil {
return

View File

@ -143,7 +143,6 @@ func (r tlsReport) sendReport(uri, userAgent string) {
req.Header.Add("Content-Type", "application/json")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("x-pm-apiversion", strconv.Itoa(Version))
req.Header.Set("x-pm-appversion", r.AppVersion)
logrus.WithField("request", req).Warn("Reporting TLS mismatch")