Skip to content

Commit

Permalink
Merge pull request #5 from SlashDevSlashGnoll/empty-mime-part-body
Browse files Browse the repository at this point in the history
Parse body parts with 0 length
  • Loading branch information
miximka authored Jan 16, 2019
2 parents 397bdf1 + fae8220 commit ccaec7b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
6 changes: 6 additions & 0 deletions MimeParser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
088827DD1FDEBE6E00FEE3BA /* MimeParser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 088827BE1FDEB12500FEE3BA /* MimeParser.framework */; };
08ABE7762063D04A00F945CF /* SpecialCharsBoundary.txt in Resources */ = {isa = PBXBuildFile; fileRef = 08ABE7752063D04A00F945CF /* SpecialCharsBoundary.txt */; };
08ABE7772063D04A00F945CF /* SpecialCharsBoundary.txt in Resources */ = {isa = PBXBuildFile; fileRef = 08ABE7752063D04A00F945CF /* SpecialCharsBoundary.txt */; };
0C9F212121EE6394009DCA21 /* MeetingRequestWithZeroLengthPart.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0C9F211F21EE61D6009DCA21 /* MeetingRequestWithZeroLengthPart.txt */; };
0C9F212221EE6395009DCA21 /* MeetingRequestWithZeroLengthPart.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0C9F211F21EE61D6009DCA21 /* MeetingRequestWithZeroLengthPart.txt */; };
4472876B20CF23A500CD7412 /* EmailWithApplicationAttachment.txt in Resources */ = {isa = PBXBuildFile; fileRef = 4472876A20CF23A500CD7412 /* EmailWithApplicationAttachment.txt */; };
4472876C20CF23A500CD7412 /* EmailWithApplicationAttachment.txt in Resources */ = {isa = PBXBuildFile; fileRef = 4472876A20CF23A500CD7412 /* EmailWithApplicationAttachment.txt */; };
813C0B4920D18A11007CF9B5 /* EmailParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 813C0B4820D18A11007CF9B5 /* EmailParsingTests.swift */; };
Expand Down Expand Up @@ -74,6 +76,7 @@
088827BE1FDEB12500FEE3BA /* MimeParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MimeParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
088827D81FDEBE6E00FEE3BA /* MimeParserTests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "MimeParserTests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
08ABE7752063D04A00F945CF /* SpecialCharsBoundary.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SpecialCharsBoundary.txt; sourceTree = "<group>"; };
0C9F211F21EE61D6009DCA21 /* MeetingRequestWithZeroLengthPart.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MeetingRequestWithZeroLengthPart.txt; sourceTree = "<group>"; };
4472876A20CF23A500CD7412 /* EmailWithApplicationAttachment.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EmailWithApplicationAttachment.txt; sourceTree = "<group>"; };
813C0B4820D18A11007CF9B5 /* EmailParsingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailParsingTests.swift; sourceTree = "<group>"; };
8145B1C620D187440019E405 /* MimeParsingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MimeParsingTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -215,6 +218,7 @@
children = (
4472876A20CF23A500CD7412 /* EmailWithApplicationAttachment.txt */,
81E3FCAC1FDF1EB600C00F25 /* Info.plist */,
0C9F211F21EE61D6009DCA21 /* MeetingRequestWithZeroLengthPart.txt */,
81E3FCB21FDF1EB600C00F25 /* MessageWithEnclosedMessageAsAttachment.txt */,
81E3FCB11FDF1EB600C00F25 /* QuotedPrintableMessage.txt */,
81E3FCAD1FDF1EB600C00F25 /* SimpleMessage.txt */,
Expand Down Expand Up @@ -386,6 +390,7 @@
buildActionMask = 2147483647;
files = (
08ABE7772063D04A00F945CF /* SpecialCharsBoundary.txt in Resources */,
0C9F212221EE6395009DCA21 /* MeetingRequestWithZeroLengthPart.txt in Resources */,
81E3FCBC1FDF1EBC00C00F25 /* SimpleMessageWithBinaryAttachment.txt in Resources */,
81E3FCBA1FDF1EBC00C00F25 /* QuotedPrintableMessage.txt in Resources */,
81E3FCBD1FDF1EBC00C00F25 /* SimpleMessageWithBinaryAttachmentCRLN.txt in Resources */,
Expand All @@ -408,6 +413,7 @@
buildActionMask = 2147483647;
files = (
08ABE7762063D04A00F945CF /* SpecialCharsBoundary.txt in Resources */,
0C9F212121EE6394009DCA21 /* MeetingRequestWithZeroLengthPart.txt in Resources */,
81E3FCB61FDF1EBB00C00F25 /* SimpleMessageWithBinaryAttachment.txt in Resources */,
81E3FCB41FDF1EBB00C00F25 /* QuotedPrintableMessage.txt in Resources */,
81E3FCB71FDF1EBB00C00F25 /* SimpleMessageWithBinaryAttachmentCRLN.txt in Resources */,
Expand Down
2 changes: 1 addition & 1 deletion Sources/MimeParser/MimeParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct MimePartsSplitter {
break
}

if searchRange.lowerBound == nextEmptyLineRange.lowerBound {
if searchRange.lowerBound == nextEmptyLineRange.lowerBound || nextEmptyLineRange.upperBound == string.endIndex {
emptyLineRange = nextEmptyLineRange
} else {
searchRange = Range<String.Index>(uncheckedBounds: (nextEmptyLineRange.upperBound, string.endIndex))
Expand Down
32 changes: 32 additions & 0 deletions Tests/MimeParserTests/MimeParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,36 @@ class MimeParsingTests: XCTestCase {
}
}

func testCanParsePartWithZeroLengthBody() throws {
let parser = MimeParser()
let message = TestAdditions.testResourceString(withName: "MeetingRequestWithZeroLengthPart", extension: "txt")

// When
let mime = try parser.parse(message)

// Then
XCTAssertEqual(mime.header.contentType?.type, "multipart")
XCTAssertEqual(mime.header.contentType?.subtype, "mixed")
XCTAssertEqual(mime.header.contentType?.raw, "multipart/mixed")
XCTAssertEqual(mime.header.other.count, 12)

if case .mixed(let mimes) = mime.content,
let alternative = mimes.first {
XCTAssertEqual(mimes.count, 1)

if case .mixed(let mimes) = alternative.content {
let first = mimes.first
XCTAssertEqual(first?.header.contentType?.type, "text")
XCTAssertEqual(first?.header.contentType?.subtype, "plain")
XCTAssertEqual(first?.header.contentType?.raw, "text/plain")
XCTAssertEqual(first?.header.contentType?.mimeType, .text)
XCTAssertEqual(first?.header.other.count, 0)
XCTAssertEqual(first?.content, .body(MimeBody("")))
} else {
XCTFail("Unexpected mime content")
}
} else {
XCTFail("Unexpected mime content")
}
}
}
30 changes: 30 additions & 0 deletions Tests/Supporting Files/MeetingRequestWithZeroLengthPart.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From: John Doe <jdoe@fnord.com>
To: F Nnord <fnord@fnord.com>
Received: from MWHPR16MB1535.namprd16.prod.outlook.com
(2603:10b6:301:75::36) by BYAPR16MB2439.namprd16.prod.outlook.com with
HTTPS via MWHPR0201CA0095.NAMPRD02.PROD.OUTLOOK.COM; Tue, 18 Sep 2018
18:07:03 +0000
Content-Transfer-Encoding: binary
Subject: Meeting request
Thread-Topic: Meeting request
Thread-Index: AdRPemY2vb6lpePsIk+sXErWYWzZnw==
Date: Tue, 18 Sep 2018 18:07:02 +0000
Message-Id:
<MWHPR16MB150401D305C7FEBD3C5400B8BF1D0@MWHPR16MB1504.namprd16.prod.outlook.com>
Accept-Language: en-US
Content-Language: en-US
MIME-Version: 1.0
Return-Path: jdoe@fnord.com
Content-Type: multipart/mixed;
boundary="----sinikael-?=_1-15475657792290.9819128808191682"

------sinikael-?=_1-15475657792290.9819128808191682
Content-Type: multipart/related;
boundary="----sinikael-?=_2-15475657792290.9819128808191682"

------sinikael-?=_2-15475657792290.9819128808191682
Content-Type: text/plain

------sinikael-?=_2-15475657792290.9819128808191682--

------sinikael-?=_1-15475657792290.9819128808191682--

0 comments on commit ccaec7b

Please sign in to comment.