Index: src/orca/scripts/apps/Thunderbird/script.py
===================================================================
--- src/orca/scripts/apps/Thunderbird/script.py	(revision 4002)
+++ src/orca/scripts/apps/Thunderbird/script.py	(working copy)
@@ -234,6 +234,23 @@
                 if string == "Delete":
                     oldLocusOfFocus = None
 
+        # If the user has just deleted an open mail message, then we want to
+        # try to speak the new name of the open mail message frame.
+        # See bug #540039 for more details.
+        #
+        rolesList = [pyatspi.ROLE_DOCUMENT_FRAME, \
+                     pyatspi.ROLE_INTERNAL_FRAME, \
+                     pyatspi.ROLE_FRAME, \
+                     pyatspi.ROLE_APPLICATION]
+        if self.isDesiredFocusedItem(event.source, rolesList):
+            if isinstance(orca_state.lastInputEvent, input_event.KeyboardEvent):
+                string = orca_state.lastNonModifierKeyEvent.event_string
+                if string == "Delete":
+                    oldLocusOfFocus = None
+                    state = newLocusOfFocus.getState()
+                    if state.contains(pyatspi.STATE_DEFUNCT):
+                        newLocusOfFocus = event.source
+
         # Pass the event onto the parent class to be handled in the default way.
 
         Gecko.Script.locusOfFocusChanged(self, event,
@@ -319,6 +336,26 @@
 
         obj = event.source
 
+        # If the user has just deleted an open mail message, then we want to
+        # try to speak the new name of the open mail message frame and also
+        # present the first line of that message to be consistent with what
+        # we do when a new message window is opened. See bug #540039 for more
+        # details.
+        #
+        rolesList = [pyatspi.ROLE_DOCUMENT_FRAME, \
+                     pyatspi.ROLE_INTERNAL_FRAME, \
+                     pyatspi.ROLE_FRAME, \
+                     pyatspi.ROLE_APPLICATION]
+        if self.isDesiredFocusedItem(event.source, rolesList):
+            if isinstance(orca_state.lastInputEvent, input_event.KeyboardEvent):
+                string = orca_state.lastNonModifierKeyEvent.event_string
+                if string == "Delete":
+                    speech.speak(obj.name)
+                    [obj, offset] = self.findFirstCaretContext(obj, 0)
+                    self.setCaretPosition(obj, offset)
+                    self.presentLine(obj, offset)
+                    return
+
         # If we get a "object:property-change:accessible-name" event for 
         # the first item in the Suggestions lists for the spell checking
         # dialog, then speak the first two labels in that dialog. These
Index: src/orca/scripts/toolkits/Gecko/script.py
===================================================================
--- src/orca/scripts/toolkits/Gecko/script.py	(revision 4002)
+++ src/orca/scripts/toolkits/Gecko/script.py	(working copy)
@@ -2680,10 +2680,14 @@
         """Returns the URI of the document frame that is active."""
         documentFrame = self.getDocumentFrame()
         if documentFrame:
-            attrs = documentFrame.queryDocument().getAttributes()
-            for attr in attrs:
-                if attr.startswith('DocURL'):
-                    return attr[7:]
+            # If the document frame belongs to a Thunderbird message which
+            # has just been deleted, getAttributes() will crash Thunderbird.
+            #
+            if not documentFrame.getState().contains(pyatspi.STATE_DEFUNCT):
+                attrs = documentFrame.queryDocument().getAttributes()
+                for attr in attrs:
+                    if attr.startswith('DocURL'):
+                        return attr[7:]
         return None
 
     def getUnicodeText(self, obj):
