#!/bin/bash

# Note: Escaping double-quotes is important both for functionality and security.

# Note: Side-effects: Upload time/bandwidth, other email clients see it as a new message, more?

NEW_SUBJECT=`osascript <<END
tell application "System Events"
	set theResult to (display dialog "Be aware of the following caveats:\n\n• An updated copy replaces the original on the IMAP server.\n• It is slow and inefficient for large emails.\n• Other email clients detect the updated copy as a new email.\n• The original subject is saved in an “Original-Subject” header." with title "Change subject" default answer "${MM_SUBJECT//\"/\"}")
	return the text returned of theResult
end tell
END
`

if [ $? -eq 0 ]
then

cat << ENDL
{ actions = (
	{
		type = changeHeaders;
		headers = { "subject" = "${NEW_SUBJECT//\"/\"}"; };
	}
); }
ENDL

fi
