mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Merge 96f63ac1c5 into c154d23cfe
This commit is contained in:
commit
77d089bffe
2 changed files with 17 additions and 4 deletions
|
|
@ -76,6 +76,10 @@ export function ParseMime(text)
|
||||||
return text.slice(this.start, this.end);
|
return text.slice(this.start, this.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get headRaw() {
|
||||||
|
return Object.keys(this.headers || {}).length ? text.slice(this.start, this.bodyStart) : '';
|
||||||
|
}
|
||||||
|
|
||||||
get bodyRaw() {
|
get bodyRaw() {
|
||||||
return text.slice(this.bodyStart, this.bodyEnd);
|
return text.slice(this.bodyStart, this.bodyEnd);
|
||||||
}
|
}
|
||||||
|
|
@ -127,6 +131,16 @@ export function ParseMime(text)
|
||||||
// mailbox-list or address-list
|
// mailbox-list or address-list
|
||||||
const lists = ['from','reply-to','to','cc','bcc'];
|
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 = '') =>
|
const ParsePart = (mimePart, start_pos = 0, id = '') =>
|
||||||
{
|
{
|
||||||
let part = new MimePart,
|
let part = new MimePart,
|
||||||
|
|
@ -140,7 +154,7 @@ export function ParseMime(text)
|
||||||
part.parts = [];
|
part.parts = [];
|
||||||
|
|
||||||
// get headers
|
// get headers
|
||||||
if (head) {
|
if (isHead(head)) {
|
||||||
head.replace(/\r?\n\s+/g, ' ').split(/\r?\n/).forEach(header => {
|
head.replace(/\r?\n\s+/g, ' ').split(/\r?\n/).forEach(header => {
|
||||||
let match = header.match(/^([^:]+):\s*([^;]+)/),
|
let match = header.match(/^([^:]+):\s*([^;]+)/),
|
||||||
params = {};
|
params = {};
|
||||||
|
|
@ -191,9 +205,8 @@ export function ParseMime(text)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
part.headers = headers;
|
|
||||||
}
|
}
|
||||||
|
part.headers = headers;
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { EmailModel } from 'Model/Email';
|
||||||
export function MimeToMessage(data, message)
|
export function MimeToMessage(data, message)
|
||||||
{
|
{
|
||||||
const struct = ParseMime(data);
|
const struct = ParseMime(data);
|
||||||
if (struct.headers) {
|
if (struct.headRaw) {
|
||||||
let html = struct.getByContentType('text/html'),
|
let html = struct.getByContentType('text/html'),
|
||||||
subject = struct.headerValue('subject');
|
subject = struct.headerValue('subject');
|
||||||
html = html ? html.body : '';
|
html = html ? html.body : '';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue