MessageID is different after send and in message view

255 views
Skip to first unread message

Amiram Korach

unread,
Jul 13, 2020, 1:42:36 PM7/13/20
to InboxSDK
I saw this message was asked before but I didn't see any solution.
The scenario is: we use the sent event to get the message id that was sent and we save it to our server. In addition, each message view that being created, we save the data of this message. This message view can be of an incoming message but it can be of an outgoing message too. When the user is sending an inline reply, right after the sent event a message view with the same message is created, so we need to make sure we don't save the message twice.
Recently we saw that sometimes the message id's in both places are not equal so we get a duplicate message in our server. In the message view I see the id that returned from messageView.getMessageIDAsync(), but the id returned from the sent event is somewhere in an hidden html. After refreshing the page, the id in the html of the message view returns to be the same as the one from the sent event, and the message id of the message view doesn't exist anymore in the html.
This doesn't happen always but most of the times an inline reply is sent.

This may look like a gmail bug. If you extract the message id from the message view html, there may be a workaround to get it by calling the "view original" page and get the message id from there.

Thanks

ale...@yoxel.com

unread,
May 31, 2021, 9:38:16 AM5/31/21
to InboxSDK
We're experiencing the same issue. A message id after inline reply is not a real message id as we get 404 Not Found from Gmail API.
And after revisiting the thread InboxSDK provides a different/real message id for the reply message.

Thoughts?

Amiram Korach

unread,
May 31, 2021, 9:56:07 AM5/31/21
to ale...@yoxel.com, InboxSDK
Here is our solution for that. We fetch the page with the headers ("View Original" page) and get the id from it.

export async function getMessageId(messageView: MessageView): Promise<string> {
const ik = document.head.getAttribute('data-inboxsdk-ik-value');
const messageId = messageView.getBodyElement().closest('div[data-message-id]')?.getAttribute('data-message-id')?.slice(1);

if (!ik || !messageId) {
// log error
return null;
}

const url = `https://mail.google.com/mail/u/0?ik=${ik}&view=om&permmsgid=${encodeURIComponent(messageId)}`;

let data;

try {
const res = await axios.get<string>(url);
data = res.data;
} catch (err) {
if ((err as AxiosError)?.response?.status === 403) {
// log error
} else {
// log error
}
}

if (!data) {
return null;
}

let doc: Document;

try {
doc = new DOMParser().parseFromString(data, 'text/html');
} catch (err) {
// log error
return null;
}

let resolvedMessageId: string;

try {
const downloadLink: HTMLAnchorElement = doc.querySelector('a.download-buttons');

if (downloadLink) {
resolvedMessageId = new URL(downloadLink.href).searchParams.get('th');
} else {
// log error
}
} catch (err) {
// log error
}

return resolvedMessageId;
}


--
You received this message because you are subscribed to the Google Groups "InboxSDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inboxsdk+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inboxsdk/6e546493-779d-4244-86aa-890b2ba6b5d4n%40googlegroups.com.

ale...@yoxel.com

unread,
May 31, 2021, 10:22:25 AM5/31/21
to InboxSDK
Thanks for sharing this.
Reply all
Reply to author
Forward
0 new messages