feat(conversion): refactor EML parser to use Simple Java Mail library and add MSG support (#5427)

# Description of Changes


Note on Simple Java Mail:
- SJM contains Angus/Jakarta Mail in it.
- SJM is a very thin layer on Angus Mail; see here:
https://github.com/bbottema/simple-java-mail
- SJM gives high level methods to more reliably parse in email via Angus
Mail, but also contains lots of other interesting features.
- SJM is Apache 2 licensed

This pull request updates the email processing utilities to add support
for parsing and validating Outlook MSG files, refactors the
`EmlProcessingUtils` utility class to use instance methods and improved
resource management, and enhances the handling and styling of generated
email HTML. The changes also introduce external CSS resource loading
with a fallback mechanism, and update dependencies to support MSG file
parsing.

**MSG file support and validation:**
- Added `simple-java-mail` and `outlook-module` dependencies to enable
EML and MSG file parsing, and updated validation logic to recognize and
accept MSG files by checking their magic bytes.
(`app/common/build.gradle`, `EmlProcessingUtils.java`)
**Refactoring and modernization of `EmlProcessingUtils`:**
- Converted static methods and fields in `EmlProcessingUtils` to
instance methods/fields, improving testability and future extensibility.
(`EmlProcessingUtils.java`)

**Enhanced HTML/CSS styling for email rendering:**
- Updated HTML generation to use consistent formatting and improved
style variable usage, and refactored CSS injection to load from an
external resource (`email-pdf-styles.css`) with a synchronized cache and
a minimal fallback if the resource is missing.
(`EmlProcessingUtils.java`)
**Attachment and content rendering improvements:**
- Improved the formatting of meta-information (e.g., CC, BCC, Date) and
attachment sections in generated email HTML, and ensured more robust
handling of empty or missing content. (`EmlProcessingUtils.java`)

**General code cleanup and logging:**
- Added SLF4J logging for error handling when loading CSS resources, and
cleaned up imports and method signatures for clarity and
maintainability. (`EmlProcessingUtils.java`)


<img width="367" height="991" alt="image"
src="https://github.com/user-attachments/assets/0cfb959c-da92-4cff-9e52-ff4ab7fa806e"
/>


<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [X] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [X] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [X] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [X] I have performed a self-review of my own code
- [X] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [X] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Signed-off-by: Balázs Szücs <[email protected]>
This commit is contained in:
Balázs Szücs
2026-01-13 21:17:40 +00:00
committed by GitHub
parent daf27b6128
commit 84ed1d7ecb
12 changed files with 764 additions and 779 deletions
@@ -0,0 +1,233 @@
*, *::before, *::after {
box-sizing: border-box;
}
html {
-webkit-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
body {
font-family: var(--font-family, 'Helvetica, sans-serif');
font-size: var(--font-size, 12px);
line-height: var(--line-height, 1.4);
color: var(--text-color, #202124);
margin: 0;
padding: 20px 24px;
background-color: var(--bg-color, #ffffff);
word-wrap: break-word;
overflow-wrap: break-word;
hyphens: auto;
}
.email-container {
width: 100%;
max-width: 100%;
margin: 0 auto;
}
.email-header {
padding-bottom: 16px;
border-bottom: 2px solid var(--border-color, #e8eaed);
margin-bottom: 20px;
}
.email-header h1 {
margin: 0 0 12px 0;
font-size: var(--header-font-size, 18px);
font-weight: 600;
color: #1a1a1a;
line-height: 1.3;
word-break: break-word;
}
.email-meta {
font-size: var(--meta-font-size, 12px);
color: #5f6368;
}
.email-meta div {
margin-bottom: 4px;
line-height: 1.5;
}
.email-meta strong {
color: #3c4043;
font-weight: 600;
min-width: 50px;
display: inline-block;
}
.email-body {
word-wrap: break-word;
overflow-wrap: break-word;
line-height: 1.6;
}
.email-body p {
margin: 0 0 1em 0;
}
.email-body a {
color: #1a73e8;
text-decoration: underline;
}
.email-body table {
border-collapse: collapse;
width: auto;
max-width: 100%;
margin: 8px 0;
}
.email-body td,
.email-body th {
padding: 8px 12px;
vertical-align: top;
border: 1px solid #e0e0e0;
}
.email-body ul,
.email-body ol {
margin: 0.5em 0;
padding-left: 2em;
}
.email-body li {
margin-bottom: 0.25em;
}
.email-body blockquote {
margin: 1em 0;
padding: 0 0 0 16px;
border-left: 3px solid #dadce0;
color: #5f6368;
}
.email-body pre,
.email-body code {
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 0.9em;
background-color: #f8f9fa;
border-radius: 3px;
}
.email-body pre {
padding: 12px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
.email-body code {
padding: 2px 6px;
}
.email-body hr {
border: none;
border-top: 1px solid #e0e0e0;
margin: 1.5em 0;
}
.attachment-section {
margin-top: 24px;
padding: 16px;
background-color: var(--attachment-bg, #f9f9f9);
border: 1px solid var(--attachment-border, #eeeeee);
border-radius: 6px;
page-break-inside: avoid;
}
.attachment-section h3 {
margin: 0 0 12px 0;
font-size: var(--attachment-header-size, 14px);
font-weight: 600;
color: #3c4043;
}
.attachment-item {
padding: 8px 0;
border-bottom: 1px solid #eeeeee;
display: flex;
align-items: center;
flex-wrap: wrap;
}
.attachment-item:last-child {
border-bottom: none;
}
.attachment-icon {
margin-right: 8px;
font-weight: bold;
color: #5f6368;
}
.attachment-name {
font-weight: 500;
color: #1a1a1a;
word-break: break-all;
}
.attachment-details,
.attachment-type {
font-size: var(--attachment-detail-size, 11px);
color: #5f6368;
margin-left: 8px;
}
.attachment-info-note {
margin-top: 12px;
padding: 10px 12px;
font-size: var(--note-font-size, 11px);
border-radius: 4px;
background-color: #e8f0fe;
border: 1px solid #d2e3fc;
color: #1967d2;
}
.attachment-info-note p {
margin: 0;
}
.no-content {
padding: 32px 20px;
text-align: center;
color: #80868b;
font-style: italic;
background-color: #f8f9fa;
border-radius: 6px;
}
.text-body {
white-space: pre-wrap;
word-wrap: break-word;
font-family: inherit;
line-height: 1.6;
}
img {
max-width: 100%;
height: auto;
display: block;
margin: 8px 0;
}
@media print {
body {
padding: 0;
font-size: 11pt;
}
.email-header {
page-break-after: avoid;
}
.attachment-section {
page-break-inside: avoid;
}
a {
text-decoration: none;
color: inherit;
}
}
.email-body div[class*="signature"],
.email-body table[class*="signature"] {
margin-top: 1.5em;
padding-top: 1em;
border-top: 1px solid #e0e0e0;
font-size: 0.95em;
color: #5f6368;
}