Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MIME Normalizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
JS Toolbox
MIME Normalizer
Commits
1c805c09
Commit
1c805c09
authored
4 years ago
by
Igor Markin
Browse files
Options
Downloads
Patches
Plain Diff
Cover "chrome" cases
parent
c83c8c12
No related branches found
No related tags found
1 merge request
!1
Initial
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__tests__/outlookHtml.test.ts
+2
-0
2 additions, 0 deletions
__tests__/outlookHtml.test.ts
src/HTMLNormalizer/strategies/common.ts
+11
-1
11 additions, 1 deletion
src/HTMLNormalizer/strategies/common.ts
src/HTMLNormalizer/strategies/outlook.ts
+26
-9
26 additions, 9 deletions
src/HTMLNormalizer/strategies/outlook.ts
with
39 additions
and
10 deletions
__tests__/outlookHtml.test.ts
+
2
−
0
View file @
1c805c09
...
...
@@ -78,6 +78,8 @@ describe("Outlook emails HTML normalization", () => {
test
(
"
Emails Chrome
"
,
async
()
=>
{
const
normalizedCases
=
await
getNormalizedTestCases
(
"
chrome
"
);
normalizedCases
.
forEach
(([
sent
,
received
])
=>
{
expect
(
received
.
length
).
toBeGreaterThan
(
0
);
expect
(
sent
.
length
).
toBeGreaterThan
(
0
);
expect
(
received
).
toContain
(
sent
);
});
});
...
...
This diff is collapsed.
Click to expand it.
src/HTMLNormalizer/strategies/common.ts
+
11
−
1
View file @
1c805c09
...
...
@@ -31,10 +31,20 @@ export const pruneElement = (element: HTMLElement): boolean => {
return
true
;
}
if
(
element
.
nodeName
.
toLowerCase
()
===
"
div
"
&&
element
.
childNodes
.
length
===
0
)
{
return
true
;
}
return
!!
ELEMENT_TYPES_TO_REMOVE
[
element
.
nodeName
.
toLowerCase
()];
};
export
const
cloneAnchorFromPane
=
(
a
:
HTMLAnchorElement
,
pane
:
HTMLElement
):
void
=>
{
export
const
cloneAnchorFromPane
=
(
a
:
HTMLAnchorElement
,
pane
:
HTMLElement
):
void
=>
{
try
{
const
url
=
new
URL
(
a
.
href
);
// If this is external url
...
...
This diff is collapsed.
Click to expand it.
src/HTMLNormalizer/strategies/outlook.ts
+
26
−
9
View file @
1c805c09
// TODO: Move this logic to amendOutlookNodes
import
{
printHtmlChildren
}
from
"
../HTMLNormalizer
"
;
import
{
ELEMENT_NODE
}
from
"
../../constants
"
;
import
{
ATTRIBUTES_TO_KEEP
,
cloneAnchorFromPane
,
pruneElement
}
from
"
./common
"
;
import
{
printHtmlChildren
}
from
"
../HTMLNormalizer
"
;
import
{
ELEMENT_NODE
}
from
"
../../constants
"
;
import
{
ATTRIBUTES_TO_KEEP
,
cloneAnchorFromPane
,
pruneElement
,
}
from
"
./common
"
;
export
const
printOutlookElement
=
(
node
:
Node
):
string
=>
{
if
(
node
.
nodeType
===
ELEMENT_NODE
)
{
...
...
@@ -25,6 +29,21 @@ export const pruneOutlookElement = (element: HTMLElement): boolean => {
};
export
const
amendOutlookNodes
=
(
document
:
HTMLDocument
):
void
=>
{
/**
* Remove quoted text
*/
const
appendOnSendNode
=
document
.
querySelector
(
"
[id*='appendonsend']
"
)
as
Node
;
if
(
appendOnSendNode
)
{
let
child
=
appendOnSendNode
;
while
(
child
)
{
const
nextSibling
=
child
.
nextSibling
;
child
.
parentNode
.
removeChild
(
child
);
child
=
nextSibling
as
Node
;
}
}
/**
* Get rid of attachments panes
*/
...
...
@@ -45,9 +64,9 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
}
attachmentsPanesContainerEnd
&&
attachmentsPanesContainerEnd
.
parentNode
.
removeChild
(
attachmentsPanesContainerEnd
);
attachmentsPanesContainerEnd
.
parentNode
.
removeChild
(
attachmentsPanesContainerEnd
);
/**
* Unwind spans, because sometimes Outlook wraps everything into span after sending
...
...
@@ -55,9 +74,7 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
const
spans
=
document
.
getElementsByTagName
(
"
span
"
);
/**
* Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
*/
//Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
const
spansDepths
:
{
depth
?:
Array
<
Node
>
}
=
{};
Array
.
from
(
spans
).
forEach
((
span
:
Node
)
=>
{
let
descendant
=
span
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment