Skip to content

Instantly share code, notes, and snippets.

Created July 3, 2017 14:42
What would you like to do?
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
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 {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment