Commit 1e0e0aa7 authored by Ola Bini's avatar Ola Bini

Add numerous new components with functionality broken out from the

larger modules.

Contribution from Fan Jiang, Iván Pazmiño and Ola Bini.
parent ea2a2c71
/*global Components: false, dump: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
const EXPORTED_SYMBOLS = [ "App" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/AddonManager.jsm"); /*global AddonManager: false */
Cu.import("resource://enigmail/log.jsm"); /*global Log: false */
const DIR_SERV_CONTRACTID = "@mozilla.org/file/directory_service;1";
const ENIG_EXTENSION_GUID = "{847b3a00-7ab1-11d4-8f02-006008948af5}";
const SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}";
const XPCOM_APPINFO = "@mozilla.org/xre/app-info;1";
const App = {
/**
* Platform application name (e.g. Thunderbird)
*/
getName: function() {
return Cc[XPCOM_APPINFO].getService(Ci.nsIXULAppInfo).name;
},
/**
* Return the directory holding the current profile as nsIFile object
*/
getProfileDirectory: function() {
let ds = Cc[DIR_SERV_CONTRACTID].getService(Ci.nsIProperties);
return ds.get("ProfD", Ci.nsIFile);
},
isSuite: function () {
// return true if Seamonkey, false otherwise
return Cc[XPCOM_APPINFO].getService(Ci.nsIXULAppInfo).ID == SEAMONKEY_ID;
},
getVersion: function() {
Log.DEBUG("app.jsm: getVersion\n");
Log.DEBUG("app.jsm: installed version: "+App.version+"\n");
return App.version;
},
getInstallLocation: function() {
return App.installLocation;
},
setVersion: function(version) {
App.version = version;
},
setInstallLocation: function(location) {
App.installLocation = location;
},
registerAddon: function(addon) {
App.setVersion(addon.version);
App.setInstallLocation(addon.getResourceURI("").QueryInterface(Ci.nsIFileURL).file);
},
initAddon: function() {
try {
AddonManager.getAddonByID(ENIG_EXTENSION_GUID, App.registerAddon);
} catch (ex) {
dump("enigmailCommon.jsm: init error: "+ex+"\n");
}
}
};
App.initAddon();
/*global Components: false, Log: false */
/*jshint -W097 */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "MPL"); you may not use this file
* except in compliance with the MPL. You may obtain a copy of
* the MPL at http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the MPL for the specific language governing
* rights and limitations under the MPL.
*
* The Original Code is Enigmail.
*
* The Initial Developer of the Original Code is Patrick Brunschwig.
* Portions created by Patrick Brunschwig <patrick@enigmail.net> are
* Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
*
* Contributor(s):
* Patrick Brunschwig <patrick@enigmail.net>
* Janosch Rux <rux@informatik.uni-luebeck.de>
* Fan Jiang <fanjiang@thoughtworks.com>
* Iván Pazmiño <iapazmino@thoughtworks.com>
* Ola Bini <obini@thoughtworks.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
* ***** END LICENSE BLOCK ***** */
"use strict";
const EXPORTED_SYMBOLS = [ "Armor" ];
Components.utils.import("resource://enigmail/log.jsm");
const Ci = Components.interfaces;
const nsIEnigmail = Ci.nsIEnigmail;
// Locates STRing in TEXT occurring only at the beginning of a line
function indexOfArmorDelimiter(text, str, offset) {
let currentOffset = offset;
while(currentOffset < text.length) {
let loc = text.indexOf(str, currentOffset);
if(loc === -1 || loc === 0 || text.charAt(loc-1) == "\n") {
return loc;
}
currentOffset = loc + str.length;
}
return -1;
}
function searchBlankLine(str, then) {
var offset = str.search(/\n\s*\r?\n/);
if(offset === -1) {
return "";
} else {
return then(offset);
}
}
function indexOfNewline(str, off, then) {
var offset = str.indexOf("\n", off);
if(offset === -1) {
return "";
} else {
return then(offset);
}
}
const Armor = {
// Locates offsets bracketing PGP armored block in text,
// starting from given offset, and returns block type string.
// beginIndex = offset of first character of block
// endIndex = offset of last character of block (newline)
// If block is not found, the null string is returned;
locateArmoredBlock: function (text, offset, indentStr, beginIndexObj, endIndexObj, indentStrObj) {
Log.DEBUG("enigmail.js: Enigmail.locateArmoredBlock: "+offset+", '"+indentStr+"'\n");
beginIndexObj.value = -1;
endIndexObj.value = -1;
var beginIndex = indexOfArmorDelimiter(text, indentStr+"-----BEGIN PGP ", offset);
if (beginIndex == -1) {
var blockStart=text.indexOf("-----BEGIN PGP ");
if (blockStart>=0) {
var indentStart=text.search(/\n.*\-\-\-\-\-BEGIN PGP /)+1;
indentStrObj.value=text.substring(indentStart, blockStart);
indentStr=indentStrObj.value;
beginIndex = indexOfArmorDelimiter(text, indentStr+"-----BEGIN PGP ", offset);
}
}
if (beginIndex == -1)
return "";
// Locate newline at end of armor header
offset = text.indexOf("\n", beginIndex);
if (offset == -1)
return "";
var endIndex = indexOfArmorDelimiter(text, indentStr+"-----END PGP ", offset);
if (endIndex == -1)
return "";
// Locate newline at end of PGP block
endIndex = text.indexOf("\n", endIndex);
if (endIndex == -1) {
// No terminating newline
endIndex = text.length - 1;
}
var blockHeader = text.substr(beginIndex, offset-beginIndex+1);
var blockRegex = new RegExp("^" + indentStr +
"-----BEGIN PGP (.*)-----\\s*\\r?\\n");
var matches = blockHeader.match(blockRegex);
var blockType = "";
if (matches && (matches.length > 1)) {
blockType = matches[1];
Log.DEBUG("enigmail.js: Enigmail.locateArmoredBlock: blockType="+blockType+"\n");
}
if (blockType == "UNVERIFIED MESSAGE") {
// Skip any unverified message block
return Armor.locateArmoredBlock(text, endIndex+1, indentStr, beginIndexObj, endIndexObj, indentStrObj);
}
beginIndexObj.value = beginIndex;
endIndexObj.value = endIndex;
return blockType;
},
/*
* locateArmoredBlocks returns an array with GPGBlock positions
*
* Struct:
* int obj.begin
* int obj.end
* string obj.blocktype
*
*
* @param string text
*
* @return empty array if no block was found
*
*/
locateArmoredBlocks: function(text) {
var beginObj = {};
var endObj = {};
var blocks = [];
var i = 0;
var b;
while (( b = Armor.locateArmoredBlock(text, i, "", beginObj, endObj, {})) !== "") {
blocks.push({
begin: beginObj.value,
end: endObj.value,
blocktype: b
});
i = endObj.value;
}
Log.DEBUG("enigmail.js: locateArmorBlocks: Found " + blocks.length + " Blocks\n");
return blocks;
},
extractSignaturePart: function (signatureBlock, part) {
Log.DEBUG("enigmail.js: Enigmail.extractSignaturePart: part="+part+"\n");
return searchBlankLine(signatureBlock, function(offset) {
return indexOfNewline(signatureBlock, offset+1, function(offset) {
var beginIndex = signatureBlock.indexOf("-----BEGIN PGP SIGNATURE-----", offset+1);
if (beginIndex == -1) {
return "";
}
if (part === nsIEnigmail.SIGNATURE_TEXT) {
return signatureBlock.substr(offset+1, beginIndex-offset-1).
replace(/^- -/, "-").
replace(/\n- -/g, "\n-").
replace(/\r- -/g, "\r-");
}
return indexOfNewline(signatureBlock, beginIndex, function(offset) {
var endIndex = signatureBlock.indexOf("-----END PGP SIGNATURE-----", offset);
if (endIndex == -1) {
return "";
}
var signBlock = signatureBlock.substr(offset, endIndex-offset);
return searchBlankLine(signBlock, function(armorIndex) {
if (part == nsIEnigmail.SIGNATURE_HEADERS) {
return signBlock.substr(1, armorIndex);
}
return indexOfNewline(signBlock, armorIndex+1, function(armorIndex) {
if (part == nsIEnigmail.SIGNATURE_ARMOR) {
return signBlock.substr(armorIndex, endIndex-armorIndex).
replace(/\s*/g, "");
} else {
return "";
}
});
});
});
});
});
},
registerOn: function(target) {
target.locateArmoredBlock = Armor.locateArmoredBlock;
target.locateArmoredBlocks = Armor.locateArmoredBlocks;
target.extractSignaturePart = Armor.extractSignaturePart;
}
};
/*global Components: false, escape: false, unescape: false */
/*jshint -W097 */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "MPL"); you may not use this file
* except in compliance with the MPL. You may obtain a copy of
* the MPL at http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the MPL for the specific language governing
* rights and limitations under the MPL.
*
* The Original Code is Enigmail.
*
* The Initial Developer of the Original Code is Patrick Brunschwig.
* Portions created by Patrick Brunschwig <patrick@enigmail.net> are
* Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
*
* Contributor(s):
* Ramalingam Saravanan <svn@xmlterm.org>
* Fan Jiang <fanjiang@thoughtworks.com>
* Iván Pazmiño <iapazmino@thoughtworks.com>
* Ola Bini <obini@thoughtworks.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
* ***** END LICENSE BLOCK ***** */
"use strict";
const EXPORTED_SYMBOLS = [ "Attachment" ];
const Cu = Components.utils;
Cu.import("resource://enigmail/execution.jsm"); /*global Execution: false */
Cu.import("resource://enigmail/log.jsm"); /*global Log: false */
Cu.import("resource://enigmail/enigmailGpgAgent.jsm"); /*global EnigmailGpgAgent: false */
Cu.import("resource://enigmail/gpg.jsm"); /*global Gpg: false */
Cu.import("resource://enigmail/passwords.jsm"); /*global Passwords: false */
Cu.import("resource://enigmail/data.jsm"); /*global Data: false */
const Attachment = {
getFileName: function (parent, byteData) {
Log.DEBUG("attachment.jsm: getFileName\n");
const args = Gpg.getStandardArgs(true).
concat(Passwords.command()).
concat(["--list-packets"]);
const listener = Execution.newSimpleListener(
function _stdin (pipe) {
Log.DEBUG("attachment.jsm: getFileName: _stdin\n");
pipe.write(byteData);
pipe.write("\n");
pipe.close();
});
const proc = Execution.execStart(EnigmailGpgAgent.agentPath, args, false, parent, listener, {});
if (!proc) {
return null;
}
proc.wait();
const matches = listener.stdoutData.match(/:literal data packet:\r?\n.*name="(.*)",/m);
if (matches && (matches.length > 1)) {
var filename = escape(matches[1]).replace(/%5Cx/g, "%");
return Data.convertToUnicode(unescape(filename), "utf-8");
} else {
return null;
}
}
};
/*global Components: false */
/*jshint -W097 */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "MPL"); you may not use this file
* except in compliance with the MPL. You may obtain a copy of
* the MPL at http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the MPL for the specific language governing
* rights and limitations under the MPL.
*
* The Original Code is Enigmail.
*
* The Initial Developer of the Original Code is Patrick Brunschwig.
* Portions created by Patrick Brunschwig <patrick@enigmail.net> are
* Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
*
* Contributor(s):
* Patrick Brunschwig <patrick@enigmail.net>
* Janosch Rux <rux@informatik.uni-luebeck.de>
* Fan Jiang <fanjiang@thoughtworks.com>
* Iván Pazmiño <iapazmino@thoughtworks.com>
* Ola Bini <obini@thoughtworks.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
* ***** END LICENSE BLOCK ***** */
"use strict";
const EXPORTED_SYMBOLS = [ "Card" ];
const Cu = Components.utils;
Cu.import("resource://enigmail/log.jsm"); /*global Log: false */
Cu.import("resource://enigmail/execution.jsm"); /*global Execution: false */
Cu.import("resource://enigmail/gpg.jsm"); /*global Gpg: false */
const Card = {
getCardStatus: function(exitCodeObj, errorMsgObj) {
Log.DEBUG("enigmail.js: Enigmail.getCardStatus\n");
const args = Gpg.getStandardArgs(false).
concat(["--status-fd", "2", "--fixed-list-mode", "--with-colons", "--card-status"]);
const statusMsgObj = {};
const statusFlagsObj = {};
const outputTxt = Execution.execCmd(Gpg.agentPath, args, "", exitCodeObj, statusFlagsObj, statusMsgObj, errorMsgObj);
if ((exitCodeObj.value === 0) && !outputTxt) {
exitCodeObj.value = -1;
return "";
}
return outputTxt;
}
};
/*global Components: false */
/*jshint -W097 */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "MPL"); you may not use this file
* except in compliance with the MPL. You may obtain a copy of
* the MPL at http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the MPL for the specific language governing
* rights and limitations under the MPL.
*
* The Original Code is Enigmail.
*
* The Initial Developer of the Original Code is Patrick Brunschwig.
* Portions created by Patrick Brunschwig <patrick@enigmail.net> are
* Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
*
* Contributor(s):
* Patrick Brunschwig <patrick@enigmail.net>
* Janosch Rux <rux@informatik.uni-luebeck.de>
* Fan Jiang <fanjiang@thoughtworks.com>
* Iván Pazmiño <iapazmino@thoughtworks.com>
* Ola Bini <obini@thoughtworks.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
* ***** END LICENSE BLOCK ***** */
"use strict";
const EXPORTED_SYMBOLS = [ "CommandLine" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); /*global XPCOMUtils: false */
const NS_ENIGCLINE_SERVICE_CID = Components.ID("{847b3ab1-7ab1-11d4-8f02-006008948af5}");
const NS_CLINE_SERVICE_CONTRACTID = "@mozilla.org/enigmail/cline-handler;1";
const nsICommandLineHandler = Ci.nsICommandLineHandler;
const nsIFactory = Ci.nsIFactory;
const nsISupports = Ci.nsISupports;
function Handler() {}
Handler.prototype = {
classDescription: "Enigmail Key Management CommandLine Service",
classID: NS_ENIGCLINE_SERVICE_CID,
contractID: NS_CLINE_SERVICE_CONTRACTID,
_xpcom_categories: [{
category: "command-line-handler",
entry: "m-cline-enigmail",
service: false
}],
QueryInterface: XPCOMUtils.generateQI([nsICommandLineHandler, nsIFactory, nsISupports]),
// nsICommandLineHandler
handle: function(cmdLine) {
if (cmdLine.handleFlag("pgpkeyman", false)) {
cmdLine.preventDefault = true; // do not open main app window
const wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
wwatch.openWindow(null, "chrome://enigmail/content/enigmailKeyManager.xul", "_blank", "chrome,dialog=no,all", cmdLine);
}
},
helpInfo: " -pgpkeyman Open the OpenPGP key management.\n",
lockFactory: function (lock) {}
};
const CommandLine = {
Handler: Handler
};
This diff is collapsed.
/*global Components: false */
/*jshint -W097 */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "MPL"); you may not use this file
* except in compliance with the MPL. You may obtain a copy of
* the MPL at http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the MPL for the specific language governing
* rights and limitations under the MPL.
*
* The Original Code is Enigmail.
*
* The Initial Developer of the Original Code is Patrick Brunschwig.
* Portions created by Patrick Brunschwig <patrick@enigmail.net> are
* Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
*
* Contributor(s):
* Ramalingam Saravanan <svn@xmlterm.org>
* Fan Jiang <fanjiang@thoughtworks.com>
* Iván Pazmiño <iapazmino@thoughtworks.com>
* Ola Bini <obini@thoughtworks.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
* ***** END LICENSE BLOCK ***** */
"use strict";
const EXPORTED_SYMBOLS = [ "Constants" ];
const Constants = {
POSSIBLE_PGPMIME: -2081,
// possible values for
// - encryptByRule, signByRules, pgpmimeByRules
// - encryptForced, signForced, pgpmimeForced (except CONFLICT)
// NOTE:
// - values 0/1/2 are used with this fixed semantics in the persistent rules
// - see also enigmailEncryptionDlg.xul
ENIG_NEVER: 0,
ENIG_UNDEF: 1,
ENIG_ALWAYS: 2,
ENIG_AUTO_ALWAYS: 22,
ENIG_CONFLICT: 99,
ENIG_FINAL_UNDEF: -1,
ENIG_FINAL_NO: 0,
ENIG_FINAL_YES: 1,
ENIG_FINAL_FORCENO: 10,
ENIG_FINAL_FORCEYES: 11,
ENIG_FINAL_SMIME_DISABLED: 98, // disabled to to preferring S/MIME
ENIG_FINAL_CONFLICT: 99
};
/*global Components: false, Log: false, unescape: false */
/*jshint -W097 */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "MPL"); you may not use this file
* except in compliance with the MPL. You may obtain a copy of
* the MPL at http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the MPL for the specific language governing
* rights and limitations under the MPL.
*
* The Original Code is Enigmail.
*
* The Initial Developer of the Original Code is Patrick Brunschwig.
* Portions created by Patrick Brunschwig <patrick@enigmail.net> are
* Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
*
* Contributor(s):
* Ramalingam Saravanan <svn@xmlterm.org>
* Fan Jiang <fanjiang@thoughtworks.com>
* Iván Pazmiño <iapazmino@thoughtworks.com>
* Ola Bini <obini@thoughtworks.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
* ***** END LICENSE BLOCK ***** */
"use strict";
const EXPORTED_SYMBOLS = [ "Data" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
const SCRIPTABLEUNICODECONVERTER_CONTRACTID = "@mozilla.org/intl/scriptableunicodeconverter";
const HEX_TABLE = "0123456789abcdef";
function converter(charset) {
let unicodeConv = Cc[SCRIPTABLEUNICODECONVERTER_CONTRACTID].getService(Ci.nsIScriptableUnicodeConverter);
unicodeConv.charset = charset || "utf-8";
return unicodeConv;
}
const Data = {
getUnicodeData: function(data) {
// convert output from subprocess to Unicode
var tmpStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
tmpStream.setData(data, data.length);
var inStream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
inStream.init(tmpStream);
return inStream.read(tmpStream.available());
},
extractMessageId: function(uri) {
var messageId = "";
var matches = uri.match(/^enigmail:message\/(.+)/);
if (matches && (matches.length > 1)) {
messageId = matches[1];
}
return messageId;
},
extractMimeMessageId: function(uri) {
var messageId = "";
var matches = uri.match(/^enigmail:mime-message\/(.+)/);
if (matches && (matches.length > 1)) {
messageId = matches[1];
}
return messageId;
},
decodeQuotedPrintable: function(str) {
return unescape(str.replace(/%/g, "=25").replace(/=/g,'%'));
},
convertToUnicode: function (text, charset) {
if (!text || (charset && (charset.toLowerCase() == "iso-8859-1"))) {
return text;
}
// Encode plaintext
try {
return converter(charset).ConvertToUnicode(text);
} catch (ex) {
return text;
}
},
convertFromUnicode: function (text, charset) {
if (!text) {
return "";
}
try {
return converter(charset).ConvertFromUnicode(text);
} catch (ex) {
return text;
}
},
convertGpgToUnicode: function (text) {
if(typeof(text) === "string") {
text = text.replace(/\\x3a/ig, "\\e3A");
var a=text.search(/\\x[0-9a-fA-F]{2}/);
while(a>=0) {
var ch = unescape('%'+text.substr(a+2,2));
var r = new RegExp("\\"+text.substr(a,4));
text=text.replace(r, ch);
a=text.search(/\\x[0-9a-fA-F]{2}/);
}