Determine Compose Message Type

In working with a customer on a new Mail App for OWA, they had a requirement to determine if the mail item being composed is a Reply or Forward or new mail message. Determining is New or Reply/Forward is easy. But getting the Reply/Forward determination is unfortunately… too easy. wlEmoticon-disappointedsmile.png Meaning the ONLY way I have been able to determine this is to look at the subject and see if there is a RE: or FW: in there. It’s a little ugly, but this is how it is. And worse – it is language dependent. If you need to support multiple languages you will have to determine the language and then make this function – much larger. So here is the English only version:

/// getMailType()
/// This function determines the type of email item currently being composed
/// - If it is a new item, it returns "New"
/// - If it is a reply, it return "Reply"
/// - If it is a Forward it returns "Forward"
/// - And if it cannot determine, it returns "UnknownReplyOrForward"
/// This accepts a function that is called with the resulting value.
function getMailType(returnFunction) {
	// get the conversation ID - if it exists
	var id = Office.cast.item.toItemCompose(Office.context.mailbox.item).conversationId;
	if (id == null) {
		// We have a new item
	else {
		// at this point we know we have a reply or forward. Now we determine which on it is.
		// we do this by getting the SUBJECT and then - yes - we look and see if it is a
		// RE: or FW: or unknown.
			.subject.getAsync(function (result) {
			var subject = result.value;
			// now this sucks, but the only way to do this is look at the
			// beginning of the subject and see it if it RE or FWD and
			// even worse, this is language specific...
			// and worse yet - if the user changed it, we have no idea
			else if(subject.toString().toUpperCase.startsWith("FW:")){
			else {

And to test this, I just created a button on my Compose App task pane, that runs the following code:

$('#getMailType').click(function () {
	getMailType(function (result) {
		app.showNotification("This is a: " + result);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s