DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
<?xml version="1.0"?>
<!--
   - ***** 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 "License"); you may not use this file except in compliance with
   - the License. You may obtain a copy of the License at
   - http://www.mozilla.org/MPL/
   -
   - Software distributed under the License is distributed on an "AS IS" basis,
   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   - for the specific language governing rights and limitations under the
   - License.
   -
   - The Original Code is Mail folder code.
   -
   - The Initial Developer of the Original Code is
   -   Joey Minta <jminta@gmail.com>
   - Portions created by the Initial Developer are Copyright (C) 2008
   - the Initial Developer. All Rights Reserved.
   -
   - Contributor(s):
   -
   - 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 *****
-->

<bindings id="mailFolderBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:html="http://www.w3.org/1999/xhtml"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="folder-menupopup"
           extends="chrome://global/content/bindings/popup.xml#popup">
    <implementation>
      <constructor><![CDATA[
        // If we are a child of a menulist, we need to build our content right
        // away, otherwise the menulist won't have proper sizing
        if (this.parentNode && this.parentNode.localName == "menulist")
          this._ensureInitialized();
      ]]></constructor>
      <!-- 
         - Make sure we remove our listener when the window is being destroyed
        -->
      <destructor><![CDATA[
        if (!this._initialized)
          return;

        const Cc = Components.classes;
        const Ci = Components.interfaces;
        var session = Cc["@mozilla.org/messenger/services/session;1"].
                      getService(Ci.nsIMsgMailSession);
        session.RemoveFolderListener(this._listener);
      ]]></destructor>

      <!--
         - If non-null, the subFolders of this nsIMsgFolder will be used to
         - populate this menu.  If this is null, the menu will be populated
         - using the root-folders for all accounts
        -->
      <field name="_parentFolder">null</field>
      <property name="parentFolder"
                onget="return this._parentFolder;"
                onset="return this._parentFolder = val;"/>

      <!--
         - Various filtering modes can be used with this menu-binding.  To use
         - one of them, append the mode="foo" attribute to the element.  When
         - building the menu, we will then use this._filters[mode] as a filter
         - function to eliminate folders that should not be shown.
         -
         - Note that extensions should feel free to plug in here!
        -->
      <field name="_filters"><![CDATA[({
        // Returns true if messages can be filed in the folder
        filing: function filter_filing(aFolder) {
          if (!aFolder.server.canFileMessagesOnServer)
            return false;

          return (aFolder.canFileMessages || aFolder.hasSubFolders);
        },

        // Returns true if we can get mail for this folder. (usually this just
        // means the "root" fake folder)
        getMail: function filter_getMail(aFolder) {
          if (aFolder.isServer && aFolder.server.type != "none")
            return true;
          if (aFolder.server.type == "nntp" || aFolder.server.type == "rss")
            return true;
          return false;
        },

        // Returns true if we can add filters to this folder/account
        filters: function filter_filter(aFolder) {
          // We can always filter news
          if (aFolder.server.type == "nntp")
            return true;

          return aFolder.server.canHaveFilters;
        },

        subscribe: function filter_subscribe(aFolder) {
          return aFolder.canSubscribe;
        },

        newFolder: function filter_newFolder(aFolder) {
          return aFolder.canCreateSubfolders &&
                 aFolder.server.canCreateFoldersOnServer;
        },

        defered: function filter_defered(aFolder) {
          return aFolder.server.canCreateFoldersOnServer &&
                 !aFolder.supportsOffline;
        },

        junk: function filter_junk(aFolder) {
          return aFolder.canFileMessages && aFolder.canSearchMessages;
        }
      })]]></field>

      <!--
         - The maximum number of entries in the "Recent" menu
        -->
      <field name="_MAXRECENT">15</field>

      <!--
         - Our listener to let us know when folders change/appear/disappear so
         - we can know to rebuild ourselves.
        -->
      <field name="_listener"><![CDATA[({
        _menu: this,
        OnItemAdded: function act_add(aRDFParentItem, aItem) {
          if (!(aItem instanceof Components.interfaces.nsIMsgFolder))
            return;
          if (this._filterFunction && !this._filterFunction(aItem)) {
            return;
          }
          //xxx we can optimize this later
          //xxx I'm not quite sure why this isn't always a function
          if (this._menu._teardown)
            this._menu._teardown();
        },
  
        OnItemRemoved: function act_remove(aRDFParentItem, aItem) {
          if (!(aItem instanceof Components.interfaces.nsIMsgFolder))
            return;
          if (this._filterFunction && !this._filterFunction(aItem)) {
            return;
          }
          //xxx we can optimize this later
          if (this._menu._teardown)
            this._menu._teardown();
        },

        //xxx I stole this listener list from nsMsgFolderDatasource.cpp, but
        //    someone should really document what events are fired when, so that
        //    we make sure we're updating at the right times.
        OnItemPropertyChanged: function(aItem, aProperty, aOld, aNew) {},
        OnItemIntPropertyChanged: function(aItem, aProperty, aOld, aNew) {
          var child = this._getChildForItem(aItem);
          if (child) {
            child._folder = aItem;
            this._menu._setCssSelectors(child, child._folder);
          }
        },
        OnItemBoolPropertyChanged: function(aItem, aProperty, aOld, aNew) {
          var child = this._getChildForItem(aItem);
          if (child) {
            child._folder = aItem;
            this._menu._setCssSelectors(child, child._folder);
          }
        },
        OnItemUnicharPropertyChanged: function(aItem, aProperty, aOld, aNew) {
          var child = this._getChildForItem(aItem);
          if (child) {
            child._folder = aItem;
            this._menu._setCssSelectors(child, child._folder);
          }
        },
        OnItemPropertyFlagChanged: function(aItem, aProperty, aOld, aNew) {},
        OnItemEvent: function(aFolder, aEvent) {
          var child = this._getChildForItem(aFolder);
          if (child) {
            // Special casing folder renames here, since they require more work
            // since sort-order may have changed
            if (aEvent.toString() == "RenameCompleted") {
              this._menu._teardown();
              this._menu._ensureInitialized();
              return;
            }
          }
        },

        /**
         * Helper function to check and see whether we have a menuitem for this
         * particular nsIMsgFolder
         *
         * @param aItem  the nsIMsgFolder to check
         * @returns      null if no child for that folder exists, otherwise the
         *              menuitem for that child
         */
        _getChildForItem: function act__itemIsChild(aItem) {
          if (!this._menu || !this._menu._initialized)
            return null;

           if (!(aItem instanceof Components.interfaces.nsIMsgFolder))
             return null;
           for (var i = 0; i < this._menu.childNodes; i++) {
             var folder = this._menu.childNodes[i]._folder;
             if (folder && folder.URI == aItem.URI)
               return aItem;
           }
           return null;
        }
      })]]></field>

      <!-- 
         - True if we have already built our menu-items and are now just
         - listening for changes
        -->
      <field name="_initialized">false</field>

      <!--
         - Call this if you are unsure whether the menu-items have been built,
         - but know that they need to be built now if they haven't.
        -->
      <method name="_ensureInitialized">
        <body><![CDATA[
          if (this._initialized)
            return;

          // I really wish they'd just make this global...
          const Cc = Components.classes;
          const Ci = Components.interfaces;

          var folders = new Array();

          // Figure out which folders to build.  If we don't have a parent, then
          // we assume we should build the top-level accounts.  (Actually we
          // build the fake root folders for those accounts.)
          if (!this._parentFolder) {
            var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"].
                          getService(Ci.nsIMsgAccountManager);
            var count = acctMgr.accounts.Count();

            // Sadly, the accountMgr doesn't provide us we a sorted list of
            // accounts.  We have to get them in the right order on our own. To
            // Do this, we'll stick them in an array, and then sort that array.
            var accounts = new Array();
            for (var i = 0; i < count; i++) {
              var acct = acctMgr.accounts.GetElementAt(i).QueryInterface(Ci.nsIMsgAccount);

              // This is a HACK to work around bug 41133. If we have one of the
              // dummy "news" accounts there, that account won't have an
              // incomingServer attached to it, and everything will blow up.
              if (acct.incomingServer)
                accounts.push(acct);
            }

            /**
             * This is our actual function for sorting accounts.  Accounts go
             * in the following order: (1) default account (2) other mail
             * accounts (3) Local Folders (4) news
             */
            function accountCompare(a, b) {
              if (a.key == acctMgr.defaultAccount.key)
                return -1;
              if (b.key == acctMgr.defaultAccount.key)
                return 1;
              var aIsNews = a.incomingServer.type == "nntp";
              var bIsNews = b.incomingServer.type == "nntp";
              if (aIsNews && !bIsNews)
                return 1;
              if (bIsNews && !aIsNews)
                return -1;

              var aIsLocal = a.incomingServer.type == "none";
              var bIsLocal = b.incomingServer.type == "none";
              if (aIsLocal && !bIsLocal)
                return 1;
              if (bIsLocal && !aIsLocal)
                return -1;
              return 0;
            }
            accounts = accounts.sort(accountCompare);

            // Now generate our folder-list.  Note that we'll special case this
            // situation below, to avoid destroying the sort order we just made
            for each (var acct in accounts) {
              folders.push(acct.incomingServer.rootFolder);
            }
          } else {
            // If we do have a parent folder, then we just build based on those
            // subFolders for that parent
            var myenum = this._parentFolder.subFolders;
            while (myenum.hasMoreElements()) {
              folders.push(myenum.getNext().QueryInterface(Ci.nsIMsgFolder));
            }
          }

          this._build(folders);

          // Lastly, we add a listener to get notified of changes in the folder
          // structure.
          var session = Cc["@mozilla.org/messenger/services/session;1"].
                        getService(Ci.nsIMsgMailSession);
          session.AddFolderListener(this._listener, Ci.nsIFolderListener.all);

          this._initialized = true;
        ]]></body>
      </method>

      <!--
         - Actually constructs the menu-items based on the folders given
         -
         - @param aFolders  an array of nsIMsgFolders to use for building
        -->
      <method name="_build">
        <parameter name="aFolders"/>
        <body><![CDATA[
          var folders;
          // Extensions and other consumers can add to these modes too, see the
          // above note on the _filters field.
          var mode = this.getAttribute("mode");
          if (mode && mode != "") {
            var filterFunction = this._filters[mode];
            folders = aFolders.filter(filterFunction);
            this._listener._filterFunction = filterFunction;
          } else {
            folders = aFolders;
          }

          // I'm not entirely happy about having to hard-code this as an attr,
          // but there doesn't seem to be a better way.
          if (this.getAttribute("showFileHereLabel") == "true" &&
              this._parentFolder && 
              ((this._parentFolder.noSelect || this._parentFolder.canFileMessages) ||
               mode == "newFolder")) {
            var menuitem = document.createElement("menuitem");
            menuitem._folder = this._parentFolder;
            menuitem.setAttribute("label", this.getAttribute("fileHereLabel"));
            menuitem.setAttribute("accesskey", this.getAttribute("fileHereAccessKey"));
            // Eww. have to support some legacy code here...
            menuitem.setAttribute("id", this._parentFolder.URI);
            this.appendChild(menuitem);

            if (this._parentFolder.noSelect)
              menuitem.setAttribute("disabled", "true");

            this.appendChild(document.createElement("menuseparator"));
          }

          // Some menus want a "Recent" option, but that should only be on our
          // top-level menu
          if (!this._parentFolder && this.getAttribute("showRecent") == "true") {
            this._buildRecentMenu();
          }

          /**
           * Sorts the list of folders. We give first priority to the sortKey
           * property, and then via a case-insensitive comparison of names
           */
          function nameCompare(a, b) {
            var sortKey = a.compareSortKeys(b);
            if (sortKey)
              return sortKey;
            return a.prettyName.toLowerCase() > b.prettyName.toLowerCase();
          }

          /**
           * If we're the root of the folder hierarchy, then we actually don't
           * want to sort the folders, but rather the accounts to which the
           * folders belong.  Since that sorting was already done, we don't need
           * to do anything for that case here
           */
          if (this._parentFolder)
            folders = folders.sort(nameCompare);

          for each (var folder in folders) {
            var node;
            // If we're going to add subFolders, we need to make menus, not
            // menuitems.
            if (!folder.hasSubFolders || this.getAttribute("expandFolders") == "false") {
              node = document.createElement("menuitem");
              // Grumble, grumble, legacy code support
              node.setAttribute("id", folder.URI);
              node.setAttribute("class", "folderMenuItem menuitem-iconic");
              this.appendChild(node);
            } else {
              //xxx this is slightly problematic in that we haven't confirmed
              //    whether any of the subfolders will pass the filter
              node = document.createElement("menu");
              node.setAttribute("class", "folderMenuItem menu-iconic");
              this.appendChild(node);
              var popup = this.cloneNode(true);
              popup._teardown();
              node.appendChild(popup);
              popup.parentFolder = folder;
            }
            node._folder = folder;
            node.setAttribute("label", folder.prettyName);

            this._setCssSelectors(folder, node);

            //xxx for later optimization
            //builtFolders.push(folder);
          }
        ]]></body>
      </method>

      <!--
         - Builds a submenu with all of the recently used folders in it, to
         - allow for easy access.
        -->
      <method name="_buildRecentMenu">
        <body><![CDATA[
          const Cc = Components.classes;
          const Ci = Components.interfaces;
          // Iterate through all folders in all accounts, and check MRU_Time,
          // then take the most current 15.

          /**
           * This function will iterate through any existing sub-folders and
           * (1) check if they're recent and (2) recursively call this function
           * to iterate through any sub-sub-folders.
           *
           * @param aFolder  the folder to check
           */
          function checkSubFolders(aFolder) {
            if (!aFolder.hasSubFolders)
              return;

            var myenum = aFolder.subFolders;
            while (myenum.hasMoreElements()) {
              var folder = myenum.getNext().QueryInterface(Ci.nsIMsgFolder);
              addIfRecent(folder);
              checkSubFolders(folder);
            }
          }

          var recentFolders = [];
          var oldestTime = 0;

          /**
           * This function will add a folder to the recentFolders array if it
           * is among the 15 most recent.  If we exceed 15 folders, it will pop
           * the oldest folder, ensuring that we end up with the right number
           *
           * @param aFolder the folder to check
           */
          var menu = this;
          function addIfRecent(aFolder) {
            if (!aFolder.canFileMessages)
              return;

            var time = 0;
            try {
              time = aFolder.getStringProperty("MRUTime");
            } catch(ex) {}
            if (time <= oldestTime)
              return;

            if (recentFolders.length == menu._MAXRECENT) {
              recentFolders.sort(sorter);
              recentFolders.pop();
              oldestTime = recentFolders[recentFolders.length-1].getStringProperty("MRUTime");
            }
            recentFolders.push(aFolder);
          }

          // Start iterating at the top of the hierarchy, that is, with the root
          // folders for each account.
          var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"].
                        getService(Ci.nsIMsgAccountManager);
          var count = acctMgr.accounts.Count();
          for (var i = 0; i < count; i++) {
            var acct = acctMgr.accounts.GetElementAt(i).QueryInterface(Ci.nsIMsgAccount);
            addIfRecent(acct.incomingServer.rootFolder);
            checkSubFolders(acct.incomingServer.rootFolder);
          }

          function sorter(a, b) {
             return a.getStringProperty("MRUTime") < b.getStringProperty("MRUTime");
          }
          recentFolders.sort(sorter);

          // Because we're scanning across multiple accounts, we can end up with
          // two folders with the same name.  In this case, we append the name
          // of the account as well, to distingiush.
          var dupeNames = [];
          for (var i = 0; i < recentFolders.length; i++) {
            for (var j = i + 1; j < recentFolders.length; j++) {
              // We can end up with the same name in dupeNames more than once,
              // but that's ok.
              if (recentFolders[i].prettyName == recentFolders[j].prettyName)
                dupeNames.push(recentFolders[i].prettyName);
            }
          }

          // Now create the Recent folder and its children
          var menu = document.createElement("menu");
          menu.setAttribute("label", this.getAttribute("recentLabel"));
          menu.setAttribute("accesskey", this.getAttribute("recentAccessKey"));
          var popup = document.createElement("menupopup");
          menu.appendChild(popup);

          // Create entries for each of the recent folders.
          for each (var folder in recentFolders) {
            var node = document.createElement("menuitem");

            var label = folder.prettyName;
            if (dupeNames.indexOf(label) != -1)
              label += " - " + folder.server.prettyName;
            node.setAttribute("label", label);
            node._folder = folder;

            node.setAttribute("class", "folderMenuItem menuitem-iconic");
            this._setCssSelectors(folder, node);
            popup.appendChild(node);
          }
          this.appendChild(menu);
          var sep = document.createElement("menuseparator");
          this.appendChild(sep);
        ]]></body>
      </method>

      <!--
         - This function adds attributes on menu/menuitems to make it easier for
         - css to style them.
         -
         - @param aFolder    the folder that corresponds to the menu/menuitem
         - @param aMenuNode  the actual DOM node to set attributes on
        -->
      <method name="_setCssSelectors">
        <parameter name="aFolder"/>
        <parameter name="aMenuNode"/>
        <body><![CDATA[
          const Ci = Components.interfaces;
          // First set the SpecialFolder attribute
          // Sigh... why aren't these in an IDL somewhere public?
          if (aFolder.flags & 0x1000) // MSG_FOLDER_FLAG_INBOX
            aMenuNode.setAttribute("SpecialFolder", "Inbox");
          else if (aFolder.flags & 0x0100) // MSG_FOLDER_FLAG_TRASH
            aMenuNode.setAttribute("SpecialFolder", "Trash");
          else if (aFolder.flags & 0x0800) // MSG_FOLDER_FLAG_QUEUE
            aMenuNode.setAttribute("SpecialFolder", "Unsent Messages");
          else if (aFolder.flags & 0x0200) // MSG_FOLDER_FLAG_SENTMAIL
            aMenuNode.setAttribute("SpecialFolder", "Sent");
          else if (aFolder.flags & 0x0400) // MSG_FOLDER_FLAG_DRAFTS
            aMenuNode.setAttribute("SpecialFolder", "Drafts");
          else if (aFolder.flags & 0x400000) // MSG_FOLDER_FLAG_TEMPLATES
            aMenuNode.setAttribute("SpecialFolder", "Templates");
          else if (aFolder.flags & 0x40000000) // MSG_FOLDER_FLAG_JUNK
            aMenuNode.setAttribute("SpecialFolder", "Junk");
          else if (aFolder.flags & 0x0020) // MSG_FOLDER_FLAG_VIRTUAL
            aMenuNode.setAttribute("SpecialFolder", "Virtual");
          else
            aMenuNode.setAttribute("SpecialFolder", "none");

          // Now set the biffState
          var biffStates = ["NewMail", "NoMail", "UnknownMail"];
          for each (var state in biffStates) {
            if (aFolder.biffState == Ci.nsIMsgFolder["nsMsgBiffState_" + state]) {
              aMenuNode.setAttribute("BiffState", state);
              break;
            }
          }

          // IsServer is simple
          aMenuNode.setAttribute("IsServer", aFolder.isServer);

          // We have to work a bit for IsSecure.  This sucks
          var server = aFolder.server;
          if (server instanceof Ci.nsINntpIncomingServer) {
            aMenuNode.setAttribute("IsSecure", server.isSecure);
          } else {
            // If it's not a news-server, apparently we look at the socket type
            var sock = server.socketType;
            var isSecure = (sock == Ci.nsIMsgIncomingServer.alwaysUseTLS ||
                            sock == Ci.nsIMsgIncomingServer.useSSL);
            aMenuNode.setAttribute("IsSecure", isSecure);
          }

          // the ServerType attribute
          aMenuNode.setAttribute("ServerType", aFolder.server.type);
        ]]></body>
      </method>

      <!--
         - Makes a given folder selected.
         -
         - @param aFolder  the folder to select
         - @note If aFolder is not in this popup, but is instead a descendant of
         -       a member of the popup, that ancestor will be selected.
        -->
      <method name="selectFolder">
        <parameter name="aFolder"/>
        <body><![CDATA[
          for (var i in this.childNodes) {
            var child = this.childNodes[i];
            if (!child || !child._folder)
              continue;
            if (child._folder.URI == aFolder.URI || (this._parentFolder &&
                this._parentFolder.isAncestorOf(aFolder))) {
              // Making an assumption about our DOM positioning here.
              this.parentNode.selectedIndex = i;
              return;
            }
          }
          throw "unable to find folder to select!";
        ]]></body>
      </method>

      <!--
         - Removes all menu-items for this popup, resets all fields, and
         - removes the listener.  This function is invoked when a change
         - that affects this menu is detected by our listener, or during
         - initialization of cloned children to reset them to their
         - initial state.  In the case of cloned children, this._initialized
         - will be false on entry, but they will possess child nodes.
        -->
      <method name="_teardown">
        <body><![CDATA[
          while(this.hasChildNodes())
            this.removeChild(this.lastChild);

          if (this._initialized) {
            const Cc = Components.classes;
            const Ci = Components.interfaces;
            var session = Cc["@mozilla.org/messenger/services/session;1"].
                          getService(Ci.nsIMsgMailSession);
            session.RemoveFolderListener(this._listener);
          }

          this._folders = null;
          this._initialized = false;
        ]]></body>
      </method>
    </implementation>

    <handlers>
      <!--
         - In order to improve performance, we're not going to build any of the
         - menu until we're shown (unless we're the child of a menulist, see
         - note in the constructor).
         -
         - @note _ensureInitialized can be called repeatedly without issue, so
         -       don't worry about it here.
        -->
      <handler event="popupshowing" phase="capturing">
        this._ensureInitialized();
      </handler>
    </handlers>
  </binding>
</bindings>