Skip to content

Commit 119f43a

Browse files
authored
🔀 Merge pull request #271 from gaynetdinov/consider-extra-empty-space-in-bodystructure
Consider extra empty space in BODYSTRUCTURE
2 parents a32cd98 + 3ed0837 commit 119f43a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

‎lib/net/imap/response_parser.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ def body_fields
11551155
# RFC3501, RFC9051:
11561156
# body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
11571157
def body_fld_param
1158+
quirky_SP? # See comments on test_bodystructure_extra_space
11581159
return if NIL?
11591160
param = {}
11601161
lpar

‎test/net/imap/fixtures/response_parser/body_structure_responses.yml

+75
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,81 @@
433433
4383638 NIL (\"attachment\" (\"filename\" \"test.xml\")) NIL NIL) \"mixed\"
434434
(\"boundary\" \"001a1137a5047848e405157ddaa3\") NIL))\r\n"
435435

436+
test_bodystructure_extra_space:
437+
:comments: |
438+
[GH-271] Responses from some IMAP servers contained extra space like this.
439+
The fix has been used since Jan 2014, seems to be easy, and doesn't seem to
440+
cause any harm.
441+
:response: "* 1 FETCH (UID 1 BODYSTRUCTURE (((\"text\" \"plain\" (\"charset\" \"UTF-8\") NIL
442+
NIL \"7bit\" 409 7 NIL NIL NIL)(\"text\" \"html\" (\"charset\" \"UTF-8\") NIL NIL \"7bit\"
443+
592 10 NIL NIL NIL) \"alternative\" (\"boundary\" \"--==_mimepart_5277b641dcc3_57d5887e8325d8\"
444+
\"charset\" \"UTF-8\") NIL NIL) \"mixed\" (\"boundary\" \"--==_mimepart_5277b64110f79_57d5887e832634\"
445+
\"charset\" \"UTF-8\") NIL NIL))\r\n"
446+
447+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
448+
name: FETCH
449+
data: !ruby/struct:Net::IMAP::FetchData
450+
seqno: 1
451+
attr:
452+
UID: 1
453+
BODYSTRUCTURE: !ruby/struct:Net::IMAP::BodyTypeMultipart
454+
media_type: MULTIPART
455+
subtype: MIXED
456+
parts:
457+
- !ruby/struct:Net::IMAP::BodyTypeMultipart
458+
media_type: MULTIPART
459+
subtype: ALTERNATIVE
460+
parts:
461+
- !ruby/struct:Net::IMAP::BodyTypeText
462+
media_type: TEXT
463+
subtype: PLAIN
464+
param:
465+
CHARSET: UTF-8
466+
content_id:
467+
description:
468+
encoding: 7BIT
469+
size: 409
470+
lines: 7
471+
md5:
472+
disposition:
473+
language:
474+
location:
475+
extension:
476+
- !ruby/struct:Net::IMAP::BodyTypeText
477+
media_type: TEXT
478+
subtype: HTML
479+
param:
480+
CHARSET: UTF-8
481+
content_id:
482+
description:
483+
encoding: 7BIT
484+
size: 592
485+
lines: 10
486+
md5:
487+
disposition:
488+
language:
489+
location:
490+
extension:
491+
param:
492+
BOUNDARY: --==_mimepart_5277b641dcc3_57d5887e8325d8
493+
CHARSET: UTF-8
494+
disposition:
495+
language:
496+
location:
497+
extension:
498+
param:
499+
BOUNDARY: --==_mimepart_5277b64110f79_57d5887e832634
500+
CHARSET: UTF-8
501+
disposition:
502+
language:
503+
location:
504+
extension:
505+
raw_data: "* 1 FETCH (UID 1 BODYSTRUCTURE (((\"text\" \"plain\" (\"charset\" \"UTF-8\") NIL NIL
506+
\"7bit\" 409 7 NIL NIL NIL)(\"text\" \"html\" (\"charset\" \"UTF-8\") NIL NIL \"7bit\"
507+
592 10 NIL NIL NIL) \"alternative\" (\"boundary\" \"--==_mimepart_5277b641dcc3_57d5887e8325d8\"
508+
\"charset\" \"UTF-8\") NIL NIL) \"mixed\" (\"boundary\" \"--==_mimepart_5277b64110f79_57d5887e832634\"
509+
\"charset\" \"UTF-8\") NIL NIL))\r\n"
510+
436511
test_bodystructure_mixed_boundary:
437512
:response: "* 2688 FETCH (UID 179161 BODYSTRUCTURE ((\"TEXT\" \"PLAIN\" (\"CHARSET\"
438513
\"iso-8859-1\") NIL NIL \"QUOTED-PRINTABLE\" 200 4 NIL NIL NIL)(\"MESSAGE\"

0 commit comments

Comments
 (0)