mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Fix Mime/Parser header detection: Don't render plaintext as Mime parts
This commit is contained in:
parent
ba496919dd
commit
96f63ac1c5
2 changed files with 17 additions and 4 deletions
|
|
@ -76,6 +76,10 @@ export function ParseMime(text)
|
|||
return text.slice(this.start, this.end);
|
||||
}
|
||||
|
||||
get headRaw() {
|
||||
return Object.keys(this.headers || {}).length ? text.slice(this.start, this.bodyStart) : '';
|
||||
}
|
||||
|
||||
get bodyRaw() {
|
||||
return text.slice(this.bodyStart, this.bodyEnd);
|
||||
}
|
||||
|
|
@ -127,6 +131,16 @@ export function ParseMime(text)
|
|||
// mailbox-list or address-list
|
||||
const lists = ['from','reply-to','to','cc','bcc'];
|
||||
|
||||
const isHead = (candidate) =>
|
||||
{
|
||||
// Unfold potential header lines: join lines that start with whitespace with previous line
|
||||
let lines = candidate.replace(/\r?\n([ \t])/g, '$1');
|
||||
lines = lines.split(/\r?\n/).filter(line => line.trim() !== '');
|
||||
const headerLines = lines.filter(line => /^[\w-]+:\s*.+/.test(line));
|
||||
// Heuristic: if more than 50% of lines look like headers, we consider it a header section
|
||||
return (headerLines.length > 0 && headerLines.length / lines.length > 0.5);
|
||||
}
|
||||
|
||||
const ParsePart = (mimePart, start_pos = 0, id = '') =>
|
||||
{
|
||||
let part = new MimePart,
|
||||
|
|
@ -140,7 +154,7 @@ export function ParseMime(text)
|
|||
part.parts = [];
|
||||
|
||||
// get headers
|
||||
if (head) {
|
||||
if (isHead(head)) {
|
||||
head.replace(/\r?\n\s+/g, ' ').split(/\r?\n/).forEach(header => {
|
||||
let match = header.match(/^([^:]+):\s*([^;]+)/),
|
||||
params = {};
|
||||
|
|
@ -191,9 +205,8 @@ export function ParseMime(text)
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
part.headers = headers;
|
||||
}
|
||||
part.headers = headers;
|
||||
|
||||
return part;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { EmailModel } from 'Model/Email';
|
|||
export function MimeToMessage(data, message)
|
||||
{
|
||||
const struct = ParseMime(data);
|
||||
if (struct.headers) {
|
||||
if (struct.headRaw) {
|
||||
let html = struct.getByContentType('text/html'),
|
||||
subject = struct.headerValue('subject');
|
||||
html = html ? html.body : '';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue