Given a threadGmailId, or possibly an array of…
return ALL email addresses in that thread.
When getting a thread I can get all the messages and end up with an array of to: email addresses
will be duplicates and some with different formatting of the actual name and some with only the email address
// Initialize an array to store the email addresses
let emailAddresses = [];
// Regular expression to match the email format
let emailRegex = /<(.*)>/;
// Loop over input items and extract the email addresses
for (const item of $input.all()) {
if (item.json.To) {
let match = item.json.To.match(emailRegex);
if (match) {
emailAddresses.push(match[1]);
}
}
if (item.json.From) {
let match = item.json.From.match(emailRegex);
if (match) {
emailAddresses.push(match[1]);
}
}
if (item.json['Reply-To']) {
let match = item.json['Reply-To'].match(emailRegex);
if (match) {
emailAddresses.push(match[1]);
}
}
}
// Remove duplicates
emailAddresses = [...new Set(emailAddresses)];
// Sort the email addresses
emailAddresses.sort();
return { emailAddresses };