Revision control
Copy as Markdown
Other Tools
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
*/
export var EnigmailURIs = {
/**
* Determine message number and folder from mailnews URI.
*
* @param {nsIURI} url - nsIURI of the message.
* @returns {?object} obj
* @returns {string} obj.msgNum - The message number, or "" if no URI scheme fits.
* @returns {string} obj.folder - The folder (or newsgroup) name.
*/
msgIdentificationFromUrl(url) {
// sample URLs in Thunderbird
if (!url) {
return null;
}
let msgNum = "";
let msgFolder = "";
const pathQueryRef = "path" in url ? url.path : url.pathQueryRef;
if (url.schemeIs("mailbox")) {
msgNum = pathQueryRef.replace(/(.*[?&]number=)([0-9]+)([^0-9].*)?/, "$2");
msgFolder = pathQueryRef.replace(/\?.*/, "");
} else if (url.schemeIs("file")) {
msgNum = "0";
msgFolder = pathQueryRef.replace(/\?.*/, "");
} else if (url.schemeIs("imap")) {
const p = unescape(pathQueryRef);
msgNum = p.replace(/(.*>)([0-9]+)([^0-9].*)?/, "$2");
msgFolder = p.replace(/\?.*$/, "").replace(/>[^>]+$/, "");
} else if (url.schemeIs("news")) {
msgNum = pathQueryRef.replace(/(.*[?&]key=)([0-9]+)([^0-9].*)?/, "$2");
msgFolder = pathQueryRef.replace(/(.*[?&]group=)([^&]+)(&.*)?/, "$2");
}
return {
msgNum,
folder: msgFolder.toLowerCase(),
};
},
};