docs: function handleWindow(type, text, callback, dontClose) {
    // Set the window opener function to use depending on the type
    var func_ptr = null;
    switch (type) {
      case "type":
        func_ptr = mozmill.utils.getWindowByType;
        break;
      case "title":
        func_ptr = mozmill.utils.getWindowByTitle;
        break;
      default:
        throw new Error(arguments.callee.name + ": Unknown opener type - " + type);
    }
  
    var window = null;
    var controller = null;
  
    try {
      // Wait until the window has been opened
      mozmill.utils.waitFor(function () {
        window = func_ptr(text);
        return window != null;
      }, "Window has been found.");
  
      // XXX: We still have to find a reliable way to wait until the new window
      // content has been finished loading. Let's wait for now.
      controller = new mozmill.controller.MozMillController(window);
      controller.sleep(200);
  
      if (callback) {
        callback(controller);
      }
  
      // Check if we have to close the window
      dontClose = dontClose || false;
      if (dontClose == false & window != null) {
        controller.window.close();
        mozmill.utils.waitFor(function () {
          return func_ptr(text) != window;
        }, "Window has been closed.");
  
        window = null;
        controller = null;
      }
  
      return controller;
    } catch (ex) {
      if (window)
        window.close();
  
      throw ex;
    }
  }