From 3f7592052cf5324d9cb869f372fca774c29e930e Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Thu, 24 Jan 2013 17:24:14 +0100 Subject: [PATCH 01/24] Added some development info to README. --- README | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README b/README index 3ef50f7..cebf0c9 100644 --- a/README +++ b/README @@ -1 +1,35 @@ A Thunderbird add-on to help with bugmail + +Development +============= + +To test the development version in thunderbird: + +- uninstall „normal” Bugmail if it is installed (using Thunderbird + Add-ons Manager) + +- in your extensions directory + (~/.thunderbird//extensions/ or similar) + create the file named + {32d96adf-23fc-403d-a1c8-e5cf6a019bee} + (yes, use this ugly name, it must match from install.rdf) + which body is + /path/to/the/devel/bugmail + (replace with true full path to the directory this file lies in) + +- restart thunderbird + +More details: https://developer.mozilla.org/en-US/docs/Extensions/Thunderbird/Building_a_Thunderbird_extension_7:_Installation + + +Packaging +============= + +Simply zip the whole extension folder, for example + + cd path/to/bugmail + zip -r ../bugmail.xpi chrome chrome.manifest install.rdf LICENSE README + + + + \ No newline at end of file From 9f72e80a38d5c18c68d8c5942f6fe8d28e956a2c Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Thu, 24 Jan 2013 17:40:16 +0100 Subject: [PATCH 02/24] Tiny fix in prev doc. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index cebf0c9..7ee88f3 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ To test the development version in thunderbird: {32d96adf-23fc-403d-a1c8-e5cf6a019bee} (yes, use this ugly name, it must match from install.rdf) which body is - /path/to/the/devel/bugmail + /path/to/the/devel/bugmail/ (replace with true full path to the directory this file lies in) - restart thunderbird From c7fac7d84ee9fa66374c78390afd8c8908034641 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Thu, 24 Jan 2013 17:52:57 +0100 Subject: [PATCH 03/24] Version push --- install.rdf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.rdf b/install.rdf index e337122..93ada82 100644 --- a/install.rdf +++ b/install.rdf @@ -12,7 +12,7 @@ {3550f703-e582-4d05-9a08-453d09bdfdc6} 2.0 - 9.0a1 + 17.* From e6c08fcdb43b04aad60cdc952a3eae597f1eefd2 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Thu, 24 Jan 2013 20:31:01 +0100 Subject: [PATCH 04/24] Some partial notes about supporting Thunderbird Conversations --- README | 18 ++++++++ chrome/content/overlay.js | 89 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/README b/README index 3ef50f7..2e329c0 100644 --- a/README +++ b/README @@ -1 +1,19 @@ A Thunderbird add-on to help with bugmail + + + +Useful development tricks: + +- set browser.dom.window.dump.enabled to true in about:config + (about:config can be reachedby Preferences/Advanced/General/Config Editor) + this should make dump("...") available to extension code + +- set javascript.options.showInConsole = true in about:config + +- set extensions.logging.enabled = true + +- start thunderbird with + + thunderbird --purgecaches + + MOZ_PURGE_CACHES \ No newline at end of file diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index a6fec80..1018a63 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -22,6 +22,16 @@ bugmail extension for Thunderbird var CC = Components.classes; var CI = Components.interfaces; +var console = { + service: null, + log: function(msg) { + if (!console.service) + console.service = Components.classes["@mozilla.org/consoleservice;1"] + .getService(Components.interfaces.nsIConsoleService); + console.service.logStringMessage(msg); + } +}; + var bugmail = { loading : false, req: null, @@ -81,7 +91,7 @@ var bugmail = { update: function(bypassCache, mailURI, headers) { var engine = null; var uri = null; - + for (var i = 0; i < bugmail.engines.length; i++) { if (bugmail.engines[i].isBug(mailURI, headers)) { uri = bugmail.engines[i].getBugURI(mailURI, headers); @@ -139,9 +149,11 @@ var bugmail = { else { document.getElementById("bugmail-box").setAttribute("collapsed", "true"); } + }, observe: function(aSubject, aTopic, aData) { + console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); if (aTopic == "MsgMsgDisplayed") { var messenger = CC["@mozilla.org/messenger;1"]. createInstance().QueryInterface(CI.nsIMessenger); @@ -244,4 +256,77 @@ function cleanup() { var ObserverService = CC["@mozilla.org/observer-service;1"]. getService(CI.nsIObserverService); -ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); \ No newline at end of file +ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); + +/////////////////////////////////////////////////////////////////////////// +// Thunderbird Conversations hooking +/////////////////////////////////////////////////////////////////////////// + +/* + Conversations do not provide MsgMsgDisplayed event. Instead, one + can subscribe their own events. See + http://blog.xulforum.org/index.php?post/2010/11/27/Thunderbird-Conversations-plugins + and + https://github.com/protz/GMail-Conversation-View/blob/master/modules/hook.js + + In particular, onMessageStreamed hook is called whenever some message + is displayed in conversations view. + + The problem is that while we have both message here, and dom objects, + the message is database-loaded, not remote, and DOM layout is different. + Therefore fairly different way to examine whether given element is a bug, + and what bug is it referencing, is needed. + */ + +let hasConversations; +try { + Components.utils.import("resource://conversations/hook.js"); + hasConversations = true; +} catch (e) { + hasConversations = false; +} + +if (hasConversations) { + registerHook({ + // Called whenever some message is displayed in conversation view. + // Arguments: + // aMsgHdr: [xpconnect wrapped nsIMsgDBHdr] + // aDomNode: [object HTMLLIElement] + // aMsgWindow: [xpconnect wrapped nsIMsgWindow] + // aMessage: undefined (is to appear in newer conversations versions probably) + // + // Some interesting attributes: + // aMsgWindow.msgHeaderSink [nsIMsgHeaderSink] + // aDomNode.baseURI (wrong, "chrome://conversations/content/stub.xhtml") + // + // if I had a message, then + // aMessage.folder.getUriForMsg(aMessage) + // or even + // aMessage.folder.getUriForMsg(aMsgHdr) + // would give uri + + onMessageStreamed: function (aMsgHdr, aDomNode, aMsgWindow, aMessage) { + console.log("onMessageStreamed"); + console.log("aMsgHdr: " + aMsgHdr); + console.log("Dom node: " + aDomNode); + console.log("Msg window: " + aMsgWindow); + console.log("aMessage: " + aMessage); + console.log("aMsgHdr.folder: " + aMsgHdr.folder); + + // var uri = aMsgWindow.openFolder.getUriForMsg(aMsgHdr); + var uri = aMsgHdr.folder.getUriForMsg(aMsgHdr); + console.log("uri: ", uri); + // bugmail.observe takes 3 params: + // - (not used) [xpconnect wrapped nsIMsgHeaderSink] + // - "MsgMsgDisplayed" (event name) + // - "imap-message://Marcin.Nowak@my.mail.server.com/INBOX#999" (uri) + //bugmail.observe(aMsgHdr, "MsgMsgDisplayed", aDomNode); + + //bugmail.update(bypassCache, uri, mimeHeaders); + bugmail.update(bugmailStreamListener.bypassCache, + uri, + aMsgWindow.msgHeaderSink); + + }, + }); +} From 3b3a8b8c5e5648e8640c5905d6c9b1fa67ad9797 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Thu, 24 Jan 2013 20:42:13 +0100 Subject: [PATCH 05/24] Factoring out update function into the two, as for conversations different detection will be needed. --- chrome/content/overlay.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 1018a63..09f535d 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -102,6 +102,16 @@ var bugmail = { } } + if(engine) { + console.log("Detected bug message, uri: " + uri); + bugmail.update_using_engine(bypassCache, engine, uri); + console.log("Interface updated"); + } + }, + + // Load the bug using given bug engine and given extracted bug uri + update_using_engine: function(bypassCache, engine, uri) { + if (engine) { document.getElementById("bugmail-logo").setAttribute("src", engine.iconURL); @@ -151,6 +161,8 @@ var bugmail = { } }, + + observe: function(aSubject, aTopic, aData) { console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); From e0bf1dfa22b570cac04c308d27aa478be8e788e4 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Thu, 24 Jan 2013 21:14:06 +0100 Subject: [PATCH 06/24] In conversations view we properly detect bugzilla bugs and extract uri. Still for some reason message does not appear, to be tested. --- chrome/content/overlay.js | 49 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 09f535d..d069120 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -324,21 +324,40 @@ if (hasConversations) { console.log("Msg window: " + aMsgWindow); console.log("aMessage: " + aMessage); console.log("aMsgHdr.folder: " + aMsgHdr.folder); - - // var uri = aMsgWindow.openFolder.getUriForMsg(aMsgHdr); - var uri = aMsgHdr.folder.getUriForMsg(aMsgHdr); - console.log("uri: ", uri); - // bugmail.observe takes 3 params: - // - (not used) [xpconnect wrapped nsIMsgHeaderSink] - // - "MsgMsgDisplayed" (event name) - // - "imap-message://Marcin.Nowak@my.mail.server.com/INBOX#999" (uri) - //bugmail.observe(aMsgHdr, "MsgMsgDisplayed", aDomNode); - - //bugmail.update(bypassCache, uri, mimeHeaders); - bugmail.update(bugmailStreamListener.bypassCache, - uri, - aMsgWindow.msgHeaderSink); - + // again stub.xhtml + console.log("aDomNode.baseUri = " + aDomNode.baseURI); // or .baseURIObject + + /* + var enumerator = aMsgHdr.propertyEnumerator; + while(enumerator.hasMore()) { + console.log("Property: " + enumerator.getNext()); + } + */ + + + // Proof of concept, to be migrated down once works + var product = aMsgHdr.getProperty("x-bugzilla-product"); + if(product) { + console.log("We have bugzilla bug here, trying to locate it's uri"); + /* + var doc = aDomNode.ownerDocument; + console.log("doc = " + doc); + var uri = doc.querySelector("a[href*=show_bug]").href + + "&ctype=xml&excludefield=attachmentdata"; + */ + let iframe = aDomNode.getElementsByTagName("iframe")[0]; + let iframeDoc = iframe.contentDocument; + console.log("inner document uri=" + iframeDoc.documentURI); // YES: here we have imap://.... + var uri = iframeDoc.querySelector("a[href*=show_bug]").href + + "&ctype=xml&excludefield=attachmentdata"; + console.log("uri from doc = " + uri); // YES: this is OK + bugmail.update_using_engine(0, // bypasscache, maybe bugmailStreamListener.bypassCache, + uri, + bugzillaEngine); + console.log("updated"); + } + + }, }); } From 9ba9f271560cc8c9964d6ebb209caf03f9460b25 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 11:59:42 +0100 Subject: [PATCH 07/24] Some more logging. --- chrome/content/overlay.js | 150 +++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 73 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index d069120..0320013 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -26,9 +26,9 @@ var console = { service: null, log: function(msg) { if (!console.service) - console.service = Components.classes["@mozilla.org/consoleservice;1"] - .getService(Components.interfaces.nsIConsoleService); - console.service.logStringMessage(msg); + console.service = Components.classes["@mozilla.org/consoleservice;1"] + .getService(Components.interfaces.nsIConsoleService); + console.service.logStringMessage(msg); } }; @@ -102,11 +102,7 @@ var bugmail = { } } - if(engine) { - console.log("Detected bug message, uri: " + uri); - bugmail.update_using_engine(bypassCache, engine, uri); - console.log("Interface updated"); - } + bugmail.update_using_engine(bypassCache, engine, uri); }, // Load the bug using given bug engine and given extracted bug uri @@ -124,6 +120,7 @@ var bugmail = { if (!bypassCache) { var data = bugmail.getFromCache(uri); if (data) { + console.log("Succesfully reloaded bug info from cache. Uri: " + uri + ", text: " + data.text); document.getElementById("bugmail-box").removeAttribute("collapsed"); var content = document.getElementById("bugmail-info"); while (content.lastChild) { @@ -135,14 +132,17 @@ var bugmail = { } bugmail.req = new XMLHttpRequest(); + console.log("Attempting to load " + uri); bugmail.req.open("GET", uri); bugmail.req.onload = function() { + console.log("Got bug info reply: " + this.responseText); bugmail.loading = false; document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); bugmail.storeInCache(uri, this.responseXML, this.responseText); engine.updateUI(this.responseXML, this.responseText); } bugmail.req.onerror = function() { + console.log("Bug info loading failed"); bugmail.loading = false; document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); } @@ -157,6 +157,7 @@ var bugmail = { bugmail.req.send(null); } else { + console.log("Removing bug info as no bug is present"); document.getElementById("bugmail-box").setAttribute("collapsed", "true"); } @@ -173,10 +174,10 @@ var bugmail = { bugmailStreamListener.uri = aData; bugmailStreamListener.bypassCache = false; try { - msgService.streamMessage(aData, bugmailStreamListener, null, + msgService.streamMessage(aData, bugmailStreamListener, null, null, false, "", null); - } catch(e) { - } + } catch(e) { + } } }, @@ -292,72 +293,75 @@ ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); let hasConversations; try { - Components.utils.import("resource://conversations/hook.js"); - hasConversations = true; + Components.utils.import("resource://conversations/hook.js"); + hasConversations = true; } catch (e) { - hasConversations = false; + hasConversations = false; } if (hasConversations) { - registerHook({ - // Called whenever some message is displayed in conversation view. - // Arguments: - // aMsgHdr: [xpconnect wrapped nsIMsgDBHdr] - // aDomNode: [object HTMLLIElement] - // aMsgWindow: [xpconnect wrapped nsIMsgWindow] - // aMessage: undefined (is to appear in newer conversations versions probably) - // - // Some interesting attributes: - // aMsgWindow.msgHeaderSink [nsIMsgHeaderSink] - // aDomNode.baseURI (wrong, "chrome://conversations/content/stub.xhtml") - // - // if I had a message, then - // aMessage.folder.getUriForMsg(aMessage) - // or even - // aMessage.folder.getUriForMsg(aMsgHdr) - // would give uri - - onMessageStreamed: function (aMsgHdr, aDomNode, aMsgWindow, aMessage) { - console.log("onMessageStreamed"); - console.log("aMsgHdr: " + aMsgHdr); - console.log("Dom node: " + aDomNode); - console.log("Msg window: " + aMsgWindow); - console.log("aMessage: " + aMessage); - console.log("aMsgHdr.folder: " + aMsgHdr.folder); - // again stub.xhtml - console.log("aDomNode.baseUri = " + aDomNode.baseURI); // or .baseURIObject - - /* - var enumerator = aMsgHdr.propertyEnumerator; - while(enumerator.hasMore()) { + console.log("Thunderbird conversations are active, installing hook for their mode"); + registerHook({ + // Called whenever some message is displayed in conversation view. + // Arguments: + // aMsgHdr: [xpconnect wrapped nsIMsgDBHdr] + // aDomNode: [object HTMLLIElement] + // aMsgWindow: [xpconnect wrapped nsIMsgWindow] + // aMessage: undefined (is to appear in newer conversations versions probably) + // + // Some interesting attributes: + // aMsgWindow.msgHeaderSink [nsIMsgHeaderSink] + // aDomNode.baseURI (wrong, "chrome://conversations/content/stub.xhtml") + // + // if I had a message, then + // aMessage.folder.getUriForMsg(aMessage) + // or even + // aMessage.folder.getUriForMsg(aMsgHdr) + // would give uri + + onMessageStreamed: function (aMsgHdr, aDomNode, aMsgWindow, aMessage) { + console.log("onMessageStreamed"); + console.log("aMsgHdr: " + aMsgHdr); + console.log("Dom node: " + aDomNode); + console.log("Msg window: " + aMsgWindow); + console.log("aMessage: " + aMessage); + console.log("aMsgHdr.folder: " + aMsgHdr.folder); + // again stub.xhtml + console.log("aDomNode.baseUri = " + aDomNode.baseURI); // or .baseURIObject + + /* + var enumerator = aMsgHdr.propertyEnumerator; + while(enumerator.hasMore()) { console.log("Property: " + enumerator.getNext()); - } - */ - - - // Proof of concept, to be migrated down once works - var product = aMsgHdr.getProperty("x-bugzilla-product"); - if(product) { - console.log("We have bugzilla bug here, trying to locate it's uri"); - /* - var doc = aDomNode.ownerDocument; - console.log("doc = " + doc); - var uri = doc.querySelector("a[href*=show_bug]").href + + } + */ + + // Proof of concept, to be migrated down once works + + var product = aMsgHdr.getProperty("x-bugzilla-product"); + if(product) { + console.log("We have bugzilla bug here, trying to locate it's uri"); + /* + var doc = aDomNode.ownerDocument; + console.log("doc = " + doc); + var uri = doc.querySelector("a[href*=show_bug]").href + "&ctype=xml&excludefield=attachmentdata"; - */ - let iframe = aDomNode.getElementsByTagName("iframe")[0]; - let iframeDoc = iframe.contentDocument; - console.log("inner document uri=" + iframeDoc.documentURI); // YES: here we have imap://.... - var uri = iframeDoc.querySelector("a[href*=show_bug]").href + - "&ctype=xml&excludefield=attachmentdata"; - console.log("uri from doc = " + uri); // YES: this is OK - bugmail.update_using_engine(0, // bypasscache, maybe bugmailStreamListener.bypassCache, - uri, - bugzillaEngine); - console.log("updated"); - } - - - }, - }); + */ + let iframe = aDomNode.getElementsByTagName("iframe")[0]; + let iframeDoc = iframe.contentDocument; + console.log("inner document uri=" + iframeDoc.documentURI); // YES: here we have imap://.... + var uri = iframeDoc.querySelector("a[href*=show_bug]").href + + "&ctype=xml&excludefield=attachmentdata"; + console.log("uri from doc = " + uri); // YES: this is OK + bugmail.update_using_engine(0, // bypasscache, maybe bugmailStreamListener.bypassCache, + uri, + bugzillaEngine); + console.log("updated"); + } + + + }, + }); +} else { + console.log("Thunderbird Conversations not active"); } From b60a8b67221e1da60ec14397dff20102384ba47c Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 12:00:31 +0100 Subject: [PATCH 08/24] Tabs replaced with spaces. Made most editors much happier. --- chrome/content/overlay.js | 306 +++++++++++++++++++------------------- 1 file changed, 153 insertions(+), 153 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 0320013..03adc22 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -34,177 +34,177 @@ var console = { var bugmail = { loading : false, - req: null, - engines : [], - - addEngine: function(engine) { - bugmail.engines.push(engine); - }, - - getFromCache: function(uri) { - var cacheService = CC["@mozilla.org/network/cache-service;1"]. + req: null, + engines : [], + + addEngine: function(engine) { + bugmail.engines.push(engine); + }, + + getFromCache: function(uri) { + var cacheService = CC["@mozilla.org/network/cache-service;1"]. getService(CI.nsICacheService); - var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); + var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); - try { - var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_READ, true); - var input = entry.openInputStream(0); - var cache = new Object(); - cache.doc = null; - cache.text = null; - var parser = CC["@mozilla.org/xmlextras/domparser;1"].createInstance(CI.nsIDOMParser); - try { - var xml = parser.parseFromStream(input, "utf-8", input.available(), "text/xml"); - cache.doc = xml; - } catch(e) { - cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, false); - entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_READ, true); - cache.text = entry.data.data; - } - return cache; - } catch(e) { - return null; - } - }, - - storeInCache: function(uri, doc, text) { - var cacheService = CC["@mozilla.org/network/cache-service;1"]. - getService(CI.nsICacheService); - if (doc) { - var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); - var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_WRITE, true); - var output = entry.openOutputStream(0); - var ser = CC["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(CI.nsIDOMSerializer); - ser.serializeToStream(doc, output, "utf-8"); - } - else { - var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, false); - var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_WRITE, true); - var wrapper = CC["@mozilla.org/supports-cstring;1"].createInstance(CI.nsISupportsCString); - wrapper.data = text; - entry.cacheElement = wrapper; - } - entry.markValid; - entry.close(); - }, + try { + var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_READ, true); + var input = entry.openInputStream(0); + var cache = new Object(); + cache.doc = null; + cache.text = null; + var parser = CC["@mozilla.org/xmlextras/domparser;1"].createInstance(CI.nsIDOMParser); + try { + var xml = parser.parseFromStream(input, "utf-8", input.available(), "text/xml"); + cache.doc = xml; + } catch(e) { + cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, false); + entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_READ, true); + cache.text = entry.data.data; + } + return cache; + } catch(e) { + return null; + } + }, + + storeInCache: function(uri, doc, text) { + var cacheService = CC["@mozilla.org/network/cache-service;1"]. + getService(CI.nsICacheService); + if (doc) { + var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); + var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_WRITE, true); + var output = entry.openOutputStream(0); + var ser = CC["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(CI.nsIDOMSerializer); + ser.serializeToStream(doc, output, "utf-8"); + } + else { + var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, false); + var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_WRITE, true); + var wrapper = CC["@mozilla.org/supports-cstring;1"].createInstance(CI.nsISupportsCString); + wrapper.data = text; + entry.cacheElement = wrapper; + } + entry.markValid; + entry.close(); + }, update: function(bypassCache, mailURI, headers) { - var engine = null; - var uri = null; - - for (var i = 0; i < bugmail.engines.length; i++) { - if (bugmail.engines[i].isBug(mailURI, headers)) { - uri = bugmail.engines[i].getBugURI(mailURI, headers); - if (uri) { - engine = bugmail.engines[i]; - break; - } - } - } - + var engine = null; + var uri = null; + + for (var i = 0; i < bugmail.engines.length; i++) { + if (bugmail.engines[i].isBug(mailURI, headers)) { + uri = bugmail.engines[i].getBugURI(mailURI, headers); + if (uri) { + engine = bugmail.engines[i]; + break; + } + } + } + bugmail.update_using_engine(bypassCache, engine, uri); }, // Load the bug using given bug engine and given extracted bug uri update_using_engine: function(bypassCache, engine, uri) { - if (engine) { - - document.getElementById("bugmail-logo").setAttribute("src", engine.iconURL); - - if (bugmail.loading) { - bugmail.req.abort(); + if (engine) { + + document.getElementById("bugmail-logo").setAttribute("src", engine.iconURL); + + if (bugmail.loading) { + bugmail.req.abort(); bugmail.loading = false; - } + } if (!bypassCache) { - var data = bugmail.getFromCache(uri); - if (data) { + var data = bugmail.getFromCache(uri); + if (data) { console.log("Succesfully reloaded bug info from cache. Uri: " + uri + ", text: " + data.text); - document.getElementById("bugmail-box").removeAttribute("collapsed"); - var content = document.getElementById("bugmail-info"); - while (content.lastChild) { - content.removeChild(content.lastChild); - } - engine.updateUI(data.doc, data.text); - return; - } - } - - bugmail.req = new XMLHttpRequest(); + document.getElementById("bugmail-box").removeAttribute("collapsed"); + var content = document.getElementById("bugmail-info"); + while (content.lastChild) { + content.removeChild(content.lastChild); + } + engine.updateUI(data.doc, data.text); + return; + } + } + + bugmail.req = new XMLHttpRequest(); console.log("Attempting to load " + uri); - bugmail.req.open("GET", uri); - bugmail.req.onload = function() { + bugmail.req.open("GET", uri); + bugmail.req.onload = function() { console.log("Got bug info reply: " + this.responseText); - bugmail.loading = false; - document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); - bugmail.storeInCache(uri, this.responseXML, this.responseText); + bugmail.loading = false; + document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); + bugmail.storeInCache(uri, this.responseXML, this.responseText); engine.updateUI(this.responseXML, this.responseText); - } - bugmail.req.onerror = function() { + } + bugmail.req.onerror = function() { console.log("Bug info loading failed"); - bugmail.loading = false; - document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); - } - var content = document.getElementById("bugmail-info"); - while (content.lastChild) { - content.removeChild(content.lastChild); - } - document.getElementById("bugmail-details").setAttribute("collapsed", "true"); - document.getElementById("bugmail-box").removeAttribute("collapsed"); - document.getElementById("bugmail-throbber").removeAttribute("collapsed"); - bugmail.loading = true; - bugmail.req.send(null); - } - else { + bugmail.loading = false; + document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); + } + var content = document.getElementById("bugmail-info"); + while (content.lastChild) { + content.removeChild(content.lastChild); + } + document.getElementById("bugmail-details").setAttribute("collapsed", "true"); + document.getElementById("bugmail-box").removeAttribute("collapsed"); + document.getElementById("bugmail-throbber").removeAttribute("collapsed"); + bugmail.loading = true; + bugmail.req.send(null); + } + else { console.log("Removing bug info as no bug is present"); - document.getElementById("bugmail-box").setAttribute("collapsed", "true"); - } + document.getElementById("bugmail-box").setAttribute("collapsed", "true"); + } - }, + }, - - observe: function(aSubject, aTopic, aData) { + + observe: function(aSubject, aTopic, aData) { console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); - if (aTopic == "MsgMsgDisplayed") { - var messenger = CC["@mozilla.org/messenger;1"]. - createInstance().QueryInterface(CI.nsIMessenger); - var msgService = messenger.messageServiceFromURI(aData); - bugmailStreamListener.uri = aData; - bugmailStreamListener.bypassCache = false; - try { - msgService.streamMessage(aData, bugmailStreamListener, null, - null, false, "", null); - } catch(e) { - } - } - }, - - forceUpdate: function() { - var messenger = CC["@mozilla.org/messenger;1"]. + if (aTopic == "MsgMsgDisplayed") { + var messenger = CC["@mozilla.org/messenger;1"]. + createInstance().QueryInterface(CI.nsIMessenger); + var msgService = messenger.messageServiceFromURI(aData); + bugmailStreamListener.uri = aData; + bugmailStreamListener.bypassCache = false; + try { + msgService.streamMessage(aData, bugmailStreamListener, null, + null, false, "", null); + } catch(e) { + } + } + }, + + forceUpdate: function() { + var messenger = CC["@mozilla.org/messenger;1"]. createInstance().QueryInterface(CI.nsIMessenger); - var msgService = messenger.messageServiceFromURI(bugmailStreamListener.uri); - bugmailStreamListener.bypassCache = true; - try { - msgService.streamMessage(bugmailStreamListener.uri, bugmailStreamListener, null, - null, false, "", null); - } catch(e) { - } - }, - - loadHiddenIFrame: function(text) { - var content = document.getElementById("bugmail-iframe").contentDocument; - var range = content.createRange(); - var root = content.getElementById("root"); - while (root.lastChild) { - root.removeChild(root.lastChild); - } - range.selectNode(root); - var frag = range.createContextualFragment(text); - root.appendChild(frag); - return content; - } + var msgService = messenger.messageServiceFromURI(bugmailStreamListener.uri); + bugmailStreamListener.bypassCache = true; + try { + msgService.streamMessage(bugmailStreamListener.uri, bugmailStreamListener, null, + null, false, "", null); + } catch(e) { + } + }, + + loadHiddenIFrame: function(text) { + var content = document.getElementById("bugmail-iframe").contentDocument; + var range = content.createRange(); + var root = content.getElementById("root"); + while (root.lastChild) { + root.removeChild(root.lastChild); + } + range.selectNode(root); + var frag = range.createContextualFragment(text); + root.appendChild(frag); + return content; + } }; var bugmailStreamListener = { @@ -215,7 +215,7 @@ bypassCache: false, QueryInterface: function(aIId, instance) { if (aIId.equals(CI.nsIStreamListener) || - aIId.equals(CI.nsISupports)) + aIId.equals(CI.nsISupports)) return this; throw Components.results.NS_ERROR_NO_INTERFACE; }, @@ -233,7 +233,7 @@ onStopRequest: function(request, context, status, errorMsg) { bugmail.update(this.bypassCache, this.uri, mimeHeaders); } catch (ex) { - return; + return; } }, @@ -246,7 +246,7 @@ onDataAvailable: function(request, context, inputStream, offset, count) { var inData = inStream.read(count); // Also ignore stuff after the first 25K or so - // should be enough to get headers... + // should be enough to get headers... if (this.message && this.message.length > 25000) return 0; @@ -254,15 +254,15 @@ onDataAvailable: function(request, context, inputStream, offset, count) { return 0; } catch (ex) { - return 0; + return 0; } } }; function cleanup() { - //alert("Bugmail cleanup"); - var ObserverService = CC["@mozilla.org/observer-service;1"]. + //alert("Bugmail cleanup"); + var ObserverService = CC["@mozilla.org/observer-service;1"]. getService(CI.nsIObserverService); ObserverService.removeObserver(bugmail, "MsgMsgDisplayed"); } From f32555f73216636348ccb738f98c277c86c4e4b6 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 12:08:58 +0100 Subject: [PATCH 09/24] Some indentation fixes. --- chrome/content/overlay.js | 170 ++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 82 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 03adc22..66e4c5d 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -1,5 +1,5 @@ /* -bugmail extension for Thunderbird + bugmail extension for Thunderbird Copyright (C) 2008 Fabrice Desré @@ -22,6 +22,10 @@ bugmail extension for Thunderbird var CC = Components.classes; var CI = Components.interfaces; +/////////////////////////////////////////////////////////////////////////// +// Helper object: log console +/////////////////////////////////////////////////////////////////////////// + var console = { service: null, log: function(msg) { @@ -32,6 +36,10 @@ var console = { } }; +/////////////////////////////////////////////////////////////////////////// +// Main object: bugmail +/////////////////////////////////////////////////////////////////////////// + var bugmail = { loading : false, req: null, @@ -43,7 +51,7 @@ var bugmail = { getFromCache: function(uri) { var cacheService = CC["@mozilla.org/network/cache-service;1"]. - getService(CI.nsICacheService); + getService(CI.nsICacheService); var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); try { @@ -54,8 +62,8 @@ var bugmail = { cache.text = null; var parser = CC["@mozilla.org/xmlextras/domparser;1"].createInstance(CI.nsIDOMParser); try { - var xml = parser.parseFromStream(input, "utf-8", input.available(), "text/xml"); - cache.doc = xml; + var xml = parser.parseFromStream(input, "utf-8", input.available(), "text/xml"); + cache.doc = xml; } catch(e) { cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, false); entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_READ, true); @@ -69,13 +77,13 @@ var bugmail = { storeInCache: function(uri, doc, text) { var cacheService = CC["@mozilla.org/network/cache-service;1"]. - getService(CI.nsICacheService); + getService(CI.nsICacheService); if (doc) { - var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); - var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_WRITE, true); - var output = entry.openOutputStream(0); - var ser = CC["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(CI.nsIDOMSerializer); - ser.serializeToStream(doc, output, "utf-8"); + var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, true); + var entry = cacheSession.openCacheEntry(uri, CI.nsICache.ACCESS_WRITE, true); + var output = entry.openOutputStream(0); + var ser = CC["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(CI.nsIDOMSerializer); + ser.serializeToStream(doc, output, "utf-8"); } else { var cacheSession = cacheService.createSession("bugmail", CI.nsICache.STORE_IN_MEMORY, false); @@ -96,7 +104,7 @@ var bugmail = { if (bugmail.engines[i].isBug(mailURI, headers)) { uri = bugmail.engines[i].getBugURI(mailURI, headers); if (uri) { - engine = bugmail.engines[i]; + engine = bugmail.engines[i]; break; } } @@ -160,35 +168,33 @@ var bugmail = { console.log("Removing bug info as no bug is present"); document.getElementById("bugmail-box").setAttribute("collapsed", "true"); } - + }, - - observe: function(aSubject, aTopic, aData) { - console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); + console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); if (aTopic == "MsgMsgDisplayed") { - var messenger = CC["@mozilla.org/messenger;1"]. - createInstance().QueryInterface(CI.nsIMessenger); - var msgService = messenger.messageServiceFromURI(aData); - bugmailStreamListener.uri = aData; - bugmailStreamListener.bypassCache = false; - try { - msgService.streamMessage(aData, bugmailStreamListener, null, - null, false, "", null); - } catch(e) { - } + var messenger = CC["@mozilla.org/messenger;1"]. + createInstance().QueryInterface(CI.nsIMessenger); + var msgService = messenger.messageServiceFromURI(aData); + bugmailStreamListener.uri = aData; + bugmailStreamListener.bypassCache = false; + try { + msgService.streamMessage(aData, bugmailStreamListener, null, + null, false, "", null); + } catch(e) { + } } }, forceUpdate: function() { var messenger = CC["@mozilla.org/messenger;1"]. - createInstance().QueryInterface(CI.nsIMessenger); + createInstance().QueryInterface(CI.nsIMessenger); var msgService = messenger.messageServiceFromURI(bugmailStreamListener.uri); bugmailStreamListener.bypassCache = true; try { - msgService.streamMessage(bugmailStreamListener.uri, bugmailStreamListener, null, - null, false, "", null); + msgService.streamMessage(bugmailStreamListener.uri, bugmailStreamListener, null, + null, false, "", null); } catch(e) { } }, @@ -209,66 +215,66 @@ var bugmail = { var bugmailStreamListener = { -message: "", -uri: null, -bypassCache: false, - -QueryInterface: function(aIId, instance) { - if (aIId.equals(CI.nsIStreamListener) || - aIId.equals(CI.nsISupports)) - return this; - throw Components.results.NS_ERROR_NO_INTERFACE; -}, - -onStartRequest: function(request, context) { -}, - -onStopRequest: function(request, context, status, errorMsg) { - try { - var headers = this.message.split(/\n\n|\r\n\r\n|\r\r/)[0]; - var mimeHeaders = CC["@mozilla.org/messenger/mimeheaders;1"]. - createInstance(CI.nsIMimeHeaders); - mimeHeaders.initialize(headers, headers.length); - this.message = ""; - bugmail.update(this.bypassCache, this.uri, mimeHeaders); - } - catch (ex) { - return; - } -}, - -onDataAvailable: function(request, context, inputStream, offset, count) { - try { - var inStream = CC["@mozilla.org/scriptableinputstream;1"].createInstance(CI.nsIScriptableInputStream); - inStream.init(inputStream); - - // It is necessary to read in data from the input stream - var inData = inStream.read(count); - - // Also ignore stuff after the first 25K or so - // should be enough to get headers... - if (this.message && this.message.length > 25000) - return 0; - - this.message += inData; - return 0; - } - catch (ex) { - return 0; - } -} + message: "", + uri: null, + bypassCache: false, + + QueryInterface: function(aIId, instance) { + if (aIId.equals(CI.nsIStreamListener) || + aIId.equals(CI.nsISupports)) + return this; + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + onStartRequest: function(request, context) { + }, + + onStopRequest: function(request, context, status, errorMsg) { + try { + var headers = this.message.split(/\n\n|\r\n\r\n|\r\r/)[0]; + var mimeHeaders = CC["@mozilla.org/messenger/mimeheaders;1"]. + createInstance(CI.nsIMimeHeaders); + mimeHeaders.initialize(headers, headers.length); + this.message = ""; + bugmail.update(this.bypassCache, this.uri, mimeHeaders); + } + catch (ex) { + return; + } + }, + + onDataAvailable: function(request, context, inputStream, offset, count) { + try { + var inStream = CC["@mozilla.org/scriptableinputstream;1"].createInstance(CI.nsIScriptableInputStream); + inStream.init(inputStream); + + // It is necessary to read in data from the input stream + var inData = inStream.read(count); + + // Also ignore stuff after the first 25K or so + // should be enough to get headers... + if (this.message && this.message.length > 25000) + return 0; + + this.message += inData; + return 0; + } + catch (ex) { + return 0; + } + } }; function cleanup() { //alert("Bugmail cleanup"); - var ObserverService = CC["@mozilla.org/observer-service;1"]. - getService(CI.nsIObserverService); - ObserverService.removeObserver(bugmail, "MsgMsgDisplayed"); + var ObserverService = CC["@mozilla.org/observer-service;1"]. + getService(CI.nsIObserverService); + ObserverService.removeObserver(bugmail, "MsgMsgDisplayed"); } var ObserverService = CC["@mozilla.org/observer-service;1"]. - getService(CI.nsIObserverService); + getService(CI.nsIObserverService); ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); /////////////////////////////////////////////////////////////////////////// @@ -291,7 +297,7 @@ ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); and what bug is it referencing, is needed. */ -let hasConversations; +var hasConversations; try { Components.utils.import("resource://conversations/hook.js"); hasConversations = true; @@ -360,7 +366,7 @@ if (hasConversations) { } - }, + } }); } else { console.log("Thunderbird Conversations not active"); From 27df1e8c17802d4d9aeaedf9f58183fb43d5b4b5 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 15:29:03 +0100 Subject: [PATCH 10/24] Moving initialization to onload --- chrome/content/overlay.js | 174 ++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 81 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 66e4c5d..8367a23 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -21,6 +21,7 @@ var CC = Components.classes; var CI = Components.interfaces; +var CU = Components.utils; /////////////////////////////////////////////////////////////////////////// // Helper object: log console @@ -29,9 +30,10 @@ var CI = Components.interfaces; var console = { service: null, log: function(msg) { - if (!console.service) - console.service = Components.classes["@mozilla.org/consoleservice;1"] - .getService(Components.interfaces.nsIConsoleService); + if (!console.service) { + console.service = CC["@mozilla.org/consoleservice;1"] + .getService(CI.nsIConsoleService); + } console.service.logStringMessage(msg); } }; @@ -128,7 +130,7 @@ var bugmail = { if (!bypassCache) { var data = bugmail.getFromCache(uri); if (data) { - console.log("Succesfully reloaded bug info from cache. Uri: " + uri + ", text: " + data.text); + console.log("bugmail: Succesfully reloaded bug info from cache. Uri: " + uri + ", text: " + data.text); document.getElementById("bugmail-box").removeAttribute("collapsed"); var content = document.getElementById("bugmail-info"); while (content.lastChild) { @@ -140,17 +142,17 @@ var bugmail = { } bugmail.req = new XMLHttpRequest(); - console.log("Attempting to load " + uri); + console.log("bugmail: Attempting to load bug details from " + uri); bugmail.req.open("GET", uri); bugmail.req.onload = function() { - console.log("Got bug info reply: " + this.responseText); + console.log("bugmail: Got bug info reply: " + this.responseText); bugmail.loading = false; document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); bugmail.storeInCache(uri, this.responseXML, this.responseText); engine.updateUI(this.responseXML, this.responseText); } bugmail.req.onerror = function() { - console.log("Bug info loading failed"); + console.log("bugmail: Bug info loading failed"); bugmail.loading = false; document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); } @@ -165,14 +167,14 @@ var bugmail = { bugmail.req.send(null); } else { - console.log("Removing bug info as no bug is present"); + console.log("bugmail: Removing bug panel as no bug is present"); document.getElementById("bugmail-box").setAttribute("collapsed", "true"); } }, observe: function(aSubject, aTopic, aData) { - console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); + // console.log("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); if (aTopic == "MsgMsgDisplayed") { var messenger = CC["@mozilla.org/messenger;1"]. createInstance().QueryInterface(CI.nsIMessenger); @@ -273,9 +275,12 @@ function cleanup() { ObserverService.removeObserver(bugmail, "MsgMsgDisplayed"); } -var ObserverService = CC["@mozilla.org/observer-service;1"]. - getService(CI.nsIObserverService); -ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); +window.addEventListener("load", function(e) { + var ObserverService = CC["@mozilla.org/observer-service;1"]. + getService(CI.nsIObserverService); + ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); + console.log("bugmail: normal messages hook installed"); +}); /////////////////////////////////////////////////////////////////////////// // Thunderbird Conversations hooking @@ -297,77 +302,84 @@ ObserverService.addObserver(bugmail, "MsgMsgDisplayed", false); and what bug is it referencing, is needed. */ -var hasConversations; -try { - Components.utils.import("resource://conversations/hook.js"); - hasConversations = true; -} catch (e) { - hasConversations = false; -} +window.addEventListener("load", function(e) { -if (hasConversations) { - console.log("Thunderbird conversations are active, installing hook for their mode"); - registerHook({ - // Called whenever some message is displayed in conversation view. - // Arguments: - // aMsgHdr: [xpconnect wrapped nsIMsgDBHdr] - // aDomNode: [object HTMLLIElement] - // aMsgWindow: [xpconnect wrapped nsIMsgWindow] - // aMessage: undefined (is to appear in newer conversations versions probably) - // - // Some interesting attributes: - // aMsgWindow.msgHeaderSink [nsIMsgHeaderSink] - // aDomNode.baseURI (wrong, "chrome://conversations/content/stub.xhtml") - // - // if I had a message, then - // aMessage.folder.getUriForMsg(aMessage) - // or even - // aMessage.folder.getUriForMsg(aMsgHdr) - // would give uri - - onMessageStreamed: function (aMsgHdr, aDomNode, aMsgWindow, aMessage) { - console.log("onMessageStreamed"); - console.log("aMsgHdr: " + aMsgHdr); - console.log("Dom node: " + aDomNode); - console.log("Msg window: " + aMsgWindow); - console.log("aMessage: " + aMessage); - console.log("aMsgHdr.folder: " + aMsgHdr.folder); - // again stub.xhtml - console.log("aDomNode.baseUri = " + aDomNode.baseURI); // or .baseURIObject - - /* - var enumerator = aMsgHdr.propertyEnumerator; - while(enumerator.hasMore()) { - console.log("Property: " + enumerator.getNext()); - } - */ - - // Proof of concept, to be migrated down once works - - var product = aMsgHdr.getProperty("x-bugzilla-product"); - if(product) { - console.log("We have bugzilla bug here, trying to locate it's uri"); + let hasConversations; + try { + CU.import("resource://conversations/hook.js"); + hasConversations = true; + } catch (e) { + console.log("bugmail: Failed to import Thunderbird conversations hook, most likely this plugin is not installed. Error details: " + e); + hasConversations = false; + } + + if (hasConversations) { + console.log("Thunderbird conversations are active, installing hook for their mode"); + registerHook({ + // Called whenever some message is displayed in conversation view. + // Arguments: + // aMsgHdr: [xpconnect wrapped nsIMsgDBHdr] + // aDomNode: [object HTMLLIElement] + // aMsgWindow: [xpconnect wrapped nsIMsgWindow] + // aMessage: undefined (is to appear in newer conversations versions probably) + // + // Some interesting attributes: + // aMsgWindow.msgHeaderSink [nsIMsgHeaderSink] + // aDomNode.baseURI (wrong, "chrome://conversations/content/stub.xhtml") + // + // if I had a message, then + // aMessage.folder.getUriForMsg(aMessage) + // or even + // aMessage.folder.getUriForMsg(aMsgHdr) + // would give uri + + onMessageStreamed: function (aMsgHdr, aDomNode, aMsgWindow, aMessage) { + console.log("bugmail: onMessageStreamed called"); + /* + console.log("aMsgHdr: " + aMsgHdr); + console.log("Dom node: " + aDomNode); + console.log("Msg window: " + aMsgWindow); + console.log("aMessage: " + aMessage); + console.log("aMsgHdr.folder: " + aMsgHdr.folder); + // again stub.xhtml + console.log("aDomNode.baseUri = " + aDomNode.baseURI); // or .baseURIObject + */ /* - var doc = aDomNode.ownerDocument; - console.log("doc = " + doc); - var uri = doc.querySelector("a[href*=show_bug]").href + - "&ctype=xml&excludefield=attachmentdata"; + var enumerator = aMsgHdr.propertyEnumerator; + while(enumerator.hasMore()) { + console.log("Property: " + enumerator.getNext()); + } */ - let iframe = aDomNode.getElementsByTagName("iframe")[0]; - let iframeDoc = iframe.contentDocument; - console.log("inner document uri=" + iframeDoc.documentURI); // YES: here we have imap://.... - var uri = iframeDoc.querySelector("a[href*=show_bug]").href + - "&ctype=xml&excludefield=attachmentdata"; - console.log("uri from doc = " + uri); // YES: this is OK - bugmail.update_using_engine(0, // bypasscache, maybe bugmailStreamListener.bypassCache, - uri, - bugzillaEngine); - console.log("updated"); + + // Proof of concept, to be migrated down once works + + var product = aMsgHdr.getProperty("x-bugzilla-product"); + if(product) { + console.log("bugmail: We have bugzilla bug here, trying to locate it's uri"); + /* + var doc = aDomNode.ownerDocument; + console.log("doc = " + doc); + var uri = doc.querySelector("a[href*=show_bug]").href + + "&ctype=xml&excludefield=attachmentdata"; + */ + var iframe = aDomNode.getElementsByTagName("iframe")[0]; + var iframeDoc = iframe.contentDocument; + console.log("bugmail: Inner document uri=" + iframeDoc.documentURI); // YES: here we have imap://.... + var uri = iframeDoc.querySelector("a[href*=show_bug]").href + + "&ctype=xml&excludefield=attachmentdata"; + console.log("bugmail: uri from doc = " + uri); // YES: this is OK + bugmail.update_using_engine(0, // bypasscache, maybe bugmailStreamListener.bypassCache, + uri, + bugzillaEngine); + console.log("bugmail: display updated"); + } + + } + }); + console.log("bugmail: Conversations hook installed"); + } else { + console.log("bugmail: Thunderbird Conversations not active, so hook not installed"); + } - - } - }); -} else { - console.log("Thunderbird Conversations not active"); -} +}); \ No newline at end of file From 40894953e0156864490898549c44fdd8f4ea913d Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 15:39:37 +0100 Subject: [PATCH 11/24] Properly loading newer conversations too. Added some logging. --- chrome/content/overlay.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 8367a23..8183235 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -305,12 +305,20 @@ window.addEventListener("load", function(e) { window.addEventListener("load", function(e) { let hasConversations; + // Trying two locations of conversations hook try { + // Older CU.import("resource://conversations/hook.js"); hasConversations = true; } catch (e) { - console.log("bugmail: Failed to import Thunderbird conversations hook, most likely this plugin is not installed. Error details: " + e); - hasConversations = false; + // Newer + try { + CU.import("resource://conversations/modules/hook.js"); + hasConversations = true; + } catch(e2) { + console.log("bugmail: Failed to import Thunderbird conversations hook, most likely this plugin is not installed. Error details for older location: " + e + ", for newer location: " + e2); + hasConversations = false; + } } if (hasConversations) { From 420226218342b38d24e5a90d855dadd0a05875d1 Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 15:53:03 +0100 Subject: [PATCH 12/24] We properly load bug info, still for some reason it does not appear. --- chrome/content/overlay.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 8183235..a573155 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -151,8 +151,8 @@ var bugmail = { bugmail.storeInCache(uri, this.responseXML, this.responseText); engine.updateUI(this.responseXML, this.responseText); } - bugmail.req.onerror = function() { - console.log("bugmail: Bug info loading failed"); + bugmail.req.onerror = function(e) { + console.log("bugmail: Bug info loading failed. Status: " + e.target.status + ", text: " + this.responseText); bugmail.loading = false; document.getElementById("bugmail-throbber").setAttribute("collapsed", "true"); } @@ -377,8 +377,8 @@ window.addEventListener("load", function(e) { "&ctype=xml&excludefield=attachmentdata"; console.log("bugmail: uri from doc = " + uri); // YES: this is OK bugmail.update_using_engine(0, // bypasscache, maybe bugmailStreamListener.bypassCache, - uri, - bugzillaEngine); + bugzillaEngine, + uri); console.log("bugmail: display updated"); } From a75dc7a8dad82e2b0d4e7340919f283e02df96fb Mon Sep 17 00:00:00 2001 From: Marcin Kasperski Date: Fri, 25 Jan 2013 18:31:49 +0100 Subject: [PATCH 13/24] For the sake of testing rename various bugmail-* to buggmail-* --- chrome.manifest | 2 -- chrome/content/bugzilla.js | 4 ++-- chrome/content/flyspray.js | 2 +- chrome/content/launchpad.js | 6 +++--- chrome/content/overlay-tb2.xul | 16 ++++++++-------- chrome/content/overlay.js | 22 +++++++++++----------- chrome/content/overlay.xul | 17 ++++++++--------- chrome/content/trac.js | 2 +- chrome/skin/bugmail.css | 4 ++-- 9 files changed, 36 insertions(+), 39 deletions(-) diff --git a/chrome.manifest b/chrome.manifest index 6849fde..d9c3c4a 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -3,5 +3,3 @@ locale bugmail en-US chrome/locale/en-US/ skin bugmail default chrome/skin/ overlay chrome://messenger/content/messageWindow.xul chrome://bugmail/content/overlay.xul appversion>=3.0b3 overlay chrome://messenger/content/messenger.xul chrome://bugmail/content/overlay.xul appversion>=3.0b3 -overlay chrome://messenger/content/messageWindow.xul chrome://bugmail/content/overlay-tb2.xul appversion>=2.0 -overlay chrome://messenger/content/messenger.xul chrome://bugmail/content/overlay-tb2.xul appversion>=2.0 \ No newline at end of file diff --git a/chrome/content/bugzilla.js b/chrome/content/bugzilla.js index ad966fd..d2832fa 100644 --- a/chrome/content/bugzilla.js +++ b/chrome/content/bugzilla.js @@ -123,13 +123,13 @@ var bugzillaEngine = { updateUI: function(doc, text) { var binding = new xsltBinding(); - binding.initWithSrc("bugmail-info", doc, "chrome://bugmail/content/bugzilla.xsl", + binding.initWithSrc("buggmail-info", doc, "chrome://bugmail/content/bugzilla.xsl", function() {}, []); }, askLogin: function() { - var bundle = document.getElementById("bugmail-strings"); + var bundle = document.getElementById("buggmail-strings"); var CC = Components.classes; var CI = Components.interfaces; diff --git a/chrome/content/flyspray.js b/chrome/content/flyspray.js index f601242..a54c5ca 100644 --- a/chrome/content/flyspray.js +++ b/chrome/content/flyspray.js @@ -46,7 +46,7 @@ var flysprayEngine = { updateUI: function(doc, text) { var content = bugmail.loadHiddenIFrame(text); var binding = new xsltBinding(); - binding.initWithSrc("bugmail-info", content, "chrome://bugmail/content/flyspray.xsl", + binding.initWithSrc("buggmail-info", content, "chrome://bugmail/content/flyspray.xsl", function() {}, []); } } diff --git a/chrome/content/launchpad.js b/chrome/content/launchpad.js index ea63114..14069ae 100644 --- a/chrome/content/launchpad.js +++ b/chrome/content/launchpad.js @@ -43,12 +43,12 @@ var launchpadEngine = { var parser = new DOMParser(); var desc = parser.parseFromString(content, "text/xml"); desc.documentElement.setAttribute("class", "launchpad"); - document.getElementById("bugmail-info").appendChild(document.importNode(desc.documentElement, true)); - document.getElementById("bugmail-details").removeAttribute("collapsed"); + document.getElementById("buggmail-info").appendChild(document.importNode(desc.documentElement, true)); + document.getElementById("buggmail-details").removeAttribute("collapsed"); }, toogleDetails: function() { - var content = document.getElementById("bugmail-info").firstChild; + var content = document.getElementById("buggmail-info").firstChild; var cvalue = content.getAttribute("class"); if (cvalue == "launchpad") { content.setAttribute("class", "launchpad-full"); diff --git a/chrome/content/overlay-tb2.xul b/chrome/content/overlay-tb2.xul index dc3ab38..1e363e2 100644 --- a/chrome/content/overlay-tb2.xul +++ b/chrome/content/overlay-tb2.xul @@ -21,7 +21,7 @@ --> -