Skip to content

Commit

Permalink
Merge pull request #44 from FlexConfirmMail/add-delay-send-param
Browse files Browse the repository at this point in the history
Add support for delay delivery
  • Loading branch information
piroor authored Jan 31, 2025
2 parents e3e33eb + 8f5db1f commit 327951e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 11 deletions.
5 changes: 4 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@
"setting_aboutAddon": "Version",
"setting_resetSetting": "Reset setting",
"setting_saveAndQuit": "Save and Exit",
"setting_cancel": "Cancel"
"setting_cancel": "Cancel",
"setting_configDelayDeliveryTime": "Delay delivery",
"setting_delayDeliveryEnabled": "Enable delay delivery",
"setting_delayDeliverySeconds": "Delay delivery a message by (in seconds)"
}
5 changes: 4 additions & 1 deletion locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@
"setting_aboutAddon": "このアドオンについて",
"setting_resetSetting": "設定をリセットする",
"setting_saveAndQuit": "保存して閉じる",
"setting_cancel": "キャンセル"
"setting_cancel": "キャンセル",
"setting_configDelayDeliveryTime": "遅延送信設定",
"setting_delayDeliveryEnabled": "遅延送信を有効化する",
"setting_delayDeliverySeconds": "送信までの遅延秒数:"
}
5 changes: 4 additions & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
"setting_aboutAddon": "版本",
"setting_resetSetting": "Reset setting",
"setting_saveAndQuit": "保存并退出",
"setting_cancel": "取消"
"setting_cancel": "取消",
"setting_configDelayDeliveryTime": "Delay delivery",
"setting_delayDeliveryEnabled": "Enable delay delivery",
"setting_delayDeliverySeconds": "Delay delivery a message by (in seconds)"
}
45 changes: 44 additions & 1 deletion src/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,38 @@ function getAttachmentsAsync() {
});
}

function getDelayDeliveryTime() {
return new Promise((resolve, reject) => {
try {
Office.context.mailbox.item.delayDeliveryTime.getAsync((asyncResult) => {
const value = asyncResult.value;
resolve(value);
});
} catch (error) {
console.log(`Error while getting DelayDeliveryTime: ${error}`);
reject(error);
}
});
}

function setDelayDeliveryTimeAsync(deliveryTime) {
return new Promise((resolve, reject) => {
try {
Office.context.mailbox.item.delayDeliveryTime.setAsync(deliveryTime, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log(asyncResult.error.message);
resolve(false);
} else {
resolve(true);
}
});
} catch (error) {
console.log(`Error while setting DelayDeliveryTime: ${error}`);
reject(error);
}
});
}

async function getAllData() {
const [to, cc, bcc, attachments, mailId, config] = await Promise.all([
getToAsync(),
Expand Down Expand Up @@ -347,6 +379,17 @@ async function onItemSend(event) {
}

console.debug("granted: continue to send");

if (data.config.common?.DelayDeliveryEnabled) {
const currentSetting = await getDelayDeliveryTime();
if (currentSetting == 0) {
const currentTime = new Date().getTime();
const delayDeliverySeconds = data.config.common?.DelayDeliverySeconds ?? 60;
const delayInMilliseconds = delayDeliverySeconds * 1000;
const deliveryTime = new Date(currentTime + delayInMilliseconds);
await setDelayDeliveryTimeAsync(deliveryTime);
}
}
asyncContext.completed({ allowEvent: true });
}
window.onItemSend = onItemSend;
Expand Down Expand Up @@ -380,7 +423,7 @@ async function onOpenSettingDialog(event) {
url: window.location.origin + "/setting.html",
data,
asyncContext,
height: Math.min(60, charsToPercentage(50, screen.availHeight)),
height: Math.min(80, charsToPercentage(70, screen.availHeight)),
width: Math.min(80, charsToPercentage(70, screen.availWidth)),
});
console.debug(`onOpensettingDialog: ${status}`);
Expand Down
10 changes: 10 additions & 0 deletions src/web/config-loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class ConfigLoader {
SafeNewDomainsEnabled: "boolean",
CountSeconds: "number",
SafeBccThreshold: "number",
DelayDeliveryEnabled: "boolean",
DelayDeliverySeconds: "number",
};

static DICTONARY_LINE_SPLITTER = /^([^=]+)=(.*)$/;
Expand Down Expand Up @@ -166,6 +168,8 @@ export class ConfigLoader {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: false,
DelayDeliverySeconds: 60,
},
trustedDomains: [],
unsafeDomains: [],
Expand Down Expand Up @@ -204,6 +208,12 @@ export class ConfigLoader {
if (right.common.SafeBccThreshold != null) {
left.common.SafeBccThreshold = right.common.SafeBccThreshold;
}
if (right.common.DelayDeliveryEnabled != null) {
left.common.DelayDeliveryEnabled = right.common.DelayDeliveryEnabled;
}
if (right.common.DelayDeliverySeconds != null) {
left.common.DelayDeliverySeconds = right.common.DelayDeliverySeconds;
}
left.trustedDomains = left.trustedDomains.concat(right.trustedDomains);
left.unsafeDomains = left.unsafeDomains.concat(right.unsafeDomains);
left.unsafeFiles = left.unsafeFiles.concat(right.unsafeFiles);
Expand Down
8 changes: 1 addition & 7 deletions src/web/setting.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ fluent-text-area::part(control){
height:100%;
}

#safeBccThreshold {
fluent-number-field {
margin-left: 10px;
margin-right: 10px;
}

#countSeconds {
margin-left: 10px;
margin-right: 10px;
}

/* fluent-tab:hover {
Expand Down
6 changes: 6 additions & 0 deletions src/web/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<fluent-checkbox id="countAllowSkip" data-l10n-text-content="setting_configCountAllowSkip"></fluent-checkbox><br />
<fluent-number-field id="countSeconds" data-l10n-text-content="setting_configCountSeconds"></fluent-number-field>
</fluent-card>
<fluent-card>
<strong data-l10n-text-content="setting_configDelayDeliveryTime"></strong>
<fluent-divider></fluent-divider>
<fluent-checkbox id="delayDeliveryEnabled" data-l10n-text-content="setting_delayDeliveryEnabled"></fluent-checkbox><br />
<fluent-number-field id="delayDeliverySeconds" data-l10n-text-content="setting_delayDeliverySeconds"></fluent-number-field>
</fluent-card>
<fluent-card>
<strong data-l10n-text-content="setting_configWarning"></strong>
<fluent-divider></fluent-divider>
Expand Down
6 changes: 6 additions & 0 deletions src/web/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ function updateDialogSetting(policy, user) {
document.getElementById("safeNewDomainsEnabled").checked = common.SafeNewDomainsEnabled;
document.getElementById("countSeconds").value = common.CountSeconds;
document.getElementById("safeBccThreshold").value = common.SafeBccThreshold;
document.getElementById("delayDeliveryEnabled").checked = common.DelayDeliveryEnabled;
document.getElementById("delayDeliverySeconds").value = common.DelayDeliverySeconds;
}

function sendStatusToParent(status) {
Expand Down Expand Up @@ -128,6 +130,8 @@ function serializeCommonConfigs() {
const safeBccThreshold = document.getElementById("safeBccThreshold").value;
const safeNewDomainsEnabled = document.getElementById("safeNewDomainsEnabled").checked;
const mainSkipIfNoExt = document.getElementById("mainSkipIfNoExt").checked;
const delayDeliveryEnabled = document.getElementById("delayDeliveryEnabled").checked;
const delayDeliverySeconds = document.getElementById("delayDeliverySeconds").value;
let commonConfigString = "";
commonConfigString += serializeCommonConfig("CountEnabled", countEnabled);
commonConfigString += serializeCommonConfig("CountSeconds", countSeconds);
Expand All @@ -136,6 +140,8 @@ function serializeCommonConfigs() {
commonConfigString += serializeCommonConfig("SafeBccThreshold", safeBccThreshold);
commonConfigString += serializeCommonConfig("SafeNewDomainsEnabled", safeNewDomainsEnabled);
commonConfigString += serializeCommonConfig("MainSkipIfNoExt", mainSkipIfNoExt);
commonConfigString += serializeCommonConfig("DelayDeliveryEnabled", delayDeliveryEnabled);
commonConfigString += serializeCommonConfig("DelayDeliverySeconds", delayDeliverySeconds);
return commonConfigString;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test-config-loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ export function test_createDefaultConfig() {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: false,
DelayDeliverySeconds: 60,
},
trustedDomains: [],
unsafeDomains: [],
Expand Down Expand Up @@ -319,6 +321,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: true,
DelayDeliverySeconds: 60,
},
trustedDomains: ["trustedDomain"],
unsafeDomains: ["unsafeDomain"],
Expand All @@ -333,6 +337,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: true,
DelayDeliverySeconds: 60,
},
trustedDomains: ["trustedDomain"],
unsafeDomains: ["unsafeDomain"],
Expand All @@ -349,6 +355,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: true,
DelayDeliverySeconds: 60,
},
trustedDomains: ["trustedDomain"],
unsafeDomains: ["unsafeDomain"],
Expand All @@ -369,6 +377,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: true,
DelayDeliverySeconds: 60,
},
trustedDomains: ["trustedDomain"],
unsafeDomains: ["unsafeDomain"],
Expand All @@ -385,6 +395,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: true,
CountSeconds: 3,
SafeBccThreshold: 4,
DelayDeliveryEnabled: true,
DelayDeliverySeconds: 60,
},
trustedDomains: ["trustedDomain_left"],
unsafeDomains: ["unsafeDomain_left"],
Expand All @@ -399,6 +411,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: false,
CountSeconds: 2,
SafeBccThreshold: 2,
DelayDeliveryEnabled: false,
DelayDeliverySeconds: 10,
},
trustedDomains: ["trustedDomain_right"],
unsafeDomains: ["unsafeDomain_right"],
Expand All @@ -413,6 +427,8 @@ test_merge.parameters = {
SafeNewDomainsEnabled: false,
CountSeconds: 2,
SafeBccThreshold: 2,
DelayDeliveryEnabled: false,
DelayDeliverySeconds: 10,
},
trustedDomains: ["trustedDomain_left", "trustedDomain_right"],
unsafeDomains: ["unsafeDomain_left", "unsafeDomain_right"],
Expand Down

0 comments on commit 327951e

Please sign in to comment.