Byron/google-apis-rs

`JsonDecodeError` when decoding response for gmail messages.get method

niconicoj opened this issue · 4 comments

Hi,

I am using the google-gmail1 crate and trying to get the content of some mail by making a messages.get call but it fails at the decoding step with the following message (I cut the message short since it contains some sensitive info) :

GmailApiError(JsonDecodeError("{\n  \"id\": \"18f5dc3c6c373405\",\n  \"threadId\": \"18f5dc3c6c373405\",\n  \"labelIds\": [\n    \"Label_5088752233975968583\",\n    \"IMPORTANT\",\n    \"CATEGORY_PERSONAL\",\n    \"INBOX\"\n  ],\n  \"snippet\": [...] }\n      }\n    ]\n  },\n  \"sizeEstimate\": 46682,\n  \"historyId\": \"73834\",\n  \"internalDate\": \"1715265050000\"\n}\n", Error("Invalid byte 45, offset 271.", line: 134, column: 9)))

Digging into the error it seems it fails to decode the data part of the MessagePartBody which is said to be base64url.

I looked around and found a bunch of issues related to this. I also found issue #446 which I understand is supposed to be a fix for this kind of problem. Unfortunately it does not seems like it works for this request. Maybe it even broke it since it seems the fix replaced the previous urlsafe_base64 decoder with the standard_base64 altogether.

Is this analysis correct ? Are there any ideas on how to fix the issue ?

Thanks for reporting. The problem is that some endpoints need URLsafe base64, others need the normal one and it's unclear which one to pick by looking at the API description. At least that's the assumption right now, which is why either way it's going to be wrong for some.

I've just encountered this same issue. Would it be possible to infer it from the documentation?

I'm trying to navigate through how the project works and it looks possible. For example https://gmail.googleapis.com/$discovery/rest?version=v1 mentions base64url and standard base64 in the description

I've opened #507 with a fix for this