forked from eykamp/Folder-Account
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nearly complete rewrite using MailExtensions with Experiments
- Loading branch information
Showing
25 changed files
with
898 additions
and
3,527 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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var { ExtensionCommon } = ChromeUtils.importESModule( | ||
"resource://gre/modules/ExtensionCommon.sys.mjs" | ||
); | ||
|
||
var { MailServices } = ChromeUtils.importESModule( | ||
"resource:///modules/MailServices.sys.mjs" | ||
); | ||
|
||
var FolderAccount = class extends ExtensionCommon.ExtensionAPI { | ||
getAPI(context) { | ||
return { | ||
FolderAccount: { | ||
async getDisplayedFolder(tabId) { | ||
return context.extension.folderManager.convert( | ||
context.extension.tabManager.get(tabId).nativeTab.folder | ||
); | ||
}, | ||
async getRelatedMessageFolder(tabId) { | ||
const tabObject = context.extension.tabManager.get(tabId); | ||
const realTabWindow = tabObject.window; | ||
const folder = realTabWindow.gMessenger.msgHdrFromURI( | ||
realTabWindow.gMsgCompose.originalMsgURI | ||
).folder; | ||
return context.extension.folderManager.convert(folder); | ||
}, | ||
async getFolderAccountSettings() { | ||
const folderPrefs = new Map(); | ||
const branch = Services.prefs.getBranch("extensions.folderaccount."); | ||
for (const child of branch.getChildList("")) { | ||
let pref; | ||
try { | ||
pref = branch.getCharPref(child); | ||
} catch (e) { | ||
continue; | ||
} | ||
const matches = child.match( | ||
/(?<setting>addToCcOnReply|overrideReturnAddress|replyTo(OnReplyForward)?|to)?\.?(?<folder>.*)/ | ||
); | ||
const folderURI = matches.groups["folder"]; | ||
const settingKey = matches.groups["setting"] ?? "identityId"; | ||
if (/addToCcOnReply|overrideReturnAddress|replyToOnReplyForward/.test(settingKey)) { | ||
pref = pref == "true"; | ||
} | ||
folderPrefs.set(folderURI, { | ||
...folderPrefs.get(folderURI), | ||
[settingKey]: pref, | ||
}); | ||
} | ||
const mailFolderPrefs = new Map(); | ||
folderPrefs.forEach((value, key) => { | ||
const folder = MailServices.folderLookup.getFolderForURL(key); | ||
const mailFolder = context.extension.folderManager.convert(folder); | ||
if (mailFolder) { | ||
mailFolderPrefs.set(mailFolder.id, value); | ||
} | ||
}); | ||
return mailFolderPrefs; | ||
}, | ||
}, | ||
}; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[ | ||
{ | ||
"namespace": "FolderAccount", | ||
"functions": [ | ||
{ | ||
"name": "getDisplayedFolder", | ||
"description": "Get the currently displayed folder in the tab", | ||
"type": "function", | ||
"async": true, | ||
"parameters": [ | ||
{ | ||
"name": "tabId", | ||
"description": "The last focused tab", | ||
"type": "integer" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "getRelatedMessageFolder", | ||
"description": "Get the folder of the related message of the currently displayed compose window", | ||
"type": "function", | ||
"async": true, | ||
"parameters": [ | ||
{ | ||
"name": "tabId", | ||
"description": "The current compose tab", | ||
"type": "integer" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "getFolderAccountSettings", | ||
"description": "Get all the Folder Account settings from its preference branch for migration.", | ||
"type": "function", | ||
"async": true, | ||
"parameters": [] | ||
} | ||
] | ||
} | ||
] |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## Objective | ||
|
||
Use this API to access Thunderbird's system preferences or to migrate your own preferences from the Thunderbird preference system to the local storage of your MailExtension. | ||
|
||
## Usage | ||
|
||
Add the [LegacyPrefs API](https://github.com/thundernest/addon-developer-support/tree/master/auxiliary-apis/LegacyPrefs) to your add-on. Your `manifest.json` needs an entry like this: | ||
|
||
``` | ||
"experiment_apis": { | ||
"LegacyPrefs": { | ||
"schema": "api/LegacyPrefs/schema.json", | ||
"parent": { | ||
"scopes": ["addon_parent"], | ||
"paths": [["LegacyPrefs"]], | ||
"script": "api/LegacyPrefs/implementation.js" | ||
} | ||
} | ||
}, | ||
``` | ||
|
||
## API Functions | ||
|
||
This API provides the following functions: | ||
|
||
### async getPref(aName, [aFallback]) | ||
|
||
Returns the value for the ``aName`` preference. If it is not defined or has no default value assigned, ``aFallback`` will be returned (which defaults to ``null``). | ||
|
||
### async getUserPref(aName) | ||
|
||
Returns the user defined value for the ``aName`` preference. This will ignore any defined default value and will only return an explicitly set value, which differs from the default. Otherwise it will return ``null``. | ||
|
||
### clearUserPref(aName) | ||
|
||
Clears the user defined value for preference ``aName``. Subsequent calls to ``getUserPref(aName)`` will return ``null``. | ||
|
||
### async setPref(aName, aValue) | ||
|
||
Set the ``aName`` preference to the given value. Will return false and log an error to the console, if the type of ``aValue`` does not match the type of the preference. | ||
|
||
## API Events | ||
|
||
This API provides the following events: | ||
|
||
### onChanged.addListener(listener, branch) | ||
|
||
Register a listener which is notified each time a value in the specified branch is changed. The listener returns the name and the new value of the changed preference. | ||
|
||
Example: | ||
|
||
``` | ||
browser.LegacyPrefs.onChanged.addListener(async (name, value) => { | ||
console.log(`Changed value in "mailnews.": ${name} = ${value}`); | ||
}, "mailnews."); | ||
``` | ||
|
||
--- | ||
|
||
A detailed example using the LegacyPref API to migrate add-on preferences to the local storage can be found in [/scripts/preferences/](https://github.com/thundernest/addon-developer-support/tree/master/scripts/preferences). |
Oops, something went wrong.