Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Change subject of received emails in Mail.app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change subject of received emails in Mail.app
Authored by: leenoble_uk on Apr 04, '06 08:15:46AM

This Applescript will allow you to change the subject of a single message or merge messages under the same subject heading. A few caveats though:

  1. It will only work on messages in the inbox, if you want to merge messages in a different mailbox then you will have to adjust the script.
  2. By all accounts THIS SHOULDN'T WORK. When writing this script a couple of years ago I could not find a workable solution and was told it was impossible to alter an incoming message, yet this has worked for me for some time. I'm not sure exactly what it's doing since if you use it multiple times you will notice that Mail still remembers the old subjects.
  3. I do not know if this works in 10.4 mail. I'm still on 10.3 so use it at your own risk.

Save as a scpt file in ~/Library/Scripts/Mail Scripts and run it from the script menu in Mail. If you only have one message selected you can enter a new subject, or if you select multiple messages you will have a choice of selecting an existing subject or writing a new one.


(*
MERGE THREADS by Lee Noble
--------------------------
It's frustrating when you have different contributors to an
email conversation start using different subject titles and Mail
doesn't keep up. Mail seems only to ignore Re: or Fw: in its
efforts to determine which messages are in the same thread.
So in an attempt to get several scattered subjects to appear as a
single coherent thread it is necessary to make all messages carry
the same subject line. This isn't possible through the Mail
interface. It is possible using AppleScript

*)


tell application "Mail"
	set theSubjectList to {}
	set headList to {}
	set themessages to selection as list
	set messageTitle to button returned of (display dialog "Thread name…" buttons {"New", "Select From Existing…"} default button 2)
	repeat with msg in themessages
		set theHeaders to headers of msg as list
		set thisSubject to (subject of msg as string)
		repeat with head in theHeaders
			if (name of head as string is "Thread-Topic") and (content of head as string is not in theSubjectList) then
				set theSubjectList to theSubjectList & {(content of head as string)}
			else if thisSubject is not in theSubjectList then
				set theSubjectList to theSubjectList & {thisSubject}
			end if
		end repeat
		if thisSubject is not in theSubjectList then
			set theSubjectList to theSubjectList & {thisSubject}
		end if
	end repeat
	
	if messageTitle is "New" then
		set theNewSubject to (text returned of (display dialog "Type new subject" default answer "NEW THREAD")) as string
	else
		set theNewSubject to (choose from list theSubjectList with prompt "Choose the subject of the merged thread…") as string
	end if
	
	if theNewSubject is not "false" then
		repeat with msg in themessages
			set subject of msg to (theNewSubject)
		end repeat
		move msg to mailbox "INBOX" of account of mailbox of msg
	else
		display dialog "Action cancelled"
	end if
end tell

---
Brought to you by S C Johnson, a family multinational conglomerate.

[ Reply to This | # ]

Change subject of received emails in Mail.app
Authored by: Satinder S Sidhu on Apr 04, '06 08:43:45AM

Received date and time are not the only things that change; the "From:" also changes to you (the changer).

This would be a problem if you later search for the message by Sender beacuse you happen to remember who the original was from.



[ Reply to This | # ]
Change subject of received emails in Mail.app
Authored by: leenoble_uk on Apr 04, '06 08:53:58AM

Oh I should mention, for those inclined to adjust/improve the script. It is not possible to get the script to dynamically retrieve the currently selected mailbox. This is why INBOX is hardcoded. You really do need separate scripts if you want to use it in any other mailbox.

It is the "move msg to mailbox "INBOX" of account of mailbox of msg" which forces the changes to stick although if you know anything about Applescript you'll be able to see that it should do absolutely nothing. Go figure.
To use in another box just change it to: "move msg to mailbox "Work/_To Do" where "Work/_To Do" is the path in mail to the mailbox you are in.

---
Brought to you by S C Johnson, a family multinational conglomerate.



[ Reply to This | # ]
Change subject of received emails in Mail.app
Authored by: hnhansen on Apr 04, '06 01:45:04PM
You said "It is not possible to get the script to dynamically retrieve the currently selected mailbox". Well, what about someting like this:

tell application "Mail"
	set theSelection to the selection
	return mailbox of item 1 of theSelection
end tell
This will return a reference to the mailbox of the selected message.

[ Reply to This | # ]
Change subject of received emails in Mail.app
Authored by: leenoble_uk on Apr 04, '06 02:20:43PM

You're welcome to try it but I'm sure I tore my hair out for days trying to get it to work and I'm certain I tried that. I can't stress enough for people not to try, it'll just waste your time, trust me. I think it is a bug in Mail as far as I recall. If the script works in 10.4 then maybe the associated bug no longer exists so it may be worth the effort in that instance.

I tried numerous online resources and message boards and the only consistent reply I got was that it wasn't possible to modify an incoming message.

---
Brought to you by S C Johnson, a family multinational conglomerate.



[ Reply to This | # ]
Change subject of received emails in Mail.app
Authored by: richwiss on Apr 04, '06 06:43:21PM

I too pulled my hair out trying to fix this... but I just upgraded to 10.4.6 and I can now -- once again -- get the mailbox.

Good luck.



[ Reply to This | # ]
Change subject of received emails in Mail.app
Authored by: Mr_London on Apr 04, '06 02:26:12PM

doesnt work in 10.4.6... tried to change to new subject title but wont work :(



[ Reply to This | # ]
Change subject of received emails in Mail.app
Authored by: laurentbodard on Jun 21, '13 07:31:12AM

Hello there - I am most keen to have a script that works with Apple Mail.

Could you indicate whether you have a script for Apple Mail 6.5?

All the best,
Laurent



[ Reply to This | # ]