<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -36,18 +36,20 @@
 const EXTENSION_ID = &quot;bugzillalinkgrabber@bryan.clark&quot;;
 
 var bugzillalinkgrabber = {
-  initialized: false,
   strings: null,
 
   onLoad: function() {
     // initialization code
-    this.initialized = true;
     this.strings = document.getElementById(&quot;bugzillalinkgrabber-strings&quot;);
 
-    document.getElementById(&quot;messagePaneContext&quot;).
-             addEventListener(&quot;popupshowing&quot;, function(e) { bugzillalinkgrabber.showContextMenu(e); }, false);
+    var cx = document.getElementById('threadPaneContext') ||
+             document.getElementById('mailContext');
+    if (cx)
+      cx.addEventListener(&quot;popupshowing&quot;, function(e) { bugzillalinkgrabber.showContextMenu(e); }, false);
 
-    Application.events.addListener(&quot;messageShow&quot;, bugzillalinkgrabber);
+    Components.classes[&quot;@mozilla.org/observer-service;1&quot;]
+              .getService(Components.interfaces.nsIObserverService)
+              .addObserver(this, &quot;MsgMsgDisplayed&quot;, false);
   },
 
   showContextMenu: function(event) {
@@ -89,23 +91,49 @@ var bugzillalinkgrabber = {
     var cDoc = document.getElementById('messagepane').contentDocument;
     var anchor = cDoc.createElementNS(&quot;http://www.w3.org/1999/xhtml&quot;, &quot;html:a&quot;);
         // Application.extensions.get(EXTENSION_ID).prefs.get(&quot;default.url&quot;).value.replace(&quot;%s&quot;, number)
-        anchor.setAttribute(&quot;href&quot;, Application.prefs.get(&quot;extensions.&quot;+EXTENSION_ID+&quot;.default.url&quot;).value.replace(&quot;%s&quot;, number));
+        anchor.setAttribute(&quot;href&quot;, Application.extensions.get(EXTENSION_ID).prefs.get(&quot;default.url&quot;).value.replace(&quot;%s&quot;, number));
         anchor.setAttribute(&quot;class&quot;, &quot;bugzilla-link&quot;);
         anchor.setAttribute(&quot;target&quot;, &quot;_content&quot;);
         anchor.setAttribute(&quot;title&quot;, &quot;(we'll be getting the title soon!)&quot;);
         anchor.appendChild(cDoc.createTextNode(bugMatch));
     return anchor;
   },
-  handleEvent : function (event) {
-    // FIXME: for now we can just assume the message has rendered in the message pane
+  createBugCommentAnchor : function(number, comment) {
+    var cDoc = document.getElementById('messagepane').contentDocument;
+    var anchor = cDoc.createElementNS(&quot;http://www.w3.org/1999/xhtml&quot;, &quot;html:a&quot;);
+        anchor.setAttribute(&quot;href&quot;, Application.extensions.get(EXTENSION_ID).prefs.get(&quot;default.url&quot;).value.replace(&quot;%s&quot;, number) + &quot;#c&quot; + comment);
+        anchor.setAttribute(&quot;class&quot;, &quot;bugzilla-link&quot;);
+        anchor.setAttribute(&quot;target&quot;, &quot;_content&quot;);
+        anchor.setAttribute(&quot;title&quot;, &quot;(we'll be getting the title soon!)&quot;);
+        anchor.appendChild(cDoc.createTextNode(&quot;Comment #&quot; + comment));
+    return anchor;
+  },
+
+  observe: function(aSubject, aTopic, aData) {
+    // FIXME: for now we just assume the message has rendered in the message pane
+    var bug = &quot;&quot;;
+    var body = &quot;&quot;;
+    var cDoc = null;
 
     try {
-      // Reach in and grab the Nodes we need
-      var cDoc = document.getElementById('messagepane').contentDocument;
+      cDoc = document.getElementById('messagepane').contentDocument;
       var msgHTMLDoc = cDoc.childNodes.item(0);
-      var text = msgHTMLDoc.childNodes.item(1).textContent;  // this is the BODY node text
+      body = msgHTMLDoc.childNodes.item(1).textContent;  // this is the BODY node text
+    } catch (e) { Application.console.log(&quot;couldn't get the body of the message&quot;); return; }
+
+    try {
+      var hdr = messenger.msgHdrFromURI(aData);
+      var subjectx = /\[Bug (\d+)\]/g;
+      var subjectMatches = subjectx.exec(hdr.mime2DecodedSubject)
+      if (subjectMatches) {
+
+        bug = subjectMatches[1];
+      }
+    } catch(e) { Application.console.log(e); }
+
+    try {
       var bugx = /(?:\s|\W|^)(bug\s+#?\d{3,6})/ig;
-      var bugMatches = bugx.exec(text);
+      var bugMatches = bugx.exec(body);
 
       if (bugMatches) {
         // A snapshot is necessary because we are going to mess with the DOM as we traverse
@@ -121,7 +149,23 @@ var bugzillalinkgrabber = {
             }
           }
         }
+      }
+    } catch (e) { Application.console.log(e); }
 
+    try {
+      var commentx = /--- Comment #(\d+) from/g;
+      var commentMatches = commentx.exec(body);
+      if (commentMatches &amp;&amp; bug != &quot;&quot;) {
+        var nodesSnapshot = cDoc.evaluate(&quot;//text()&quot;, cDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE , null );
+        for ( var i=0 ; i &lt; nodesSnapshot.snapshotLength; i++ ) {
+          var nssi = nodesSnapshot.snapshotItem(i);
+          if ( nssi.textContent.indexOf(&quot;Comment #&quot; + commentMatches[1]) != -1 ) {
+            var t = nssi.splitText(nssi.textContent.indexOf(&quot;Comment #&quot; + commentMatches[1]));
+            t.replaceData(t.textContent.indexOf(&quot;Comment #&quot; + commentMatches[1]),(&quot;Comment #&quot; + commentMatches[1]).length, &quot;&quot;);
+            nssi.parentNode.insertBefore(this.createBugCommentAnchor(bug, commentMatches[1]),t);
+            break;
+          }
+        }
       }
     } catch (e) { Application.console.log(e); }
 
@@ -138,3 +182,4 @@ var bugzillalinkgrabber = {
    },
 };
 window.addEventListener(&quot;load&quot;, function(e) { bugzillalinkgrabber.onLoad(e); }, false);
+//Application.events.addListener(&quot;load&quot;, function(e) { bugzillalinkgrabber.onLoad(e); });</diff>
      <filename>content/overlay.js</filename>
    </modified>
    <modified>
      <diff>@@ -44,7 +44,7 @@
     &lt;stringbundle id=&quot;bugzillalinkgrabber-strings&quot; src=&quot;chrome://bugzillalinkgrabber/locale/bugzillalinkgrabber.properties&quot;/&gt;
   &lt;/stringbundleset&gt;
 
-  &lt;popup id=&quot;messagePaneContext&quot;&gt;
+  &lt;popup id=&quot;mailContext&quot;&gt;
     &lt;menuitem id=&quot;context-bugzillalinkgrabber&quot; label=&quot;&amp;bugzillalinkgrabberContext.label;&quot;
               oncommand=&quot;bugzillalinkgrabber.onMenuItemCommand(gContextMenu.linkURL)&quot;/&gt;
   &lt;/popup&gt;</diff>
      <filename>content/thunderbirdOverlay.xul</filename>
    </modified>
    <modified>
      <diff>@@ -4,15 +4,15 @@
   &lt;Description about=&quot;urn:mozilla:install-manifest&quot;&gt;
     &lt;em:id&gt;bugzillalinkgrabber@bryan.clark&lt;/em:id&gt;
     &lt;em:name&gt;Bugzilla Link Grabber&lt;/em:name&gt;
-    &lt;em:version&gt;1.1&lt;/em:version&gt;
+    &lt;em:version&gt;1.2&lt;/em:version&gt;
     &lt;em:creator&gt;Bryan Clark&lt;/em:creator&gt;
     &lt;em:description&gt;Extracts and cleans bugzilla links from Thunderbird Messages&lt;/em:description&gt;
     &lt;em:optionsURL&gt;chrome://bugzillalinkgrabber/content/options.xul&lt;/em:optionsURL&gt;
     &lt;em:targetApplication&gt;
       &lt;Description&gt;
         &lt;em:id&gt;{3550f703-e582-4d05-9a08-453d09bdfdc6}&lt;/em:id&gt; &lt;!-- thunderbird --&gt;
-        &lt;em:minVersion&gt;2.20.*&lt;/em:minVersion&gt;
-        &lt;em:maxVersion&gt;3.0a1pre&lt;/em:maxVersion&gt;
+        &lt;em:minVersion&gt;3.0b3pre&lt;/em:minVersion&gt;
+        &lt;em:maxVersion&gt;3.1a1pre&lt;/em:maxVersion&gt;
       &lt;/Description&gt;
     &lt;/em:targetApplication&gt;
   &lt;/Description&gt;</diff>
      <filename>install.rdf</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1299066f449976644ee1fe94f5886f9dc7b121f7</id>
    </parent>
  </parents>
  <author>
    <name>Bryan Clark</name>
    <email>clarkbw@gnome.org</email>
  </author>
  <url>http://github.com/clarkbw/thunderbird-bugzilla-link-grabber/commit/63d17a773bf2840ccbc9e979346623f3a5d90a5b</url>
  <id>63d17a773bf2840ccbc9e979346623f3a5d90a5b</id>
  <committed-date>2009-08-20T11:57:04-07:00</committed-date>
  <authored-date>2009-08-20T11:57:04-07:00</authored-date>
  <message>fix up issues with using STEEL as landed in TB3b3 and not the STEEL as was an extension</message>
  <tree>2586fb6f647875d7cac77fe99239afdcad974383</tree>
  <committer>
    <name>Bryan Clark</name>
    <email>clarkbw@gnome.org</email>
  </committer>
</commit>
