<commit_before>---
title: Extracting recipients information from email headers returned from Gmail API
excerpt: In this post I explain one can properly extract the recipients list from the Gmail API response with some regex.
---

In this post I explain one can properly extract the recipients list from the Gmail API response with some regex.

From the [Gmail API documentation](https://developers.google.com/gmail/api/v1/reference/), when you send a get request to the Gmail API at https://www.googleapis.com/gmail/v1/users/userId/messages/messageId with the appropriate userId and messageId, it returns a [Users.message resource](https://developers.google.com/gmail/api/v1/reference/users/messages#resource) which looks something like this:

```json
{
  "id": string,
  "threadId": string,
  "labelIds": [
    string
  ],
  "snippet": string,
  "historyId": unsigned long,
  "internalDate": long,<commit_msg>fix typo with regex post<commit_after>---
title: Extracting recipients information from email headers returned from Gmail API
excerpt: In this post I explain how we can properly extract the recipients list from the Gmail API response with some regex.
---

In this post I explain how we can properly extract the recipients list from the Gmail API response with some regex.

From the [Gmail API documentation](https://developers.google.com/gmail/api/v1/reference/), when you send a get request to the Gmail API at https://www.googleapis.com/gmail/v1/users/userId/messages/messageId with the appropriate userId and messageId, it returns a [Users.message resource](https://developers.google.com/gmail/api/v1/reference/users/messages#resource) which looks something like this:

```json
{
  "id": string,
  "threadId": string,
  "labelIds": [
    string
  ],
  "snippet": string,
  "historyId": unsigned long,
  "internalDate": long,
{'fraction_non_alphanumeric': 0.09580838323353294, 'fraction_numerical': 0.00326619488296135, 'mean_word_length': 4.552870090634441, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6725640', 'n_tokens_mistral': 510, 'n_tokens_neox': 499, 'n_words': 205}