|
273 | 273 | $stream->open(); |
274 | 274 |
|
275 | 275 | // Simulating BODY[TEXT] before BODY[HEADER] |
276 | | - $stream->feed([ |
277 | | - '* 1 FETCH (UID 123 FLAGS (\\Seen) BODY[TEXT] {0}', |
278 | | - '', |
279 | | - ' BODY[HEADER] {0}', |
280 | | - '', |
281 | | - ')', |
| 276 | + $stream->feedRaw([ |
| 277 | + "* 1 FETCH (UID 123 FLAGS (\\Seen) BODY[TEXT] {13}\r\n", |
| 278 | + "Hello World\r\n", |
| 279 | + " BODY[HEADER] {23}\r\n", |
| 280 | + "Subject: Test Message\r\n", |
| 281 | + ")\r\n", |
282 | 282 | ]); |
283 | 283 |
|
284 | 284 | $tokenizer = new ImapTokenizer($stream); |
|
301 | 301 | $flags = $data->lookup('FLAGS'); |
302 | 302 | expect($flags)->not->toBeNull(); |
303 | 303 |
|
304 | | - // Verify we can lookup both BODY sections |
| 304 | + // Verify we can lookup both BODY sections with correct content |
305 | 305 | $text = $data->lookup('[TEXT]'); |
306 | 306 | expect($text)->not->toBeNull(); |
| 307 | + expect($text->value)->toBe("Hello World\r\n"); |
307 | 308 |
|
308 | 309 | $header = $data->lookup('[HEADER]'); |
309 | 310 | expect($header)->not->toBeNull(); |
310 | | -})->issue(115); |
| 311 | + expect($header->value)->toBe("Subject: Test Message\r\n"); |
| 312 | +}); |
311 | 313 |
|
312 | 314 | test('parses fetch response with body header then text', function () { |
313 | 315 | $stream = new FakeStream; |
314 | 316 | $stream->open(); |
315 | 317 |
|
316 | 318 | // Simulating BODY[HEADER] before BODY[TEXT] |
317 | | - $stream->feed([ |
318 | | - '* 1 FETCH (UID 456 FLAGS (\\Seen) BODY[HEADER] {0}', |
319 | | - '', |
320 | | - ' BODY[TEXT] {0}', |
321 | | - '', |
322 | | - ')', |
| 319 | + $stream->feedRaw([ |
| 320 | + "* 1 FETCH (UID 456 FLAGS (\\Seen) BODY[HEADER] {26}\r\n", |
| 321 | + |
| 322 | + " BODY[TEXT] {20}\r\n", |
| 323 | + "Message body here.\r\n", |
| 324 | + ")\r\n", |
323 | 325 | ]); |
324 | 326 |
|
325 | 327 | $tokenizer = new ImapTokenizer($stream); |
|
342 | 344 | $flags = $data->lookup('FLAGS'); |
343 | 345 | expect($flags)->not->toBeNull(); |
344 | 346 |
|
345 | | - // Verify we can lookup both BODY sections |
| 347 | + // Verify we can lookup both BODY sections with correct content |
346 | 348 | $header = $data->lookup('[HEADER]'); |
347 | 349 | expect($header)->not->toBeNull(); |
| 350 | + expect( $header-> value)-> toBe( "From: [email protected]\r\n"); |
348 | 351 |
|
349 | 352 | $text = $data->lookup('[TEXT]'); |
350 | 353 | expect($text)->not->toBeNull(); |
351 | | -})->issue(115); |
| 354 | + expect($text->value)->toBe("Message body here.\r\n"); |
| 355 | +}); |
352 | 356 |
|
353 | 357 | test('parses fetch response with all metadata and body parts', function () { |
354 | 358 | $stream = new FakeStream; |
355 | 359 | $stream->open(); |
356 | 360 |
|
357 | 361 | // Full FETCH response with all common fields |
358 | | - $stream->feed([ |
359 | | - '* 1 FETCH (UID 789 RFC822.SIZE 1024 FLAGS (\\Seen \\Flagged) BODY[TEXT] {0}', |
360 | | - '', |
361 | | - ' BODY[HEADER] {0}', |
362 | | - '', |
363 | | - ')', |
| 362 | + $stream->feedRaw([ |
| 363 | + "* 1 FETCH (UID 789 RFC822.SIZE 1024 FLAGS (\\Seen \\Flagged) BODY[TEXT] {25}\r\n", |
| 364 | + "This is the email body.\r\n", |
| 365 | + " BODY[HEADER] {46}\r\n", |
| 366 | + "To: [email protected]\r\nSubject: Re: Test\r\n", |
| 367 | + ")\r\n", |
364 | 368 | ]); |
365 | 369 |
|
366 | 370 | $tokenizer = new ImapTokenizer($stream); |
|
373 | 377 | $data = $response->tokenAt(3); |
374 | 378 | expect($data)->toBeInstanceOf(ListData::class); |
375 | 379 |
|
376 | | - // Verify all lookups work correctly |
| 380 | + // Verify all lookups work correctly with actual content |
377 | 381 | expect($data->lookup('UID')?->value)->toBe('789'); |
378 | 382 | expect($data->lookup('RFC822.SIZE')?->value)->toBe('1024'); |
379 | 383 | expect($data->lookup('FLAGS'))->not->toBeNull(); |
380 | | - expect($data->lookup('[TEXT]'))->not->toBeNull(); |
381 | | - expect($data->lookup('[HEADER]'))->not->toBeNull(); |
382 | | -})->issue(115); |
| 384 | + expect($data->lookup('[TEXT]')->value)->toBe("This is the email body.\r\n"); |
| 385 | + expect( $data-> lookup( '[HEADER]') ->value)->toBe("To: [email protected]\r\nSubject: Re: Test\r\n"); |
| 386 | +}); |
0 commit comments