Closed Bug 1532528 Opened 6 years ago Closed 5 years ago

Add WebExtensions API to block sending message from a message composition window (mailRequest like webRequest)

Categories

(Thunderbird :: Add-Ons: Extensions API, enhancement, P2)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 74.0

People

(Reporter: yuki, Assigned: darktrojan)

References

Details

Attachments

(1 file, 2 obsolete files)

On company use, addons to block sending of composing messages before send is required, to avoid missending. There are some know major addons for the purpose, for example:

Confirm-Address
https://addons.thunderbird.net/thunderbird/addon/confirm-address-5582/

Flex Confirm Mail
https://addons.thunderbird.net/thunderbird/addon/flex-confirm-mail/

I've looked the list of planned WebExtensions APIs on Thunderbird but I couldn't find out any API to do that, like Firefox's tabs.webRequest.onBeforeRequest.

Local email client is still used on many companies in Japan. "How to avoid missending" is very popular topic, and sometimes it can be the core reason why they use Thunderbird. Thus I propose to add something API to do that on Thunderbird.

API draft:

function tryBlock(header, parts) {
  return new Promise((resolve, reject) => {
    if ([...header.recipients,
         ...header.ccList,
         ...header.bccList].every(recipient => /@mycompanydomain/.test(recipient)))
      return resolve();

    // show custom UI to ask the user like
    // "do you really want to send this mail to these recipients?"
    // with checkboxes
    browser.composeAction.openPopup();

    // the popup content sends a message to notify the result: granted or rejected.
    const listener = (message, sender) => {
      browser.runtime.onMessage.removeListener(listener);
      if (message && message.result == 'granted')
        resolve();
      else
        resolve({ cancel: true });
    };
    browser.runtime.onMessage.addListener(listener);
  });
}
browser.compose.onBeforeSend.addListener(
  tryBlock,
  ["blocking"]
);

How about such an API?

I know that such a blocking type API is very rare and new proposals like that are never been accepted on Firefox's WebExtensions, because Firefox has a policy avoiding performance problem. But I think that Thunderbird looks no need to concentrate at the point.

Blocks: webext-tb
Priority: -- → P2

I think having such an API would be valuable, thanks for filing this bug! We could have a similar model as webRequest indeed with a few events based on the lifecycle of a message, and a blocking flag that would allow async operations.

Note that for Manifest v3, Google is removing blocking webRequest for performance and security reasons. Email is different, but this just something to keep in mind.

Summary: Add WebExtensions API to block sending message from a message composition window → Add WebExtensions API to block sending message from a message composition window (mailRequest like webRequest)

At the moment my add-on Mail Merge listens for the "compose-send-message" event in the Message Compose Window. See: function mailmerge.check() in /content/overlay.js in Mail Merge 6.1.0.

It checks, whether there are multiple recipients in the To field or variables in the To / Cc / Bcc / Reply / Subject / Body fields. Then it asks the user, whether to continue the send process or to cancel the send process and use Mail Merge instead.

Having an API to block sending messages is necessary for Mail Merge to prevent a user from accidentally sending a message to multiple (many!) recipients instead of using Mail Merge - which creates an individual messages for each recipient.

When you develop such an API, please keep Mail Merge and its use-case in mind, thanks!

I am working on this. I have enough to prove that what I want to do works, but not the exact details yet.

As it is you'll be able to listen to an event and cancel the sending outright or change some things† and continue to send. Your event listener can return an answer immediately or a Promise to do so later. Not sure how multiple send attempts will work as yet.

† For now, just the recipients and subject. We've yet to work out how we represent the message body and attachments for this and various other uses.

Assignee: nobody → geoff
Status: NEW → ASSIGNED

Before adding new functions, I wanted to add some tests of the existing browser.compose functions, because there are none.

Attachment #9123763 - Flags: review?(mkmelin+mozilla)

For now, this just has the ability to pause or block sending. I've removed the parts that allow reading and changing fields as it adds too much complexity and there are some issues I have yet to resolve.

Attachment #9123764 - Flags: review?(mkmelin+mozilla)

… and of course, the moment I upload it I find a mistake.

Attachment #9123764 - Attachment is obsolete: true
Attachment #9123764 - Flags: review?(mkmelin+mozilla)
Attachment #9123765 - Flags: review?(mkmelin+mozilla)
See Also: → 1590121
Comment on attachment 9123763 [details] [diff] [review] 1532528-pt0-compose-begin-tests-1.diff Moving this patch to bug 1612480 where it's more relevant.
Attachment #9123763 - Attachment is obsolete: true
Attachment #9123763 - Flags: review?(mkmelin+mozilla)
Attachment #9123765 - Flags: review?(mkmelin+mozilla) → review+

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/f1815f2e593f
Add an API event that can block message sending from the compose window. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 74.0
Blocks: 1613536
Blocks: 1613562
Depends on: 1617022
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: