@bobfrankston/iflow 1.0.55 → 1.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -521,11 +521,18 @@ export class NativeImapClient {
521
521
  }
522
522
  processBuffer() {
523
523
  while (true) {
524
- // Check for literal {size}\r\n — reading exact byte count of literal data
524
+ // Check for literal {size}\r\n — reading exact BYTE count of literal data
525
+ // CRITICAL: literalBytes is in octets (from IMAP {N}), but this.buffer is a
526
+ // JavaScript string where multi-byte UTF-8 characters count as 1 character.
527
+ // We must use Buffer.byteLength to find the correct character boundary.
525
528
  if (this.pendingCommand?.literalBytes != null) {
526
- if (this.buffer.length >= this.pendingCommand.literalBytes) {
527
- let literal = this.buffer.substring(0, this.pendingCommand.literalBytes);
528
- this.buffer = this.buffer.substring(this.pendingCommand.literalBytes);
529
+ const neededBytes = this.pendingCommand.literalBytes;
530
+ const bufferBytes = Buffer.byteLength(this.buffer, "utf-8");
531
+ if (bufferBytes >= neededBytes) {
532
+ // Find the character position that corresponds to the byte boundary
533
+ const buf = Buffer.from(this.buffer, "utf-8");
534
+ let literal = buf.subarray(0, neededBytes).toString("utf-8");
535
+ this.buffer = buf.subarray(neededBytes).toString("utf-8");
529
536
  // For non-BODY literals (e.g. display names in ENVELOPE), wrap in quotes
530
537
  // so tokenizeParenList treats them as a single token
531
538
  if (!this.pendingCommand.currentLiteralKey) {
@@ -549,7 +556,7 @@ export class NativeImapClient {
549
556
  continue;
550
557
  }
551
558
  if (this.verbose && this.pendingCommand.literalBytes > 0) {
552
- console.log(` [imap] waiting for literal: need ${this.pendingCommand.literalBytes}, have ${this.buffer.length}`);
559
+ console.log(` [imap] waiting for literal: need ${neededBytes} bytes, have ${bufferBytes} bytes`);
553
560
  }
554
561
  break; // Wait for more data
555
562
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/iflow",
3
- "version": "1.0.55",
3
+ "version": "1.0.56",
4
4
  "description": "IMAP client wrapper library",
5
5
  "main": "index.js",
6
6
  "types": "index.ts",