Index: src/orca/scripts/apps/Thunderbird/script.py
===================================================================
--- src/orca/scripts/apps/Thunderbird/script.py	(revision 4094)
+++ src/orca/scripts/apps/Thunderbird/script.py	(working copy)
@@ -250,11 +250,32 @@
         # Handle a newly-opened message.
         #
         if event.source.getRole() == pyatspi.ROLE_DOCUMENT_FRAME \
-           and orca_state.locusOfFocus.getRole() == pyatspi.ROLE_FRAME \
-           and self._messageLoaded:
-            consume = True
-            self._presentMessage(event.source)
+           and orca_state.locusOfFocus.getRole() == pyatspi.ROLE_FRAME:
+            if self._messageLoaded:
+                consume = True
+                self._presentMessage(event.source)
 
+            # If the user just gave focus to the message window (e.g. by
+            # Alt+Tabbing back into it), we might have an existing caret
+            # context. But we'll need the document frame in order to verify
+            # this. Therefore try to find the document frame.
+            #
+            elif self.getCaretContext() == [None, -1]:
+                documentFrame = None
+                for child in orca_state.locusOfFocus:
+                    if child.getRole() == pyatspi.ROLE_INTERNAL_FRAME \
+                       and child.childCount \
+                       and child[0].getRole() == pyatspi.ROLE_DOCUMENT_FRAME:
+                        documentFrame = child[0]
+                        break
+                try:
+                    contextObj, contextOffset = \
+                        self._documentFrameCaretContext[hash(documentFrame)]
+                    if contextObj:
+                        orca.setLocusOfFocus(event, contextObj)
+                except:
+                    pass
+
         if not consume:
             Gecko.Script.onFocus(self, event)
 
Index: src/orca/scripts/toolkits/Gecko/script.py
===================================================================
--- src/orca/scripts/toolkits/Gecko/script.py	(revision 4094)
+++ src/orca/scripts/toolkits/Gecko/script.py	(working copy)
@@ -1712,6 +1712,16 @@
             #
             self.presentLine(obj, characterOffset)
 
+    def onWindowDeactivated(self, event):
+        """Called whenever a toplevel window is deactivated.
+
+        Arguments:
+        - event: the Event
+        """
+
+        self._objectForFocusGrab = None
+        default.Script.onWindowDeactivated(self, event)
+
     def handleProgressBarUpdate(self, event, obj):
         """Determine whether this progress bar event should be spoken or not.
         For Firefox, we don't want to speak the small "page load" progress
@@ -5028,7 +5038,7 @@
         #
         documentFrame = self.getDocumentFrame()
         if documentFrame:
-            self._documentFrameCaretContext[documentFrame] = caretContext
+            self._documentFrameCaretContext[hash(documentFrame)] = caretContext
 
         if caretContext == [obj, characterOffset]:
             return
