Change Mail behavior when replying to a message in the Sent mailbox

Jun 09, '11 07:30:00AM

Contributed by: Anonymous

When using Gmail (I don't know if this is the case with other webmail providers), if you reply to a message in your Sent mailbox, the recipient of the reply message is set to the recipient of the original message you sent. That makes sense, it's useful for quickly replying to a message you've just sent when you realize you've forgotten something (like an attachment).

However, Apple Mail doesn't work that way; if you reply to a message in your Sent mailbox, you (the sender of the original message) become the recipient of the reply message (which is pretty useless in my opinion).

If you choose Reply all instead of Reply, it's a little better: you are still the 'To' recipient of the reply message, but the recipients of the original message are added as Cc: recipients of the reply message.

I used this fact to create an AppleScript that when invoked creates a reply to the selected message in the Sent mailbox in Mail, with the recipients of the original message as 'To' recipients of the reply message and no Cc: recipient, thus restoring Gmail's behavior in Mail.

Here is the script:

tell application "Mail"
  activate
  set theMessages to the selected messages of the front message viewer
  
  (*the script is intended to work on only one message but if "selection" is used instead of "selected items" along with "first item of" on the next line, nothing happens (no message appears). I think it's a bug in the reply command. (A little Google search shows you this command has a buggy past...) *)
  
  set theMessage to first item of theMessages
  set outgoingReplyMessage to (reply theMessage with opening window and reply to all)
  
  (*"reply to all" is always used in order to get the recipients of the original message in the Cc field (as I said above, if it's not used, the original recipients are not used anywhere). They are switched to the To field later on. *)
  
  set theIntendedRecipientsAdresses to (get address of every cc recipient of outgoingReplyMessage)
  set quoted to quote original message
  if quoted is true then
    set quote original message to false
    
    (*this is to prevent the cited text of the original message to appear a large number of time in the reply message (in my tests, it was copied at least 27 times). I think this is another bug... *)
    
  end if
  repeat with theIntendedRecipientAddress in theIntendedRecipientsAdresses
    
    (*this is the real work : each cc recipient is copied to the To recipient field. *)
    
    tell outgoingReplyMessage
      set theIntendedRecipient to make new to recipient at the end of to recipients
      set address of theIntendedRecipient to theIntendedRecipientAddress
    end tell
  end repeat
  set address of first to recipient of outgoingReplyMessage to ""
  
  --deletes you (the sender) from the list of To recipients
  
  set address of cc recipient of outgoingReplyMessage to ""
  
  --deletes every Cc recipients
  
  if quoted is true then
    set quote original message to true
  end if
end tell
For ease of use, I copied that script into a 'Run Applescript' Automator action (receive no input, in application Mail) and saved it as a Service (10.6 only). I then assigned a keyboard shortcut for it using the Keyboard preference pane of System Preference (Under the Keyboard Shortcut tab, then choosing Services on the left). Command+Option+Shift+R and Command+Control+Option+R are both available in Mail.

Of course, you can also use it with your favorite shortcut application, be it Quicksilver, Butler, Alfred, Keyboard Maestro, etc. Just save it as a Script instead (.scpt).

Be warned that this script is only intended to be used in the Sent mailbox; using it on a message in your Inbox won't work (and could lead to errors.) What's more, there is no error detection to verify it is used in the Sent mailbox.

[crarko adds: I tested this, and it works as described. A very useful script.]

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20110608154158765