# The IMAP node encoding

**URL:** <https://community.n8n.io/t/the-imap-node-encoding/94146>\
**Category:** Questions\
**Created:** [March 28, 2025, 7:42pm UTC](https://community.n8n.io/t/the-imap-node-encoding/94146 "2025-03-28T19:42:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![koordinator7](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@koordinator7](https://community.n8n.io/u/koordinator7)\
**Post date:** [March 28, 2025, 7:42pm UTC](https://community.n8n.io/t/the-imap-node-encoding/94146/1 "2025-03-28T19:42:41Z")

</div>

The imap node does something with the encoding. Here is the full text of the letter with technical fields:

Received: from [mail-collectors-ext-production-main-66.klg.yp-c.yandex.net](http://mail-collectors-ext-production-main-66.klg.yp-c.yandex.net) ([mail-collectors-ext-production-main-66.klg.yp-c.yandex.net](http://mail-collectors-ext-production-main-66.klg.yp-c.yandex.net) [2a02:6b8:c42:dda8:0:5e2b:7654:0])  
by [mail-nwsmtp-mxback-production-main-76.klg.yp-c.yandex.net](http://mail-nwsmtp-mxback-production-main-76.klg.yp-c.yandex.net) (mxback/Yandex) with HTTP id RbNSYj9L64Y0-y05P3QKh  
for [sale@shpilka-9066.ru](mailto:sale@shpilka-9066.ru); Fri, 28 Mar 2025 11:37:27 +0300  
X-Yandex-Fwd: 2  
Received: from [sale@imap.yandex.ru](mailto:sale@imap.yandex.ru) ([77.88.21.125])  
by [mail.yandex.ru](http://mail.yandex.ru) with POP3 id QbNNNQ3LkuQ0  
for 1130000042718651@2760933; Fri, 28 Mar 2025 11:37:27 +0300  
X-yandex-pop-server: [imap.yandex.ru](http://imap.yandex.ru)  
X-yandex-rpop-id: 2760933  
X-yandex-rpop-info: [sale@imap.yandex.ru](mailto:sale@imap.yandex.ru)  
X-yandex-rpop-foldername: SU5CT1g=  
Received: from [postback17b.mail.yandex.net](http://postback17b.mail.yandex.net) ([postback17b.mail.yandex.net](http://postback17b.mail.yandex.net) [2a02:6b8:c02:900:1:45:d181:da17])  
by [mail-notsolitesrv-production-main-87.sas.yp-c.yandex.net](http://mail-notsolitesrv-production-main-87.sas.yp-c.yandex.net) (notsolitesrv/Yandex) with LMTPS id wlxx7ShWAl5I-vG302R7a;  
Fri, 28 Mar 2025 11:36:00 +0300  
Received: from [mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net](http://mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net) ([mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net](http://mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net) [IPv6:2a02:6b8:c37:7da2:0:640:6456:0])  
by [postback17b.mail.yandex.net](http://postback17b.mail.yandex.net) (Yandex) with ESMTPS id 6523060BB2;  
Fri, 28 Mar 2025 11:36:00 +0300 (MSK)  
Received: by [mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net](http://mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net) (smtp/Yandex) with ESMTPSA id qZNs7mPLduQ0-zeb3b7yW;  
Fri, 28 Mar 2025 11:36:00 +0300  
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; [d=yandex.ru](http://d=yandex.ru); s=mail;  
t=1743150960; bh=Z5fcybnqI61Om0MK6MuFAKA3pmWte1Rou5SCuRnLkRA=;  
h=Subject:Message-ID:Reply-To:To:From:Date;  
b=YoDy6v8vRQL5SV/OJEv/zG108KCSQ/vZEz14UTNx5voMh6qeU+LlmB6rAa9oHfn4N  
aRRLlhbT+fI9BfkwU8keiHB7eG063eSP940MqdXqVtAY1nhH+7um5l7FFvSFVNFO5G  
pA9hUj7ipu+ELr8SxHX15b81x9NaIvqZYNVGfyUo=  
Date: Fri, 28 Mar 2025 11:34:45 +0300  
From: =?windows-1251?B?yvDl78ru7O/r5ery?= [krepkomplekt@yandex.ru](mailto:krepkomplekt@yandex.ru)  
Reply-To: =?windows-1251?B?yvDl78ru7O/r5ery?= [krepkomplekt@yandex.ru](mailto:krepkomplekt@yandex.ru)  
Organization: =?windows-1251?B?zs7OICLK8OXvyu7s7+vl6vIi?=  
X-Priority: 3 (Normal)  
Message-ID: [1821594317.20250328113445@yandex.ru](mailto:1821594317.20250328113445@yandex.ru)  
To: =?windows-1251?B?0eXw4+Xp?= [sale@grover-6402.ru](mailto:sale@grover-6402.ru)  
Subject: =?windows-1251?B?x+Dv8O7xIO3gIOjn4+7y7uLr5e3o5SDj4Onq6CDv7iDDztHSIDI1MjYtNzA=?=  
MIME-Version: 1.0  
Content-Type: text/plain; charset=windows-1251  
Content-Transfer-Encoding: 8bit  
X-Yandex-Forward: 3c7a78b1979ee567785fafe659fc4605

Добрый день.

Гайка М27 ГОСТ 2526-70, ст.12Х18Н10Т - 50 штук

С уважением, Владимир

–  
Компания “КрепКомплект™”  
(812) 363-34-09, 938-00-12

## The IMAP node receives such data: [{ “textHtml”: “”, “textPlain”: “������ ����.\r\n\r\n ����� �27 ���� 2526-70, ��.12�18�10� - 50 ����\r\n \r\n\r\n� ���������, ��������\r\n\r\n–\r\n�������� "������������"\r\n(812) 363-34-09, 938-00-12\r\n\r\n”, “metadata”: { “received”: “from [mail-collectors-ext-production-main-66.klg.yp-c.yandex.net](http://mail-collectors-ext-production-main-66.klg.yp-c.yandex.net) ([mail-collectors-ext-production-main-66.klg.yp-c.yandex.net](http://mail-collectors-ext-production-main-66.klg.yp-c.yandex.net) [2a02:6b8:c42:dda8:0:5e2b:7654:0])\tby [mail-nwsmtp-mxback-production-main-76.klg.yp-c.yandex.net](http://mail-nwsmtp-mxback-production-main-76.klg.yp-c.yandex.net) (mxback/Yandex) with HTTP id RbNSYj9L64Y0-y05P3QKh\tfor [sale@shpilka-9066.ru](mailto:sale@shpilka-9066.ru); Fri, 28 Mar 2025 11:37:27 +0300”, “x-yandex-fwd”: “2”, “x-yandex-pop-server”: “[imap.yandex.ru](http://imap.yandex.ru)”, “x-yandex-rpop-id”: “2760933”, “x-yandex-rpop-info”: “[sale@imap.yandex.ru](mailto:sale@imap.yandex.ru)”, “x-yandex-rpop-foldername”: “SU5CT1g=”, “dkim-signature”: “v=1; a=rsa-sha256; c=relaxed/relaxed; [d=yandex.ru](http://d=yandex.ru); s=mail;\tt=1743150960; bh=Z5fcybnqI61Om0MK6MuFAKA3pmWte1Rou5SCuRnLkRA=;\th=Subject:Message-ID:Reply-To:To:From:Date;\tb=YoDy6v8vRQL5SV/OJEv/zG108KCSQ/vZEz14UTNx5voMh6qeU+LlmB6rAa9oHfn4N\t aRRLlhbT+fI9BfkwU8keiHB7eG063eSP940MqdXqVtAY1nhH+7um5l7FFvSFVNFO5G\t pA9hUj7ipu+ELr8SxHX15b81x9NaIvqZYNVGfyUo=”, “reply-to”: “КрепКомплект [krepkomplekt@yandex.ru](mailto:krepkomplekt@yandex.ru)”, “organization”: “ООО "КрепКомплект"”, “x-priority”: “3 (Normal)”, “message-id”: “[1821594317.20250328113445@yandex.ru](mailto:1821594317.20250328113445@yandex.ru)”, “mime-version”: “1.0”, “content-type”: “text/plain; charset=windows-1251”, “content-transfer-encoding”: “8bit”, “x-yandex-forward”: “3c7a78b1979ee567785fafe659fc4605” }, “date”: “Fri, 28 Mar 2025 11:34:45 +0300”, “from”: “КрепКомплект [krepkomplekt@yandex.ru](mailto:krepkomplekt@yandex.ru)”, “to”: “Сергей [sale@grover-6402.ru](mailto:sale@grover-6402.ru)”, “subject”: “Запрос на изготовление гайки по ГОСТ 2526-70” } ] Thus, such text: "Добрый день. Гайка М27 ГОСТ 2526-70, ст.12Х18Н10Т - 50 штук С уважением, Владимир

Компания “КрепКомплект™”  
(812) 363-34-09, 938-00-12"  
turns into this:  
“������ ����.\r\n\r\n ����� �27 ���� 2526-70, ��.12�18�10� - 50 ����\r\n \r\n\r\n� ���������, ��������\r\n\r\n–\r\n�������� "������������"\r\n(812) 363-34-09, 938-00-12\r\n\r\n”

How can this be fixed?

## Share the output returned by the last node

## Information on your n8n setup

- \*\*n8n version: 1.80.3
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- \*\*Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
- \*\*Operating system: Ubuntu 22.04

---

<div class="post-metadata">

**Author:** ![ThinkBot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/thinkbot/32/62172_2.png) [@ThinkBot](https://community.n8n.io/u/ThinkBot)\
**Post date:** [March 29, 2025, 6:06pm UTC](https://community.n8n.io/t/the-imap-node-encoding/94146/2 "2025-03-29T18:06:26Z")

</div>

Try re-encode this with a code node after the fact, something like:

```auto
for (const item of items) {
  if (item.json.textPlain) {
    let charset = 'windows-1251';
    
    if (item.json.metadata && item.json.metadata['content-type']) {
      const contentType = item.json.metadata['content-type'];
      const charsetMatch = contentType.match(/charset=([^;]+)/i);
      if (charsetMatch) {
        charset = charsetMatch[1].trim();
      }
    }
    
    // Convert using Node.js built-in Buffer capabilities
    try {
      // Create a buffer from the binary data
      const buffer = Buffer.from(item.json.textPlain, 'binary');
      // Decode using TextDecoder (built into Node.js)
      const decoder = new TextDecoder(charset);
      item.json.textPlain = decoder.decode(buffer);
    } catch (error) {
      // If decoding fails, add an error field but keep original data
      item.json.decodingError = error.message;
    }
  }
  
  return item;
}

```

---

<div class="post-metadata">

**Author:** ![koordinator7](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@koordinator7](https://community.n8n.io/u/koordinator7)\
**Post date:** [March 30, 2025, 5:11pm UTC](https://community.n8n.io/t/the-imap-node-encoding/94146/3 "2025-03-30T17:11:21Z")

</div>

Here is a question about the work of the IMAP node. It immediately gives the wrong encoding. Then it is impossible to decode, I tried different methods.

---

<div class="post-metadata">

**Author:** ![ThinkBot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/thinkbot/32/62172_2.png) [@ThinkBot](https://community.n8n.io/u/ThinkBot)\
**Post date:** [March 30, 2025, 5:13pm UTC](https://community.n8n.io/t/the-imap-node-encoding/94146/4 "2025-03-30T17:13:31Z")

</div>

Have you tried something like the above? What are the results/errors?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [June 28, 2025, 5:14pm UTC](https://community.n8n.io/t/the-imap-node-encoding/94146/5 "2025-06-28T17:14:14Z")

</div>

Closed on June 28, 2025, 5:14pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
