From b0c14ba5b9d3958d9b68ced19c3199b0645a7d80 Mon Sep 17 00:00:00 2001 From: bosiraphael <71827178+bosiraphael@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:26:29 +0100 Subject: [PATCH] 3571 remove reply quotations from emails (#3630) * lib is working * update * plural --- packages/twenty-server/package.json | 1 + .../fetch-messages-by-batches.service.ts | 18 +++++++++++++++++- yarn.lock | 8 ++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index a352206bc8..c3878eee59 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -92,6 +92,7 @@ "passport-local": "^1.0.0", "pg": "^8.11.3", "pg-boss": "^9.0.3", + "planer": "^1.2.0", "react": "^18.2.0", "rimraf": "^3.0.2", "sharp": "^0.32.1", diff --git a/packages/twenty-server/src/workspace/messaging/services/fetch-messages-by-batches.service.ts b/packages/twenty-server/src/workspace/messaging/services/fetch-messages-by-batches.service.ts index 5ea66bd6fe..c776868260 100644 --- a/packages/twenty-server/src/workspace/messaging/services/fetch-messages-by-batches.service.ts +++ b/packages/twenty-server/src/workspace/messaging/services/fetch-messages-by-batches.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import axios, { AxiosInstance, AxiosResponse } from 'axios'; import { simpleParser, AddressObject } from 'mailparser'; +import planer from 'planer'; import { GmailMessage, @@ -197,6 +198,21 @@ export class FetchMessagesByBatchesService { ...this.formatAddressObjectAsParticipants(bcc, 'bcc'), ]; + let textWithoutReplyQuotations = text; + + if (text) + try { + textWithoutReplyQuotations = planer.extractFrom( + text, + 'text/plain', + ); + } catch (error) { + console.log( + 'Error while trying to remove reply quotations', + error, + ); + } + const messageFromGmail: GmailMessage = { historyId, externalId: id, @@ -207,7 +223,7 @@ export class FetchMessagesByBatchesService { fromHandle: from.value[0].address || '', fromDisplayName: from.value[0].name || '', participants, - text: text || '', + text: textWithoutReplyQuotations || '', html: html || '', attachments, }; diff --git a/yarn.lock b/yarn.lock index 6810d53edc..fef0e5f579 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36032,6 +36032,13 @@ __metadata: languageName: node linkType: hard +"planer@npm:^1.2.0": + version: 1.2.0 + resolution: "planer@npm:1.2.0" + checksum: d2515294e772bbba1b26c0fa611590369f1ff510b11855eb55cb30e093286c888868020b9a62e41a46a4c5686def03f5c34fd91801fc9104404ffeb01ad46b78 + languageName: node + linkType: hard + "playwright-core@npm:1.40.1, playwright-core@npm:>=1.2.0": version: 1.40.1 resolution: "playwright-core@npm:1.40.1" @@ -42451,6 +42458,7 @@ __metadata: passport-local: "npm:^1.0.0" pg: "npm:^8.11.3" pg-boss: "npm:^9.0.3" + planer: "npm:^1.2.0" react: "npm:^18.2.0" rimraf: "npm:^3.0.2" sharp: "npm:^0.32.1"