Skip to content

Instantly share code, notes, and snippets.

@davecra
Created July 3, 2017 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davecra/e8bbfee63b48c340c24fecedc3899022 to your computer and use it in GitHub Desktop.
Save davecra/e8bbfee63b48c340c24fecedc3899022 to your computer and use it in GitHub Desktop.
Determines if the mail item is a new mail, reply or forward
/// 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
returnFunction("New");
return;
}
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.
Office.cast.item.toItemCompose(Office.context.mailbox.item)
.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
if(subject.toString().toUpperCase.startsWith("RE:")){
returnFunction("Reply");
}
else if(subject.toString().toUpperCase.startsWith("FW:")){
returnFunction("Forward");
}
else {
returnFunction("UnknownReplyOrForward");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment