@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.
- package/imaplib/imap-native.js +12 -5
- package/package.json +1 -1
package/imaplib/imap-native.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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 ${
|
|
559
|
+
console.log(` [imap] waiting for literal: need ${neededBytes} bytes, have ${bufferBytes} bytes`);
|
|
553
560
|
}
|
|
554
561
|
break; // Wait for more data
|
|
555
562
|
}
|