Behavior of Custom Headers in Gmail Routing and Apps Script

9 views
Skip to first unread message

Ajay Shinde

unread,
6:14 AM (2 hours ago) 6:14 AM
to Google Apps Script Community
Hi All, 
 
I am trying to read a custom header which i have added  to all incoming messages in gmail by using routing settings 

https://admin.google.com/ac/apps/gmail/routing

2024-07-19_10-36.png

after adding the header I am reading this X-MY-CUSTOM-HEADER in google apps script project. 

const onGmailMessageOpen= (e)=>{
var accessToken = e.gmail.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);

var messageId = e.gmail.messageId;
var message = GmailApp.getMessageById(messageId);

console.log(message.getHeader("X-MY-CUSTOM-HEADER"));
}

my questions are
1.  if incoming message already has X-MY-CUSTOM-HEADER  set, what will happen to the header added using Gmail Routing? Will it always get appended at the end of header list? is there any documentation to confirm this?

2. If duplicate headers  for X-MY-CUSTOM-HEADER are present  then which will get returned upon executing message.getHeader("X-MY-CUSTOM-HEADER")? (I didn't find any documentation for which header value  will be returned by  message.getHeader() if duplicate headers are present. RFC 2822 standard doesn't define strict behavior for duplicate headers. 
behavior which i am seeing is that it picks the last header value, but i am not finding it documented anywhere , can some one point me to the official page where it may be documented)

Regards,
Ajay



Reply all
Reply to author
Forward
0 new messages