mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 16:07:03 +03:00
Bugfix Mime parser for decrypted messages
This commit is contained in:
parent
8054e48d4a
commit
33b228a86f
1 changed files with 14 additions and 13 deletions
|
|
@ -23,7 +23,7 @@ export function ParseMime(text)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
header(name) {
|
header(name) {
|
||||||
return this.headers[name];
|
return this.headers?.[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
headerValue(name) {
|
headerValue(name) {
|
||||||
|
|
@ -93,6 +93,7 @@ export function ParseMime(text)
|
||||||
const ParsePart = (mimePart, start_pos = 0, id = '') =>
|
const ParsePart = (mimePart, start_pos = 0, id = '') =>
|
||||||
{
|
{
|
||||||
let part = new MimePart,
|
let part = new MimePart,
|
||||||
|
head = mimePart.match(/^[\s\S]+?\r?\n\r?\n/)?.[0],
|
||||||
headers = {};
|
headers = {};
|
||||||
if (id) {
|
if (id) {
|
||||||
part.id = id;
|
part.id = id;
|
||||||
|
|
@ -102,19 +103,19 @@ export function ParseMime(text)
|
||||||
part.parts = [];
|
part.parts = [];
|
||||||
|
|
||||||
// get headers
|
// get headers
|
||||||
let head = mimePart.match(/^[\s\S]+?\r?\n\r?\n/);
|
|
||||||
if (head) {
|
if (head) {
|
||||||
head = head[0];
|
|
||||||
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 = {};
|
||||||
[...header.matchAll(/;\s*([^;=]+)=\s*"?([^;"]+)"?/g)].forEach(param =>
|
if (match) {
|
||||||
params[param[1].trim().toLowerCase()] = param[2].trim()
|
[...header.matchAll(/;\s*([^;=]+)=\s*"?([^;"]+)"?/g)].forEach(param =>
|
||||||
);
|
params[param[1].trim().toLowerCase()] = param[2].trim()
|
||||||
headers[match[1].trim().toLowerCase()] = {
|
);
|
||||||
value: match[2].trim(),
|
headers[match[1].trim().toLowerCase()] = {
|
||||||
params: params
|
value: match[2].trim(),
|
||||||
};
|
params: params
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// get body
|
// get body
|
||||||
|
|
@ -122,7 +123,7 @@ export function ParseMime(text)
|
||||||
part.bodyEnd = start_pos + mimePart.length;
|
part.bodyEnd = start_pos + mimePart.length;
|
||||||
|
|
||||||
// get child parts
|
// get child parts
|
||||||
let boundary = headers['content-type'].params.boundary;
|
let boundary = headers['content-type']?.params.boundary;
|
||||||
if (boundary) {
|
if (boundary) {
|
||||||
part.boundary = boundary;
|
part.boundary = boundary;
|
||||||
let regex = new RegExp('(?:^|\r?\n)--' + boundary + '(?:--)?(?:\r?\n|$)', 'g'),
|
let regex = new RegExp('(?:^|\r?\n)--' + boundary + '(?:--)?(?:\r?\n|$)', 'g'),
|
||||||
|
|
@ -141,9 +142,9 @@ export function ParseMime(text)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
part.headers = headers;
|
part.headers = headers;
|
||||||
|
}
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue