nylas/nylas-ruby

More options for reading email headers

Closed this issue · 3 comments

Is your feature request related to a problem? Please describe.
There is presently no option for reading all email headers for a given message using this SDK. This can make using the sdk pretty inflexible.

One specific problem that is probably common is that when dealing with mailing lists often the email in the "To" field is not necessarily the receiving address you may expect. "Delivered-To" often is the address that is actually authenticated with Nylas or an alias for that address, more in line with expectations.

Describe the solution you'd like
Provide a way to pull the full headers for a given message.

The Nylas API already surfaces a path to retrieving the rfc822 formatted email which can be used to parse out the headers, even allowing this would provide a path to parsing these headers without breaking out of the SDK and implementing a separate implementation that uses HTTP to hit the Nylas API.

Describe alternatives you've considered
Developing a second implementation of the Nylas API directly to grab the rfc822 formatted messages and parsing out the headers myself.

Additional context
Providing the Message-ID header was a nice touch but given IANA's list of header proposals I think there may be a long tail of use cases you may want to support in the long term. This is why I suggest a way to return all headers and not just my specific use case of "Delivered-To". In the end that's a Nylas decision, though.

@chris-pauley Thanks for adding this request, we will take a look and get back to you with any updates.

Hey @chris-pauley thanks for opening this ticket. Just going through this now, and we do have a method for parsing out headers from messages, as well as a method for returning a rfc822 formatted message (albeit not documented in the best way):

To get the headers for a message you would need to inflate the message object by calling the expanded view, like so:

nylas = Nylas::API.new(
    app_id: CLIENT_ID,
    app_secret: CLIENT_SECRET,
    access_token: ACCESS_TOKEN
)

message = nylas.messages.expanded.find("MESSAGE_ID")
headers = message.headers

but note that this returns what the Nylas API scrapes for the headers, which from my testing is less than what the rfc822 messages provide. To get the rfc822 message you can do it like so:

nylas = Nylas::API.new(
    app_id: CLIENT_ID,
    app_secret: CLIENT_SECRET,
    access_token: ACCESS_TOKEN
)

raw_message = nylas.messages.raw.find("MESSAGE_ID")

raw_message will be a string containing the rfc822 message. From there you can perform parsing. I think this should at least partially satisfy your problem until we can explore a way to maybe extract the headers out using the SDK itself as a feature enhancement sometime in the future.

Try the above samples and please let me know if you're successful! Thank you and sorry for the delay.

Closing this ticket for now, @chris-pauley let me know if you have any comments or issues with the above solution! I have added your feature request of having an easy way to extract headers via the API on our Nylas Roadmap board. If it gets picked up then you can see it on the board and track it's progress.