-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e496e46
commit 6e3490e
Showing
2 changed files
with
8 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" type="application/javascript" crossorigin="anonymous"></script> | ||
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> | ||
<script src="dialog.js" type="application/javascript"></script> | ||
<script src="recipient-parser.mjs" type="module"></script> | ||
<script src="recipient-classifier.mjs" type="module"></script> | ||
<script src="dialog.js" type="module"></script> | ||
<link href="dialog.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,4 @@ | ||
function parse(recipient) { | ||
const address = /<([^@]+@[^>]+)>\s*$/.test(recipient) ? RegExp.$1 : recipient; | ||
const domain = address.split("@")[1].toLowerCase(); | ||
return { | ||
recipient, | ||
address, | ||
domain, | ||
}; | ||
} | ||
|
||
class RecipientClassifier { | ||
constructor({ internalDomains } = {}) { | ||
const uniquePatterns = new Set( | ||
(internalDomains || []) | ||
.filter((pattern) => !pattern.startsWith("#")) // reject commented out items | ||
.map( | ||
(pattern) => | ||
pattern | ||
.toLowerCase() | ||
.replace(/^(-?)@/, "$1") // delete needless "@" from domain only patterns: "@example.com" => "example.com" | ||
.replace(/^(-?)(?![^@]+@)/, "$1*@") // normalize to full address patterns: "[email protected]" => "[email protected]", "example.com" => "*@example.com" | ||
) | ||
); | ||
const negativeItems = new Set( | ||
[...uniquePatterns].filter((pattern) => pattern.startsWith("-")).map((pattern) => pattern.replace(/^-/, "")) | ||
); | ||
for (const negativeItem of negativeItems) { | ||
uniquePatterns.delete(negativeItem); | ||
uniquePatterns.delete(`-${negativeItem}`); | ||
} | ||
this.$internalPatternsMatcher = new RegExp( | ||
`^(${[...uniquePatterns].map((pattern) => this.$toRegExpSource(pattern)).join("|")})$`, | ||
"i" | ||
); | ||
this.classify = this.classify.bind(this); | ||
} | ||
|
||
$toRegExpSource(source) { | ||
// https://stackoverflow.com/questions/6300183/sanitize-string-of-regex-characters-before-regexp-build | ||
const sanitized = source.replace(/[#-.]|[[-^]|[?|{}]/g, "\\$&"); | ||
|
||
const wildcardAccepted = sanitized.replace(/\\\*/g, ".*").replace(/\\\?/g, "."); | ||
|
||
return wildcardAccepted; | ||
} | ||
|
||
classify(recipients) { | ||
const internals = new Set(); | ||
const externals = new Set(); | ||
|
||
for (const recipient of recipients) { | ||
const classifiedRecipient = { | ||
...parse(recipient), | ||
}; | ||
const address = classifiedRecipient.address; | ||
if (this.$internalPatternsMatcher.test(address)) internals.add(classifiedRecipient); | ||
else externals.add(classifiedRecipient); | ||
} | ||
|
||
return { | ||
internals: Array.from(internals), | ||
externals: Array.from(externals), | ||
}; | ||
} | ||
} | ||
import { RecipientClassifier } from "./recipient-classifier.mjs"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
Office.initialize = function (reason) {}; | ||
|
@@ -84,7 +20,7 @@ function sendStatusToParent(status) { | |
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function onCheckAllTrusted() { | ||
window.onCheckAllTrusted = () => { | ||
const checkTargetLength = $("fluent-checkbox.check-target").length; | ||
const checkedTargetLength = $("fluent-checkbox.check-target.checked").length; | ||
const toBeCheckedNumber = $("#trusted-domains fluent-checkbox.check-target").not(".checked").length; | ||
|
@@ -94,17 +30,17 @@ function onCheckAllTrusted() { | |
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function onOk() { | ||
window.onOk = () => { | ||
sendStatusToParent("ok"); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function onCancel() { | ||
window.onCancel = () => { | ||
sendStatusToParent("cancel"); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function checkboxChanged(target_element) { | ||
window.checkboxChanged = (target_element) => { | ||
const checkTargetLength = $("fluent-checkbox.check-target").length; | ||
const checkedTargetLength = $("fluent-checkbox.check-target.checked").length; | ||
// If the target is currently checked, the target is unchecked after this function and vice versa. | ||
|