Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Web archives and mail are checked for scripts that need shaping too

KnifeLemon07552f558b4d
diff --git a/src/Filee.Engines/Infrastructure/ComplexScripts.cs b/src/Filee.Engines/Infrastructure/ComplexScripts.cs
index 55bfdbd1..d86c07ba 100644
--- a/src/Filee.Engines/Infrastructure/ComplexScripts.cs
+++ b/src/Filee.Engines/Infrastructure/ComplexScripts.cs
@@ -160,12 +160,18 @@ internal static partial class ComplexScripts
{
if (IsZip(path))
return FindInPackage(path, format);
+ // Web archives and mail are MIME: their HTML (or text) part is what reaches the PDF.
+ if (format is "mhtml" or "eml")
+ {
+ var message = MimeKit.MimeMessage.Load(path);
+ return FindInString(message.HtmlBody ?? message.TextBody ?? "");
+ }
return format is "txt" or "md" or "html" or "csv" or "tsv" or "fb2" or "rtf" or "rst" or "tex" or "org" or "adoc"
or "typ" or "mediawiki" or "dbk" or "textile" or "man" or "opml"
? FindInText(path)
: null; // binary formats (HWP, DOC, MOBI, ...): left to the engines
}
- catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or FormatException)
{
return null;
}
@@ -189,7 +195,11 @@ internal static partial class ComplexScripts
bytes = new byte[(int)Math.Min(stream.Length, MaxTextBytes)];
stream.ReadExactly(bytes);
}
- var text = DocumentReaders.DecodeText(bytes);
+ return FindInString(DocumentReaders.DecodeText(bytes));
+ }
+
+ private static string? FindInString(string text)
+ {
if (Find(text) is { } script)
return script;
// અ / અ in HTML and XML, ⚓? in RTF.
diff --git a/tests/Filee.Engines.Tests/ComplexScriptTests.cs b/tests/Filee.Engines.Tests/ComplexScriptTests.cs
index d2296675..76d50695 100644
--- a/tests/Filee.Engines.Tests/ComplexScriptTests.cs
+++ b/tests/Filee.Engines.Tests/ComplexScriptTests.cs
@@ -52,6 +52,13 @@ public class ComplexScriptTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal("Thai", ComplexScripts.FindInFile(Text("thai.rtf", @"{\rtf1 \u3585?\u3634?}"), "rtf"));
Assert.Null(ComplexScripts.FindInFile(Text("plain.md", "# Title\n\nC:\\users\\me and &#169; 2026"), "md"));
Assert.Null(ComplexScripts.FindInFile(Text("binary.hwp", "ignored"), "hwp"));
+
+ // Web archives: the HTML part, quoted-printable here, as Chrome saves it.
+ const string Mhtml = "MIME-Version: 1.0\r\nContent-Type: multipart/related; boundary=\"b\"\r\n\r\n--b\r\n" +
+ "Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" +
+ "<p>=E0=AA=B8=E0=AB=8C=E0=AA=B0=E0=AA=BE</p>\r\n--b--\r\n";
+ Assert.Equal("Gujarati", ComplexScripts.FindInFile(Text("page.mhtml", Mhtml), "mhtml"));
+ Assert.Null(ComplexScripts.FindInFile(Text("plain.mhtml", Mhtml.Replace("=E0=AA=B8=E0=AB=8C=E0=AA=B0=E0=AA=BE", "Hello")), "mhtml"));
}
[Fact]