Skip to content

Commit

Permalink
Merge pull request #7 from WesleyBranton/Version-2.1
Browse files Browse the repository at this point in the history
Version 2.1
  • Loading branch information
WesleyBranton committed Jun 25, 2019
2 parents 388bde6 + e4facf8 commit 55a4dd0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ To develop and test the extension, you need to open the "about:debugging" page i
Further documentation about developing Firefox extensions can be found [here](https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension).

## Release Notes
### Version 2.1
* **[FIXED]** Outlook now opens in a new tab
* **[FIXED]** The Outlook selection screen will not load if you have selected "Don't ask again"
* **[FIXED]** Optimized link generation

### Version 2.0
* **[NEW]** Added support for outlook.office.com
* **[FIXED]** Message prefill data is no longer lost at login page
46 changes: 42 additions & 4 deletions firefox/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function handleIncomplete(tabId, changeInfo, tabInfo) {

// Handle tab that will not lose parameters
function handleComplete(tabId, changeInfo, tabInfo) {
console.log("Running");
removeHandlers();
}

Expand All @@ -28,8 +27,8 @@ function removeHandlers() {
browser.tabs.onUpdated.removeListener(handleComplete);
}

// Message handler
function listenMessage(message) {
// Saves message data if the user needs to login
function saveMessage(message) {
if (message.code == 'create-handler') {
// Create required handlers
browser.tabs.onUpdated.addListener(handleIncomplete, filter);
Expand All @@ -39,9 +38,48 @@ function listenMessage(message) {
}
}

// Opens new tab
async function openTab(requestDetails) {
var params = await getParameters(requestDetails.url);
var base = await getBase();
var link = base + params;
browser.tabs.create({
url:link
});
saveMessage({'code':'create-handler','msg':[link,params]})
return {cancel: true};
}

// Converts Firefox mailto string into standard URL parameters
function getParameters(url) {
var decodedURL, to, formatURL;
decodedURL = decodeURIComponent(url);
decodedURL = decodedURL.slice(decodedURL.indexOf("mailto") + 7);
if (decodedURL.indexOf("?") >= 0) {
to = decodedURL.slice(0,decodedURL.indexOf("?"));
decodedURL = decodedURL.slice(decodedURL.indexOf("?") + 1);
formatURL = "?to=" + to + "&" + decodedURL;
} else {
to = decodedURL;
formatURL = "?to=" + to;
}
return formatURL;
}

// Determines which Outlook service to go to
async function getBase() {
var data = await browser.storage.local.get();
if (data.mode == 'live' || data.mode == 'office') {
return "https://outlook." + data.mode + ".com/mail/deeplink/compose";
} else {
return "/handler/sendmail.html";
}
}

let data = browser.storage.local.get();
data.then(verify);
var tmpUrl;
const filter = {urls:["*://outlook.live.com/mail/deeplink/compose",
"*://outlook.office.com/mail/deeplink/compose"]};
chrome.runtime.onMessage.addListener(listenMessage);
chrome.runtime.onMessage.addListener(saveMessage);
browser.webRequest.onBeforeRequest.addListener(openTab,{urls:["*://outlook.send/*"]},["blocking"]);
19 changes: 2 additions & 17 deletions firefox/handler/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// Converts Firefox mailto string into standard URL parameters
function createURL() {
var decodedURL, to, formatURL;
decodedURL = decodeURIComponent(window.location);
decodedURL = decodedURL.slice(decodedURL.indexOf("mailto") + 7);
if (decodedURL.indexOf("?") >= 0) {
to = decodedURL.slice(0,decodedURL.indexOf("?"));
decodedURL = decodedURL.slice(decodedURL.indexOf("?") + 1);
formatURL = "?to=" + to + "&" + decodedURL;
} else {
to = decodedURL;
formatURL = "?to=" + to;
}
return formatURL;
}

// Load email composition page
function redirect(mode) {
var parameters = createURL();
var parameters = decodeURIComponent(window.location);
parameters = parameters.slice(parameters.indexOf("?to="),parameters.length);
var url = "https://outlook." + mode + ".com/mail/deeplink/compose" + parameters;
if (!wait) {
if (document.getElementById('doNotAsk').checked) {
Expand Down
14 changes: 10 additions & 4 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Outlook.com mailto",
"version": "2.0",
"version": "2.1",
"description": "Add Outlook.com as a default email provider for all mailto links.",
"author": "Wesley Branton",

Expand All @@ -24,19 +24,25 @@
"browser_specific_settings": {
"gecko": {
"id": "outlook@computerwhiz",
"strict_min_version": "54.0"
"strict_min_version": "57.0"
}
},

"protocol_handlers": [{
"protocol": "mailto",
"name": "Outlook.com",
"uriTemplate": "/handler/sendmail.html?to=%s"
"uriTemplate": "https://outlook.send/?to=%s"
}],

"background": {
"scripts": ["background.js"]
},

"permissions": ["storage","tabs"]
"permissions": [
"storage",
"tabs",
"webRequest",
"webRequestBlocking",
"*://outlook.send/*"
]
}

0 comments on commit 55a4dd0

Please sign in to comment.