mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 15:56:10 +08:00
[client-app] allow returning of message from DOM
Summary: SFDC's task to upload an email to salesforce needs the stripped DOM of a Message object to call `innerText`. The API was changed to return a string instead of the DOM. This adds a flag to request the DOM instead of a string. Test Plan: Manually assert `EnsureMessageOnSalesforceTask` properly can add the plain text to the Salesforce Task object Reviewers: halla, mark, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3976
This commit is contained in:
parent
5577d1b4d3
commit
d1b5cb9952
|
@ -381,7 +381,7 @@ Message(date DESC) WHERE draft = 1`,
|
|||
// run an expensive parse once, but use the DOM to load both HTML and
|
||||
// PlainText versions of the body.
|
||||
computeDOMWithoutQuotes() {
|
||||
return QuotedHTMLTransformer.removeQuotedHTML(this.body);
|
||||
return QuotedHTMLTransformer.removeQuotedHTML(this.body, {asDOM: true});
|
||||
}
|
||||
|
||||
fromContact() {
|
||||
|
|
|
@ -43,9 +43,10 @@ class QuotedHTMLTransformer {
|
|||
removeQuotedHTML(html, options = {keepIfWholeBodyIsQuote: true}) {
|
||||
const doc = this._parseHTML(html);
|
||||
const quoteElements = this._findQuoteLikeElements(doc, options);
|
||||
const asDOM = !!options.asDOM
|
||||
|
||||
if (options.keepIfWholeBodyIsQuote && this._wholeBodyIsQuote(doc, quoteElements)) {
|
||||
return this._outputHTMLFor(this._parseHTML(html), {initialHTML: html});
|
||||
return this._outputHTMLFor(this._parseHTML(html), {initialHTML: html, asDOM});
|
||||
}
|
||||
|
||||
DOMUtils.Mutating.removeElements(quoteElements, options);
|
||||
|
@ -53,20 +54,20 @@ class QuotedHTMLTransformer {
|
|||
// It's possible that the entire body was quoted text anyway and we've
|
||||
// removed everything.
|
||||
if (options.keepIfWholeBodyIsQuote && (!doc.body || !doc.children[0])) {
|
||||
return this._outputHTMLFor(this._parseHTML(html), {initialHTML: html});
|
||||
return this._outputHTMLFor(this._parseHTML(html), {initialHTML: html, asDOM});
|
||||
}
|
||||
|
||||
if (!doc.body) {
|
||||
return this._outputHTMLFor(this._parseHTML(""), {initialHTML: html});
|
||||
return this._outputHTMLFor(this._parseHTML(""), {initialHTML: html, asDOM});
|
||||
}
|
||||
|
||||
this.removeTrailingBr(doc);
|
||||
DOMUtils.Mutating.removeElements(quoteStringDetector(doc));
|
||||
if (options.keepIfWholeBodyIsQuote && (!doc.children[0] || this._wholeNylasPlaintextBodyIsQuote(doc))) {
|
||||
return this._outputHTMLFor(this._parseHTML(html), {initialHTML: html});
|
||||
return this._outputHTMLFor(this._parseHTML(html), {initialHTML: html, asDOM});
|
||||
}
|
||||
|
||||
return this._outputHTMLFor(doc, {initialHTML: html});
|
||||
return this._outputHTMLFor(doc, {initialHTML: html, asDOM});
|
||||
}
|
||||
|
||||
// Finds any trailing BR tags and removes them in place
|
||||
|
@ -119,7 +120,8 @@ class QuotedHTMLTransformer {
|
|||
return doc;
|
||||
}
|
||||
|
||||
_outputHTMLFor(doc, {initialHTML}) {
|
||||
_outputHTMLFor(doc, {initialHTML, asDOM} = {}) {
|
||||
if (asDOM) return doc
|
||||
if (/<\s?head\s?>/i.test(initialHTML) || /<\s?body[\s>]/i.test(initialHTML)) {
|
||||
return doc.children[0].innerHTML;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue