Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIKA-4249 -- allow utf8 bom in rfc822 #1739

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7035,6 +7035,7 @@
<magic priority="45">
<!-- be a bit more flexible, but require one from each of these -->
<match minShouldMatch="2">

<match minShouldMatch="1">
<match value="Content-ID:" type="stringignorecase" offset="0"/>
<match value="Content-Location:" type="stringignorecase" offset="0"/>
Expand All @@ -7055,6 +7056,27 @@
<match value="User-Agent:" type="string" offset="0"/>
<match value="X-Mailer:" type="string" offset="0"/>
<match value="X-Originating-IP:" type="stringignorecase" offset="0"/>
<match value="0xefbbbf" type="string" offset="0">
<match value="Content-ID:" type="stringignorecase" offset="3"/>
<match value="Content-Location:" type="stringignorecase" offset="3"/>
<match value="Content-Transfer-Encoding:" type="stringignorecase" offset="3"/>
<match value="Content-Type:" type="stringignorecase" offset="3"/>
<match value="Date:" type="stringignorecase" offset="3"/>
<match value="Delivered-To:" type="string" offset="3"/>
<match value="From:" type="stringignorecase" offset="3"/>
<match value="Message-ID:" type="stringignorecase" offset="3"/>
<match value="MIME-Version:" type="stringignorecase" offset="3"/>
<match value="Received:" type="stringignorecase" offset="3"/>
<match value="Relay-Version:" type="stringignorecase" offset="3"/>
<match value="Return-Path:" type="stringignorecase" offset="3"/>
<match value="Sent:" type="string" offset="3"/>
<match value="Status:" type="string" offset="3"/>
<match value="Subject:" type="string" offset="3"/>
<match value="To:" type="string" offset="3"/>
<match value="User-Agent:" type="string" offset="3"/>
<match value="X-Mailer:" type="string" offset="3"/>
<match value="X-Originating-IP:" type="stringignorecase" offset="3"/>
</match>
</match>
<match minShouldMatch="1">
<match value="\nContent-ID:" type="stringignorecase" offset="0:1024"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.InputStream;
import java.net.URL;

import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -109,6 +111,27 @@ public void testByteOrderMark() throws Exception {
.detect(new ByteArrayInputStream("\ufefftest".getBytes(UTF_8)), new Metadata()));
}

@Test
public void testRFC822WithBOM() throws Exception {
String header = "From: blah <blah@blah.com>\r\n" + "Received: Friday, January 24, 2020 3:24 PM\r\n" +
"To: someone@somewhere.com\r\n" + "Cc: someone-else@other.com\r\n" +
"Subject: Received\r\n";
MediaType rfc822 = MediaType.parse("message/rfc822");
assertEquals(rfc822, MIME_TYPES.detect(UnsynchronizedByteArrayInputStream
.builder()
.setByteArray(header.getBytes(UTF_8))
.get(), new Metadata()));

int utfLength = ByteOrderMark.UTF_8.length();
byte[] bytes = new byte[header.getBytes(UTF_8).length + utfLength];
System.arraycopy(ByteOrderMark.UTF_8.getBytes(), 0, bytes, 0, utfLength);
System.arraycopy(header.getBytes(UTF_8), 0, bytes, 3, header.getBytes(UTF_8).length);
assertEquals(rfc822, MIME_TYPES.detect(UnsynchronizedByteArrayInputStream
.builder()
.setByteArray(bytes)
.get(), new Metadata()));
}

@Test
public void testSuperTypes() {
assertTrue(REGISTRY.isSpecializationOf(MediaType.parse("text/something; charset=UTF-8"),
Expand Down