--- /dev/null
+/* ***** BEGIN LICENSE BLOCK *****\r
+ * Copyright (c) 2008-2009 EADS DEFENCE AND SECURITY - All rights reserved.\r
+ * ximfmail is under the triple license MPL 1.1/GPL 2.0/LGPL 2.1.\r
+ *\r
+ *\r
+ * Redistribution and use, in source and binary forms, with or without modification,\r
+ * are permitted provided that the following conditons are met :\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright notice,\r
+ * 2. MPL 1.1/GPL 2.0/LGPL 2.1. license agreements must be attached\r
+ * in the redistribution of the source code.\r
+ * 3. Neither the names of the copyright holders nor the names of any contributors\r
+ * may be used to endorse or promote products derived from this software without specific\r
+ * prior written permission from EADS Defence and Security.\r
+ *\r
+ * Alternatively, the contents of this file may be used under the terms of\r
+ * either of the GNU General Public License Version 2 or later (the "GPL"),\r
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),\r
+ * in which case the provisions of the GPL or the LGPL are applicable instead\r
+ * of those above. If you wish to allow use of your version of this file only\r
+ * under the terms of either the GPL or the LGPL, and not to allow others to\r
+ * use your version of this file under the terms of the MPL, indicate your\r
+ * decision by deleting the provisions above and replace them with the notice\r
+ * and other provisions required by the GPL or the LGPL. If you do not delete\r
+ * the provisions above, a recipient may use your version of this file under\r
+ * the terms of any one of the MPL, the GPL or the LGPL.\r
+ *\r
+ * REMINDER :\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * EADS Defence and Security - 1 Boulevard Jean Moulin -\r
+ * ZAC de la Clef Saint Pierre - 78990 Elancourt - FRANCE (IDDN.FR.001.480012.002.S.P.2008.000.10000)\r
+ * ***** END LICENSE BLOCK ***** */\r
+gConsole.logStringMessage("[ximfmail] messengerCompose-ov-ximfmail.js file loaded ");\r
+var gCurrentInstance = "";\r
+var gcounterStarter = 1;\r
+/**\r
+ * mail:composeOnSend observer\r
+ * Add XIMF Headers to MIME message\r
+ */\r
+var XimfMsgSend = XimfMsgSend || {};\r
+XimfMsgSend = {\r
+ observe: function(subject, topic, data) {\r
+ if (!gCurrentIdentity) {\r
+ return;\r
+ }\r
+ try {\r
+ var msgCompFields = gMsgCompose.compFields;\r
+ var charSet = null;\r
+ charSet = msgCompFields.characterSet;\r
+ if(!charSet){\r
+ charSet === msgCompFields.defaultCharacterSet;\r
+ }\r
+ var currCompfieldsotherHeaders = msgCompFields.otherRandomHeaders;\r
+ // add headers of ximf instance\r
+ var addCompfieldsotherHeaders = "";\r
+ var ximfCatalog = XimfCatalog.getInstance();\r
+ if (ximfCatalog) {\r
+ var ximfName = ximfConst.DEFAULT_XIMF_NAME;\r
+ ximfName = ximfCatalog.getNameInstance(gXimfHdrs.getXimfInstanceResource());\r
+ try {\r
+ if (ximfName.toLowerCase() === ximfConst.SMTP_INSTANCE_KEY) {\r
+ // FT INT_FT3970\r
+ gConsole.logStringMessage("[ximfmail - ximfmailOnSend ] Send non XIMF message - instance " + ximfName);\r
+ } else {\r
+ addCompfieldsotherHeaders += EncodeMimeXimfheader(ximfConst.XIMF_NAME_HEADER, ximfName, charSet) + ximfConst.XIMF_ENDLINE;\r
+ // insert XIMF-Version - B4521\r
+ var ximfVersion = ximfConst.DEFAULT_XIMF_VERSION;\r
+ ximfVersion = ximfCatalog.getVersionInstance(gXimfHdrs.getXimfInstanceResource());\r
+ addCompfieldsotherHeaders += EncodeMimeXimfheader(ximfConst.XIMF_VERSION_HEADER, ximfVersion, charSet) + ximfConst.XIMF_ENDLINE;\r
+ // insert extended headers in sending message\r
+ var headersToSend = ReadMimeHeadersSelection(ximfConst.XIMF_ENDLINE, charSet);\r
+ if (headersToSend) {\r
+ addCompfieldsotherHeaders += headersToSend;\r
+ gConsole.logStringMessage("[XimfMsgSend] Ximf header added to send message!");\r
+ }\r
+ }\r
+ } catch(ex) {\r
+ gConsole.logStringMessage("[XimfMsgSend]Exception : " + ex + "\nfile : " + Error().fileName + "\nline : " + Error().lineNumber);\r
+ }\r
+ }\r
+ // apply xsmtp rules instances\r
+ if (gCurrentIdentity.getBoolAttribute("ximfmail_xsmtp_compatibility_on")) {\r
+ var xsmtpHeadersToSend = ReadXsmptHeadersTranslation(ximfConst.XIMF_SEPARATOR_HEADER, ximfConst.XIMF_ENDLINE,charSet);\r
+ if (xsmtpHeadersToSend) {\r
+ addCompfieldsotherHeaders += xsmtpHeadersToSend;\r
+ gConsole.logStringMessage("[XimfMsgSend]XSMTP compatibility process");\r
+ }\r
+ }\r
+ // add ximf headers 1 time - copy last XIMF entries\r
+ if (currCompfieldsotherHeaders.length <= 0 ) {\r
+ msgCompFields.otherRandomHeaders = addCompfieldsotherHeaders;\r
+ } else {\r
+ var regCRLF = new RegExp(ximfConst.XIMF_ENDLINE, "g");\r
+ var arrayAddCompfieldsotherHeaders = addCompfieldsotherHeaders.split(regCRLF);\r
+ var arrayCurrCompfieldsotherHeaders = currCompfieldsotherHeaders.split(regCRLF);\r
+ for (var i=0; i < arrayAddCompfieldsotherHeaders.length; ++i) {\r
+ var tmpAdd = arrayAddCompfieldsotherHeaders[i].slice(0,arrayAddCompfieldsotherHeaders[i].indexOf(":",0));\r
+ if (tmpAdd !=="") {\r
+ for (j=0 ; j<arrayCurrCompfieldsotherHeaders.length ; ++j) {\r
+ var tmpCurr = arrayCurrCompfieldsotherHeaders[j].slice(0,arrayCurrCompfieldsotherHeaders[j].indexOf(":",0));\r
+ if (tmpCurr !== "" && tmpCurr === tmpAdd) {\r
+ arrayCurrCompfieldsotherHeaders[j] = arrayAddCompfieldsotherHeaders[i];\r
+ arrayAddCompfieldsotherHeaders[i] = "";\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ //update new selection\r
+ var arrayAddCompfieldsotherHeaders2 = new Array();\r
+ for (var i=0 ; i<arrayAddCompfieldsotherHeaders.length ; ++i) {;\r
+ if (arrayAddCompfieldsotherHeaders[i]!== "") {\r
+ arrayAddCompfieldsotherHeaders2.push(arrayAddCompfieldsotherHeaders[i]);\r
+ }\r
+ }\r
+ // insert header\r
+ msgCompFields.otherRandomHeaders = arrayCurrCompfieldsotherHeaders.join(ximfConst.XIMF_ENDLINE);\r
+ if (arrayAddCompfieldsotherHeaders2.length>0) {\r
+ msgCompFields.otherRandomHeaders += arrayAddCompfieldsotherHeaders2.join(ximfConst.XIMF_ENDLINE);\r
+ }\r
+ }\r
+ // append Security labels\r
+ AppendESSSecuityLabel();\r
+ }catch(e){\r
+ gConsole.logStringMessage("[XimfMsgSend] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+ }\r
+};\r
+/**\r
+ * (Re)open message composer with XIMF instance\r
+ */\r
+var XimfMsgCompose = XimfMsgCompose || {};\r
+XimfMsgCompose = { \r
+ maxNbStarter : 20,\r
+ counterStarter : 0,\r
+ catalog: null,\r
+ currentInstance : undefined,\r
+ preinit: function(){\r
+ var objMsgCompose = this;\r
+ XimfCatalogFactory.getIntance(function (instance) {\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] instance of catalog ready to use, init composer...");\r
+ objMsgCompose.catalog = instance;\r
+ objMsgCompose.init();\r
+ });\r
+ },\r
+ init: function () {\r
+ // ximfmail not requested\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] init begin...");\r
+ var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(null);\r
+ var showXimfmail = prefBranch.getBoolPref("mailnews.headers.showXimfmail");\r
+ //ResetXimfhdrsDom();\r
+ if (showXimfmail === false) {\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] no ximfmail composerfor this message");\r
+ $("#isUsingXimfail").attr("hidden","true");\r
+ try{\r
+ //remove ximf events ...\r
+ HideSendMessageElements(true);\r
+ $("#addressingWidget").unbind("command",SpecialXimfRule_CheckAddress);\r
+ ReloadSecurityAccess();\r
+ }catch(e){\r
+ }\r
+ return;\r
+ }\r
+ // let's compose ximf message\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] instance of ximfmail has to be loaded");\r
+ var o = this;\r
+ $("#isUsingXimfail").attr("hidden","false");\r
+ // observer on sending message\r
+ var ximfmailObserverSvc = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);\r
+ ximfmailObserverSvc.addObserver(XimfMsgSend, "mail:composeOnSend", false);\r
+ // add catalog\r
+ XimfMsgSend.ximfCatalog = o.catalog;\r
+ // check message type\r
+ try {\r
+ // is Template or Draft message\r
+ var typeMsg = -1;\r
+ var args = window.arguments[0];\r
+ if (args) {\r
+ typeMsg = args.type;\r
+ } else {\r
+ if (gMsgCompose) {\r
+ typeMsg = gMsgCompose.type;\r
+ }\r
+ }\r
+ switch (typeMsg) {\r
+ case nsIMsgCompType.Draft:\r
+ case nsIMsgCompType.Template:\r
+ case nsIMsgCompType.Reply:\r
+ case nsIMsgCompType.ReplyAll:\r
+ case nsIMsgCompType.ReplyToSender:\r
+ case nsIMsgCompType.ForwardInline:\r
+ case nsIMsgCompType.ForwardAsAttachment:\r
+ var uriMsg = null;\r
+ if (args) {\r
+ uriMsg = args.originalMsgURI;\r
+ } else {\r
+ if (gMsgCompose) {\r
+ uriMsg = gMsgCompose.originalMsgURI;\r
+ }\r
+ } \r
+ ResetXimfhdrsDom();\r
+ XimfmailGetMessage(uriMsg, function (msgSrc,uriSrc) {\r
+ // Get Extended headers of messages and display known instances\r
+ var currentXimfHdrArray = XimfmailParseMessage(msgSrc);\r
+ var ximfMsg = new XimfmailMesssage();\r
+ if (ximfMsg.init(uriSrc,currentXimfHdrArray)) {\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] parse original message and load Ximf instance " + ximfMsg._instanceMsgXimf);\r
+ o.currentInstance = ximfMsg._instanceMsgXimf;\r
+ o.loadPanel();\r
+ ComputeWithForm(ximfMsg);\r
+ } else {\r
+ $("#ximfmailComposeMessageTitle").attr("value","");\r
+ $("#isUsingXimfail").attr("hidden","false");\r
+ HideSendMessageElements(true);\r
+ $("#addressingWidget").unbind("command",SpecialXimfRule_CheckAddress);\r
+ ReloadSecurityAccess();\r
+ }\r
+ });\r
+ break;\r
+ default :\r
+ // default instance of account loaded\r
+ o.currentInstance = prefBranch.getCharPref("ximfmail.composeMsg.instance");\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] load Ximf instance " + o.currentInstance);\r
+ o.loadPanel();\r
+ break;\r
+ }\r
+ } catch(e) {\r
+ gConsole.logStringMessage("[ximfmail - XimfMsgCompose ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+e.lineNumber);\r
+ } \r
+ },\r
+ loadPanel : function () {\r
+ gConsole.logStringMessage("[XimfMsgCompose:loadPanel ] XIMF instance : " + this.currentInstance);\r
+ try{\r
+ // reload security user functions\r
+ ReloadSecurityAccess();\r
+ }catch(e){}\r
+ \r
+ if (this.currentInstance) {\r
+ try {\r
+ gCurrentInstance = this.currentInstance;\r
+ if (null !== gXimfHdrs) {\r
+ gXimfHdrs = null;\r
+ }\r
+ gXimfHdrs = new XimfmailInstanceHeaders();\r
+ gXimfHdrs.init(gCurrentInstance);\r
+ gXimfHdrs.loadXimfSecurityRules(gCurrentIdentity);\r
+ InsertXimfhdrsDom(gXimfHdrs.getXimfInstanceResource(), ximfConst.CHROME_XSL_MSG_COMPOSE, this.catalog);\r
+ // controler init\r
+ LoadXimfhdrsEventObserver();\r
+ ExecuteXimfHdrsDefaultValuesRule();\r
+ InitSpecialXimfRules();\r
+ CheckXimfhdrsSelection();\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - InsertXimfmailComposer ] " + e +"\nline : " + e.lineNumber + " : "+ e + "\nfile : "+ Error().fileName);\r
+ }\r
+ }\r
+ // ximfmail composer is initialized, event-it\r
+ var event = document.createEvent('Events');\r
+ event.initEvent('compose-ximfmail-init', false, true);\r
+ document.getElementById("msgcomposeWindow").dispatchEvent(event);\r
+ }\r
+};\r
+/**\r
+ * wait for thunderbird context before initializing ximfmail composer\r
+ * @returns\r
+ */\r
+function ximfMsgComposeStarter() {\r
+ var maxNbStarter = 20;\r
+ gConsole.logStringMessage("[ximfmail - ximfMsgComposeStarter ]start try " + gcounterStarter + "/" + maxNbStarter + " - gCurrentIdentity = " + gCurrentIdentity.key);\r
+ if (!gCurrentIdentity) {\r
+ try{\r
+ // try to get identity\r
+ // copy code from LoadIdentity(startup) function of MsgComposeCommand.js file\r
+ var identityElement = document.getElementById("msgIdentity");\r
+ if (identityElement) {\r
+ gCurrentIdentity = MailServices.accounts.getIdentity(identityElement.value);\r
+ }\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - ximfMsgComposeStarter ] error : " + e);\r
+ }\r
+ gConsole.logStringMessage("[ximfmail - ximfMsgComposeStarter ] get gCurrentIdentity = " + gCurrentIdentity.key);\r
+ // I can't catch event on completely initialized compose message, so loop on gCurrentIdentity loaded\r
+ if (gcounterStarter < maxNbStarter) {\r
+ gcounterStarter++;\r
+ setTimeout(function() {\r
+ ximfMsgComposeStarter();\r
+ }, 50);\r
+ return;\r
+ }\r
+ }\r
+ // init XimfMsgCompose\r
+ gConsole.logStringMessage("[ximfmail - ximfMsgComposeStarter ] Init XimfMsgCompose with identity " + gCurrentIdentity.key);\r
+ XimfMsgCompose.preinit();\r
+}\r
+//init ximfmail document\r
+window.addEventListener("compose-window-reopen", function() {\r
+ XimfMsgCompose.init(); \r
+ }, true);\r
+window.addEventListener("compose-window-init", function() {\r
+ gConsole.logStringMessage("[ximfmail - ximfMsgComposeStarter ] compose-window-init event catched! ");\r
+ gcounterStarter = 1;\r
+ ximfMsgComposeStarter(); \r
+ }, true);\r
+// overload Trustedbird function : add verifications on security message\r
+SendMessage = function(){\r
+ if (CheckIfMustBSigned()) {\r
+ return false;\r
+ }\r
+ GenericSendMessage(nsIMsgCompDeliverMode.Now);\r
+};\r
+// overload Trustedbird function : add verifications on security message\r
+SendMessageLater = function() {\r
+ if(CheckIfMustBSigned()){\r
+ return false;\r
+ }\r
+ GenericSendMessage(nsIMsgCompDeliverMode.Later);\r
+};\r
+/*\r
+ * is XIMFMAIL message ?\r
+ * yes : check if message must be signed\r
+ * no : continue\r
+ */\r
+function CheckIfMustBSigned() {\r
+ try {\r
+ var arrSecureHdrs = CreateRulesArray(gCurrentInstance,"ximf:secureHeaders");\r
+ var arrSecurityLabelHdrs = CreateRulesArray(gCurrentInstance,"ximf:securityLabel");\r
+ if ((arrSecureHdrs.length > 0 || arrSecurityLabelHdrs.length > 0) && !gSMFields.signMessage) {\r
+ // current message must be secured\r
+ toggleSignMessage();\r
+ if (!gCurrentIdentity.getUnicharAttribute("signing_cert_name")) {\r
+ return true;\r
+ } else {\r
+ if (!gSMFields.signMessage) {\r
+ // certificate is set by user\r
+ toggleSignMessage();\r
+ }\r
+ }\r
+ }\r
+ } catch(e) {\r
+ gConsole.logStringMessage("[ximfmail - SendMessage_Ximf ] not a ximf message... \n " + e + "\nfile : " + Error().fileName+"\nline : "+e.lineNumber);\r
+ }\r
+ return false;\r
+}
\ No newline at end of file