Mail 5.0: No longer deselects message after removing attachments

Posted by Pierre Igot in: Mail
August 23rd, 2011 • 6:30 pm

In Lion, Apple has finally fixed a long-standing problem with message selection in Mail. The specific symptom was that, when you selected a message containing an attachment and then chose the “Remove Attachments” command in the “Message” menu, Mail would indeed remove the attachment from the selected message, but then it would also deselect the message.

In more recent versions of Mail, the bug changed without getting fixed. Instead of just deselecting the message after removing its attachments, Mail would… select the next message in the list (except when a whole thread was selected).

Now, in Mail 5.0, “Remove Attachments” no longer deselects the message. Obviously Apple’s engineers have finally eliminated the weird trickery that they used previously to remove attachments.

Coincidentally, this morning I received a follow-up e-mail from Apple about another related bug that I had submitted to them in a bug report, after exploring it in a discussion on the AppleScript forum at Apple Discussions last year.

I uncovered the problem while attempting to write a script to work around the problem with Mail deselecting messages after removing their attachments. I obviously do not need such a script anymore, but it appears that Apple’s engineers have fixed the message selection issue in AppleScript at the same time, possibly as part of the same general bug fixing process.

The sample script that I had sent to Apple with my bug report was as follows:

tell application "Mail"
	activate
	set selectedMessages to selected messages of message viewer 1
	tell application "System Events" to tell process "Mail"
		key code 126
	end tell
	try
		set selected messages of message viewer 1 to selectedMessages
	on error
		get selectedMessages
	end try
	get selectedMessages
end tell

This script simply would not work reliably with a message selected in Mail. Sometimes it would work, sometimes I would get an error saying “selectedMessages variable not defined.” There was obviously something broken in “set selected messages” in Mail’s AppleScript support.

Now, when I try to run the script, it seems to be working fine every time.

Like I said, I no longer need to write a script for fixing the “Remove Attachments” bug, since they fixed it, but it still is a good thing that the message selection bug in Mail’s AppleScript support has been fixed as well.

Now, things are not quite perfect in Mail 5. While “Remove Attachments” works fine on a single selected message or a selection of individual messages, I cannot get it to work on a conversation, i.e. when I select the conversation heading itself.

Whenever I select a conversation heading, the “Remove Attachments” command becomes disabled. This appears to imply that selecting a conversation does not actually select the enclosed messages. And yet, when I try to move a conversation to a different mailbox after just selecting the conversation heading, Mail does correctly move the entire conversation, including all the enclosed messages.

So there is still some message selection inconsistency here. Visually speaking, if you click on the small control that displays the message count for the conversation, Mail expands the conversation to reveal all the individual messages it contains:

Message Count

And after that, if you click on the conversation heading itself, you’ll see that Mail selects it without selecting the enclosed messages. And yet, as I said, even with such a selection, if you try to move it, the entire conversation gets moved, including the individual messages that do not appear to be selected:

Conversation selected

I can shift-click to add the enclosed messages to the selection:

Conversation selected

But doing this does not cause the “Remove Attachments” command to become enabled again, so it won’t work to remove attachments from all the messages in a conversation either.

The only thing that will work is to select the enclosed messages without selecting the conversation heading itself:

Conversation selected

Then, and only then, if the selection includes messages with attachments, the “Remove Attachments” command will become enabled and usable again.

Adding a level of abstraction such as this “conversation” concept obviously poses a number of challenges and, on the whole, I think that Apple did a decent job in Mail 5.0. (I am still familiarizing myself with it.) But I still wish that they were a big more careful about remaining consistent throughout the Mail UI. Either clicking on a conversation heading selects the enclosed messages, or it does not. If it does not, why does moving the conversation heading also move the enclosed messages? If it does, why is the “Remove Attachments” command disabled?

[UPDATE: I am actually mistaken about moving messages. If you select a conversation heading and move it, only the last (most recent) message in the conversation is moved. This makes things even more confusing, because the last message is somehow “selected” without being selected.]


Comments are closed.