<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  xmlns:imlogic="imlogic">


<xsl:output method="text"/>

<msxsl:script language="javascript" implements-prefix="imlogic"><![CDATA[
//Date: 8/31/2011
var TransformVersion = "8.0.0052"
// Change this to one of: Legato, KVS, Exchange, Zantaz, HP, AXSOne
var exportSystem = "Exchange";
var journalingEmailboxname = "";

//Change this to true if you want the transform to throw an exception when
//there are no email addresses found in the conversation.
//This will prevent IM conversations from going to external systems without
//email addresses.
var exceptionOnNoEmail = true;


var network = "";
var exportBloombergEmailAddresses = false; 									// Set this to 'false' if you want to export standard email address from the email attribute rather than exporting the Bloomberg Email addresses.
var exportCanonicalJabberIMnameasEmail = false; 						// Set this to 'true' if you want to use the canonicalized version of the Jabber IM name as the email address -- this is almost always the case when used with JabLog.
var exportCanonicalReutersIMnameasEmail = false; 						// Set this to 'true' if you want to use the canonicalized version of the Reuters IM name as the email address
var localEmailDomains = '(imlogic.com|bostonimlogic.COM|)'; // This is used with Reuters to determine the internal email domains of the customer.  Separate each domain with a pipe symbol
var bloombergNetworkName = "BloombergIMessage";

// Variables dealing with the from address
var useFirstMessageSenderInFrom = true; 	// Set this to 'false' if you want to have a hard coded from address.
var fromEmailaddress = "";
var zantazAddress = "";
var addJournal = "";	// For HP - Set this to JournalOnly or JournalAndEmail. JournalOnly - adds the Journaling mail box address to the 'To:' field, but there are no user email addresses in 'To:' field. JournalAndEmail - adds the Journaling mail box address to the list of email addresses in the 'To:' field.


var useLocalDate = true; 																		// Set this to 'false' if you want the dates/times in the body of the message to be UTC.
var xAXSOneAttribute = "extensionAttribute1";
var legatoXReceiver = false; 																//Set this to 'true' if you want use the XReceiver and SMTP to send messages to the Legato.
var addScreenNames = true; 	//Set to 'true' if you want to add screenNames in the 'To:' and 'From:' field.  These are set as the email display portion

// Sametime enhancement.  When Sametime IM Names are used in the export output and 
// are distinguishednames:
//
//cn=eric lorenzo/o=imlogic.com/c=us
//
//to:
//
//eric lorenzo/imlogic.com/us
//
//If you set these variables to 'true' then you get the friendly version below as the email address.
var useSametimeIMNameAsEmailAddress = false;
var changeSametimeIMNameToFriendly = false;



var participantsFromEmailAddress = false;	// 1. Set to true if you would like to list the participants in the From: list.  

// Change this to one of: HardCodedString, Standard, 
var subjectType = "Standard";
var HardCodedSubjectString = "IM Archive"; //Enter a message subjec string to use in conjunction with sujectType = "HardCodedString".

//Output body of email as quoted printable.  Typically this is always true but if you want to debug the output it may be useful to see the raw text.
var useQuotedPrintable = true;

function setup(topLevelNode)
{
    network  = topLevelNode.item(0).selectSingleNode("IMManagerExport/conversation/network").text

    if ( ! ((getExportSystem() == "Zantaz") || (getExportSystem() == "Legato") || (getExportSystem() == "KVS") || (getExportSystem() == "Exchange") || (getExportSystem() == "HP") || (getExportSystem() == "AXSOne") ) )
    {
        throw("Incorrect export system: " + exportSystem);
    }

    return("");
}

function getKVSJournalingEmailboxname()
{
    return(journalingEmailboxname);
}

function getParticipantsFromEmailAddress()
{
	return(participantsFromEmailAddress);
}

function getlegatoXReceiver()
{
	return(legatoXReceiver);
}

function getExportSystem()
{
    return(exportSystem);
}

function getNumericMonthFromTextMonth(textMonth)
{
    var month = "";
    if ( textMonth == "Jan" | textMonth == "January")
    {
        month = "01";
    }
    else if ( textMonth == "Feb" | textMonth == "February")
    {
        month = "02";
    }
    else if ( textMonth == "Mar" | textMonth == "March")
    {
        month = "03";
    }
    else if ( textMonth == "Apr" | textMonth == "April")
    {
        month = "04";
    }
    else if ( textMonth == "May" )
    {
        month = "05";
    }
    else if ( textMonth == "Jun" | textMonth == "June")
    {
        month = "06";
    }
    else if ( textMonth == "Jul" | textMonth == "July")
    {
        month = "07";
    }
    else if ( textMonth == "Aug" | textMonth == "August")
    {
        month = "08";
    }
    else if ( textMonth == "Sep" | textMonth == "September")
    {
        month = "09";
    }
    else if ( textMonth == "Oct" | textMonth == "October")
    {
        month = "10";
    }
    else if ( textMonth == "Nov" | textMonth == "November")
    {
        month = "11";
    }
    else if ( textMonth == "Dec" | textMonth == "December")
    {
        month = "12";
    }

    return(month);

} // getNumericMonthFromTextMonth

function getLocalDate(date) 
{ 
    if(! useLocalDate) 
    {
        return(date); 
    }

        //' Parse date. 
        var inDay = date.split(" ")[1]; 
        var inMon = date.split(" ")[2]; 
        var inYear = date.split(" ")[3]; 
        var inTime = date.split(" ")[4]; 

        var inHr = inTime.split(":")[0]; 
        var inMin = inTime.split(":")[1]; 
        var inSec = inTime.split(":")[2]; 

        //' Convert month to numeric val 
        if(inMon == 'Jan' | inMon == 'January') 
        { 
            inMon = "01"; 
        } 

        else if(inMon == 'Feb' | inMon == 'February') 
        { 
            inMon = "02"; 
        } 

        else if(inMon == 'Mar' | inMon == 'March') 
        { 
            inMon = "03"; 
        } 

        else if(inMon == 'Apr' | inMon == 'April') 
        { 
            inMon = "04"; 
        } 

        else if(inMon == 'May') 
        { 
            inMon = "05"; 
        } 

        else if(inMon == 'Jun' | inMon == 'June') 
        { 
            inMon = "06"; 
        } 

        else if(inMon == 'Jul' | inMon == 'July') 
        { 
            inMon = "07"; 
        } 

        else if(inMon == 'Aug' | inMon == 'August') 
        { 
            inMon = "08"; 
        } 

        else if(inMon == 'Sep' | inMon == 'September') 
        { 
            inMon = "09"; 
        } 

        else if(inMon == 'Oct' | inMon == 'October') 
        { 
            inMon = "10"; 
        } 

        else if(inMon == 'Nov' | inMon == 'November') 
        { 
            inMon = "11"; 
        } 

        else if(inMon == 'Dec' | inMon == 'December') 
        { 
            inMon = "12"; 
        } 


        var utcDate = new Date(inMon + "/" + inDay + "/" + inYear + " " + inHr + ":" + inMin + ":" + inSec + " UTC"); 
        var localDate = utcDate.toLocaleString(); 

		var re = new RegExp("\\d\\d:\\d\\d:\\d\\d\\s+(.*)");
		re.test(utcDate.toTimeString());

        localDate = localDate + " " + RegExp.$1;
        localDate = threeCharDayMonth(localDate);
        return (localDate);
} 

///////////////////////////////////////////////////////////////////
// This is all Zantaz stuff
////////////////////////////////////////////////////////////////

function getZantazAddress()
{
    return(zantazAddress);
}

function getDateList(conversationNode)
{
    var messageSentNodes = conversationNode.item(0).selectNodes("message");
    var length =  messageSentNodes.length;
    var index = 0;

    var dateList = "";
    for (index = 0; index < length; index++)
    {
        var tmpDate = new String(messageSentNodes.item(index).selectSingleNode("date").text);
        // Get the components of the date string.
        var dateArray = tmpDate.split(/\s/);
        var dayOfMonth = dateArray[1];
        var textMonth = dateArray[2];
        var year = dateArray[3];
        var time = dateArray[4];

        // Convert the text month into a numeric month
        var month = getNumericMonthFromTextMonth(textMonth);

        // Format the date in the format mm/dd/yyyy hh:mm:ss 
        var newDate = month + "/" + dayOfMonth + "/" + year + " " + time;

        // Check to see if the time is already part of the timeList and if not then add it.
       if (dateList.search(newDate) == -1)
       {
            if ( dateList.length > 0 )
            {
               dateList += "; ";
            }
            dateList += newDate;
        }
    }

    return(dateList);
} // getDateList()

function escapeString(str)
{
		// JVD 1/13/09 Updated to use hex code for characters to avoid issues where IMName contain special characters
     str = str.replace(/\\/g,"\\\x5C");
     str = str.replace(/\+/g,"\\\x2B");
     str = str.replace(/\[/g,"\\\x5B");
     str = str.replace(/\]/g,"\\\x5D");
     str = str.replace(/\*/g,"\\\x2A");
     str = str.replace(/\(/g,"\\\x28");
     str = str.replace(/\?/g,"\\\x3F");
     str = str.replace(/\)/g,"\\\x29");
     str = str.replace(/\;/g,"\\\x3B");

    return(str);

}

function getSenderList(conversationNode, type)
{

  var messageSentNodes = conversationNode.item(0).selectNodes("message");
  var length =  messageSentNodes.length;
  var index = 0;
  var type = new String(type);

  var toList = "";
    for (index = 0; index < length; index++)
    {
       var usernameNode = messageSentNodes.item(index).selectSingleNode("userName");
        var imNameNode =messageSentNodes.item(index).selectSingleNode("userIM");

       var name = "";
       if ( type == "username" )
       {
           if ( usernameNode != null )
           {
               name = usernameNode.text;
           }
       }
       else if ( imNameNode != null )
       {
           name = imNameNode.text;
           name = name.replace(/^sip:/, "");

       }

       if ((name.length > 0) && (toList.search(escapeString(name)) == -1))
       {
            if ( toList.length > 0 )
            {
               toList += "; ";
            }
            toList += name;
        }
    }

    return(toList);
} // getSenderList

function getRecipientList(conversationNode, type)
{

  var partEnteredNodes = conversationNode.item(0).selectNodes("partEntered");
  var senderList = getSenderList(conversationNode, type);

  var length =  partEnteredNodes.length;
  var index = 0;

  var toList = "";
    for (index = 0; index < length; index++)
    {
       var usernameNode = partEnteredNodes.item(index).selectSingleNode("userName");
        var imNameNode =partEnteredNodes.item(index).selectSingleNode("userIM");
       var name = "";
       if ( type == "username" )
       {
           if ( usernameNode != null )
           {
               name = usernameNode.text;
           }
       }
       else if ( imNameNode != null )
       {
           name = imNameNode.text;
           name = name.replace(/^sip:/, "");
       }

       if ((name.length > 0) && (toList.search(escapeString(name)) == -1))
       {
            if ( toList.length > 0 )
            {
               toList += "; ";
            }
            toList += name;
        }

    }

    // Check to see if anyone else besides the first participant sent a message.
    // If so, then add the first participant to the recipient list
    var firstParticipant = getFirstPartName(conversationNode, type);
    firstParticipant = firstParticipant.replace(/^sip:/, "");
    
    if ( toList.replace(firstParticipant.replace(/\\/,"\\\\")).length > 0 )
    {
       toList += "; " + firstParticipant;
    }
    return(toList);
}

//////////////////////////////////////////////////
// End Zantaz stuff
//////////////////////////////////////////////////


function getFirstParticipantNode(conversationNode)
{
  var firstParticipantNode = conversationNode.item(0).selectSingleNode("message");

  return(firstParticipantNode);
}

function getFirstPartName(conversationNode, type)
{
    var firstParticipantNode = getFirstParticipantNode(conversationNode);
    var usernameNode = firstParticipantNode.selectSingleNode("userName");
    var imNameNode = firstParticipantNode.selectSingleNode("userIM");

     var name = "";
     if ( type == "username" )
     {
         if ( usernameNode != null )
         {
             name = usernameNode.text;
         }
     }
     else if ( imNameNode != null )
     {
        name = imNameNode.text;
     }

    return(name);
}

function getFromEmailaddress(conversationNode, shouldEncode)
{

    if ( useFirstMessageSenderInFrom )
    {
        var emailaddress = getEmailAddress(getFirstParticipantNode(conversationNode), shouldEncode);
      
        if ( emailaddress.length < 1 )
        {
            return(fromEmailaddress);
        }
        return(emailaddress);
    }

    return(fromEmailaddress);
}

function getNetwork()
{
    return(network);
}

function getDisplayName(username)
{
    return(username);
}   

function getSametimeIMName(imname)
{
// Sametime enhancement.  When Sametime IM Names are used in the export output and 
// are distinguishednames:
//
//cn=eric lorenzo/o=imlogic.com/c=us
//
//to:
//
//eric lorenzo/imlogic.com/us
	imname = imname.replace(/,/g,"/");
	
	if (  changeSametimeIMNameToFriendly == true ) 
    {
        imname = imname.replace(/\/.[^=]*=/g,"/");
        imname = imname.replace(/^.[^=]*=/g,"");
    }

    return(imname);

}

//Return the email address of the particpiant.
//An email address is of the following format:
//
// "Display Name" <emailaddress@foo.com>
//
// For example:
//
// "Benjamin Lurie" <benjamin_lurie@foo.com>
//

function getEmailAddress(userNode, shouldEncodeForHeader)
{
       var mailNode = userNode.selectSingleNode("column[@name='mail']"); 
       var displayName = userNode.selectSingleNode("column[@name='displayName']");
       var imName = userNode.selectSingleNode("userIM");
       var userName = userNode.selectSingleNode("userName").text;

       var emailAddress = ""
       //First get the email address
        if ( mailNode != null )
        {
		emailAddress = mailNode.text;
	}
	else if ( (getNetwork() == bloombergNetworkName) && (exportBloombergEmailAddresses == true) )
       {
                emailAddress = imName.text;
       } else if ( (getNetwork().match(/SameTime/i)) && (useSametimeIMNameAsEmailAddress) )
        {
              emailAddress = getSametimeIMName(imName.text);
       } else if ( (exportCanonicalJabberIMnameasEmail) && (getNetwork().match(/JABBER IM/i) ))
       {
            // It is assumed that Jabber names are logged in the following format:
            //
            // drich@medea.blackmesacapital.com/JabberMessenger/Embudo
            // 
            // and that the first part of the imname is the email address of the user.

            var regex = new RegExp("(.[^@]*@.[^/]*)");
            imName.search(regex);
            if ( RegExp.$1 )
            {
                imName = RegExp.$1;
            }
	    emailAddress = imName.text;
       }  else if ( (exportCanonicalReutersIMnameasEmail) && (getNetwork().match(/REUTERS/i)) && (isReutersIMName(imName.text)))
       {
            emailAddress =  getEmailFromReutersIMname(imName.text);
       }

       var strDisplayName = "";
       // Now get display name
       if (displayName != null)
       {
       	    strDisplayName = displayName.text;
       }
       else if ( ! userName.match(imName.text) )
       {
       	 //If the username is not the same as the imname then use it as the display name
	 strDisplayName = userName;
       }
       else if ( addScreenNames )
       {
		strDisplayName = imName.text;
	}


	var finalEmailAddress = "";
	// Now combine the email address and display name
	if ( strDisplayName.length > 0 ) 
	{
		finalEmailAddress += '"' + (shouldEncodeForHeader ? encodeHeaderIfNecessary(strDisplayName) : strDisplayName) + '" ';
	}	

	if ( emailAddress.length > 0 )
	{
		finalEmailAddress += '<' + (shouldEncodeForHeader ? encodeHeaderIfNecessary(emailAddress) : emailAddress) + '>';
	}

    return(finalEmailAddress);
}

function isReutersIMName(reutersName)
{
    var reutersDomain = getReutersDomain();
    var regex = new RegExp("@" + reutersDomain, "i");
    if ( reutersName.search(regex) == -1 )
    {
        return(false);
    }
    return(true);
}
function getEmailFromReutersIMname(reutersName)
{
    if ( ! isReutersIMName(reutersName) )
    {
        throw("Not a Reuters name: " + reutersName);
    }
    if ( !isReutersInternal(reutersName) )
    {
         return("");
    }

    var emaildomain = getEmailDomainRegExp();
    var reutersDomain = getReutersDomain();

    //Remove reuters domain from the email address.
    var regex = new RegExp("@" + reutersDomain, "i");
    var emailAddress = reutersName.replace(regex, "");
    //Replace the '.' with an '@' before the email domain
    regex = new RegExp("\\." + emaildomain, "i");
     emailAddress.match(regex);
     var tempDomain = RegExp.$1;
    emailAddress = emailAddress.replace(regex, "@" + tempDomain);
    
    return(emailAddress);
}

function isReutersInternal(reutersName)
{
    var emaildomain = getEmailDomainRegExp();
    var reutersDomain = getReutersDomain();
    //Remove reuters domain from the email address.
    var regex = new RegExp("@" + reutersDomain, "i");
    var emailAddress = reutersName.replace(regex, "");
    regex = new RegExp("\\." + emaildomain, "i");
    emailAddress.match(regex);
    var matchString = RegExp.$1;
    if ( matchString.length > 0 )
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

function getReutersDomain()
{
   return("reuters.net");
}

function getEmailDomainRegExp()
{
    return(localEmailDomains + "$");
}

function getPartListSufix()
{
    var suffix = "";
    
    // For HP - Generates a different lable for the participant list in the body.
    if(exportSystem == "HP")
    {
        suffix = "Screenname:";
    }
    else
    {
    	suffix = "participant:";
    }
    
    return (suffix);
}

function getParticipantsForDisplay(conversationNode)
{ 
    var partEnteredNodes = conversationNode.item(0).selectNodes("firstPartEntered|partEntered");
  
    var partList = "";
  
    if(partEnteredNodes == null)
    {
        return(partList);
    }

	var length =  partEnteredNodes.length;
	var index = 0;

	var tmpUserIM = "";
	partList += '<table border="1">'; 
	for (index = 0; index < length; index++)
    	{
		var emailAddressString = getEmailAddress(partEnteredNodes.item(index), false)
       		var username = partEnteredNodes.item(index).selectSingleNode("userName").text;
        	var imName = partEnteredNodes.item(index).selectSingleNode("userIM").text;

		if ((emailAddressString.length > 0) && (tmpUserIM.search(escapeString(imName)) == -1) )
		{
			partList += '<tr>' +
				'<td>' + imName + '</td>' +
				'<td>' + username + '</td>' +
				'</tr>'; 

			tmpUserIM += " " + imName;
		}
	}
		partList += '</table>';

  return(partList);   
}

// For HP - Xpath participants list.
function getParticipantsForXpath(conversationNode)
{ 
    var partEnteredNodes = conversationNode.item(0).selectNodes("firstPartEntered|partEntered");
  
    var partList = "";
  
    if(partEnteredNodes == null)
    {
        return(partList);
    }

	var length =  partEnteredNodes.length;
	var index = 0;

    for (index = 0; index < length; index++)
    {
    var emailAddressString = getEmailAddress(partEnteredNodes.item(index), false)
		var mailNode = partEnteredNodes.item(index).selectSingleNode("column[@name='mail']");
		var imNameNode = partEnteredNodes.item(index).selectSingleNode("userIM");
		var dispNameNode = partEnteredNodes.item(index).selectSingleNode("column[@name='displayName']");
		var name = "";

		if ( emailAddressString.length > 0 )
			{
				name += emailAddressString + ' ';
			}
			
		if( dispNameNode != null )
			{
				name += '"' + dispNameNode.text + '" ';
			}	       
		if ( imNameNode != null )
			{
				name += '"' + imNameNode.text + '"; ';
			}
	       
		if (name.length > 0 && (partList.search(RegExp(escapeString(name))) == -1) )
			{
				partList += name;
			}

		}
   
  return(partList);   
}

function substituteThreeCharDay(stringContainingDay)
{
	//This is not very efficient.  Could be done better.
      stringContainingDay = stringContainingDay.replace(/Sunday/, "Sun");
      stringContainingDay = stringContainingDay.replace(/Monday/, "Mon");
      stringContainingDay = stringContainingDay.replace(/Tuesday/, "Tue");
      stringContainingDay = stringContainingDay.replace(/Wednesday/, "Wed");
      stringContainingDay = stringContainingDay.replace(/Thursday/, "Thu");
      stringContainingDay = stringContainingDay.replace(/Saturday/, "Sat");
      return(stringContainingDay);
}

function substituteThreeCharMonth(stringContainingMonth)
{
	//This is not very efficient.  Could be done better.
      stringContainingMonth = stringContainingMonth.replace(/January/, "Jan");
      stringContainingMonth = stringContainingMonth.replace(/February/, "Feb");
      stringContainingMonth = stringContainingMonth.replace(/March/, "Mar");
      stringContainingMonth = stringContainingMonth.replace(/April/, "Apr");
      stringContainingMonth = stringContainingMonth.replace(/May/, "May");
      stringContainingMonth = stringContainingMonth.replace(/June/, "Jun");
      stringContainingMonth = stringContainingMonth.replace(/July/, "Jul");
      stringContainingMonth = stringContainingMonth.replace(/August/, "Aug");
      stringContainingMonth = stringContainingMonth.replace(/September/, "Sep");
      stringContainingMonth = stringContainingMonth.replace(/October/, "Oct");
      stringContainingMonth = stringContainingMonth.replace(/November/, "Nov");
      stringContainingMonth = stringContainingMonth.replace(/December/, "Dec");
      return(stringContainingMonth);
}


function threeCharDayMonth(origDate)
{
	newDate = substituteThreeCharMonth(origDate);
	var newDate = substituteThreeCharDay(newDate);

	return (newDate);
	
}

// For AXS-One IMService conversion.
function getIMService(Network)
{
	var IMService = new String(Network);
	
	
	if(IMService == 'AOL IM')
	{
		IMService = "AOL";
	}
	else if(IMService == 'MSN IM')
	{
		IMService = "MSN";
	}
	else if(IMService == 'Yahoo IM')
	{
		IMService = "Yahoo";
	}
	else if(IMService == 'Microsoft Exchange IM')
	{
		IMService = "XIM";
	}
	else if(IMService == 'Reuters IM')
	{
		IMService = "Reuters";
	}
	else if(IMService == 'SameTime')
	{
		IMService = "Lotus IM";
	}
	else
	{
		IMService = "Unsupported Network";
	}
	
	return(IMService);
}

// For AXS-One popuates the X-AXSONE-Sender.
function getXSenderName(conversationNode)
{
    var senderNode = getFirstParticipantNode(conversationNode); 
    var XSenderName = senderNode.selectSingleNode("column[@name='" + xAXSOneAttribute + "']");            
    var name =  "";
   
    if(XSenderName != null)
    {
      name = XSenderName.text;
    }      
    return(name);
}


// For AXS-One populates the X-AXSONE_Recipient
function getXRecipientNames(conversationNode )
{

  var recipientNodes = conversationNode.item(0).selectNodes("firstPartEntered|partEntered");
  var length =  recipientNodes.length;
  var index = 0;

  var recipientList = "";
    for (index = 0; index < length; index++)
    {
       var XRecipientName = recipientNodes.item(index).selectSingleNode("column[@name='" + xAXSOneAttribute + "']");

       var name = "";
       
       if (XRecipientName != null)
       {
       	    name = XRecipientName.text;
       }
        
       if (name.length > 0 && (recipientList.search(RegExp(escapeString(name))) == -1))
        {
            if ( recipientList.length > 0 )
            {
               recipientList += "; ";
            }
            recipientList += name;
        }
    }

    return(recipientList);
}

function getToListOfEmails(conversationNode, shouldEncode)
{

  var partEnteredNodes = conversationNode.item(0).selectNodes("firstPartEntered|partEntered");
  var fromEmailAddress = getFromEmailaddress(conversationNode, shouldEncode);
  var length =  partEnteredNodes.length;
  var index = 0;

    var areThereEmailAddresses = false;
	
	if ( fromEmailAddress.search("@") > -1 )
	{
		areThereEmailAddresses = true;
	}

  var toList = "";

    for (index = 0; index < length; index++)
    {
        var name = getEmailAddress(partEnteredNodes.item(index), shouldEncode)

	//If the first particpiant is going in the From address then don't include it in the To list.
	if ( (useFirstMessageSenderInFrom) && (name == fromEmailAddress)) 
	{
		continue;
	}
	else if (name.length > 0 && (toList.search(RegExp(escapeString(name))) == -1))
        {
            if ( toList.length > 0 )
            {
               toList += ", ";
            }
            toList += name;

	    //If the email address contains a display name we need to check that it actually has a real email address to count it.
	    if ( ((addScreenNames) && (name.search("@") > -1)) || (!addScreenNames) )
	    {
		    areThereEmailAddresses = true;
	    }
        }
    }
    
    // Add the journaling mailbox and participant names to the 'To:' list for HP.
	if ( (exportSystem == "HP") && (addJournal == "JournalAndEmail")  )
	{
			toList += ", " + journalingEmailboxname;
	}
       
	if ( exceptionOnNoEmail && (! areThereEmailAddresses ))
	{
		throw("Could not find email address of internal participant");
	}

    return(toList);
}

// For HP messsage count.
function getNumberOfMessages(conversationNode)
{
  var messageNodes = conversationNode.item(0).selectNodes("message");
  var numberOfMessages = messageNodes.length;
  
  return(numberOfMessages);
}

function getSingleLine(tmpString)
{
   
   return(tmpString.split("\n")[0])
}

function getSubject(exportNode, conversationNode)
{
	var subject = "";

	//Set subjectType for Zantaz
    if ( getExportSystem() == "Zantaz" )
    {
		subject = "Subject: Conversation Participants = ";
		subject += getToListOfEmails(conversationNode, false);
		subject = subject.toUpperCase();
    }

	else if ( subjectType == "HardCodedString" )
	{
		subject = HardCodedSubjectString;
	}
	
	else if( subjectType = "Standard" )
	{
		subject = "Symantec IMManager conversation export: ";
		subject += getLocalDate(exportNode.item(0).selectSingleNode("@dateOfFirstMessage").text);
		subject += ": ";
	    subject += getSingleLine(exportNode.item(0).selectSingleNode("conversation/message/content").text);
	}
	
    return(subject);
}

function formatForHTML(str)
{

	str = str.replace(/\n/g, "<br>\n");

	return(str);
}


//If shouldSplit is 'false' then the header value is truncated to a maximum of 'maximumLength'.  Otherwise if the header value is over maximumLength then additional headers are added.
function limitHeaderLength(headerName, maximumLength, separator, shouldSplit, headerValue)
{

	var allHeaders = ""

	if (( headerValue == null ) || (headerValue.length < 1 ))
	{
		return(allHeaders);
	}

  if (shouldSplit == false)
	{
	
		//Just truncate header.
	  return(headerValue.substr(0, maximumLength));
	}
	
	var valueArray = headerValue.split(separator);
	var value;
	var currentLineLength = 0;
	for (value in valueArray)
	{

		if ( currentLineLength + valueArray[value].length > maximumLength )
		{
			allHeaders += "\n";
			var tmp =  headerName + ": " + valueArray[value];
			currentLineLength = tmp.length;
			allHeaders += tmp;
		}
		else
		{
			if ( currentLineLength > 0 ) 
			{
				allHeaders +=  separator + " ";
				currentLineLength += separator.length + 1;
			}
			allHeaders +=  valueArray[value];
			
		}
	  currentLineLength += valueArray[value].length;
	}

	return(allHeaders);

} //limitHeaderLength


// Copyright 2010 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//*
// * @fileoverview Functions for encoding strings according to MIME
// * standards, especially RFC 1522.
// */

///**
// * Regular expression for matching those characters that are outside the
// * range that can be used in the quoted-printable encoding of RFC 1522:
// * anything outside the 7-bit ASCII encoding, plus ?, =, _ or space.
// * @type {RegExp}
// * @private
// */
var googi18nmimeNONASCII_ = /[^!-<>@-^`-~]/g;


///**
// * Like goog.i18n.NONASCII_ but also omits double-quotes.
// * @type {RegExp}
// * @private
// */
var googi18nmimeNONASCII_NOQUOTE_ = /[^!#-<>@-^`-~]/g;


///**
// * Encodes a string for inclusion in a MIME header. The string is encoded
//* in UTF-8 according to RFC 1522, using quoted-printable form.
// * @param {string} str The string to encode.
// * @param {boolean=} opt_noquote Whether double-quote characters should also
// *     be escaped (should be true if the result will be placed inside a
// *     quoted string for a parameter value in a MIME header).
// * @return {string} The encoded string.
// */

function googencode(str, opt_noquote) {

  var nonascii = opt_noquote ?
      googi18nmimeNONASCII_NOQUOTE_ : googi18nmimeNONASCII_;

  if (str.search(nonascii) >= 0) {
    str = '' + str.replace(nonascii,
    ///**
    //    * @param {string} c The matched char.
    //    * @return {string} The quoted-printable form of utf-8 encoding.
    //    */
        function(c) {
          var i = c.charCodeAt(0);
	  //if (i == 32) {
            // Special case for space, which can be encoded as _ not =20
	    //  return '_';
	    // }

          var a = [''];  // start with empty string to get = before every char
          // First convert the UCS-2 character into its UTF-8 bytes
          if (i < 128) {
            a.push(i);
          } else if (i <= 0x7ff) {
            a.push(
                0xc0 + ((i >> 6) & 0x3f),
                0x80 + (i & 0x3f));
          } else if (i <= 0xffff) {
            a.push(
                0xe0 + ((i >> 12) & 0x3f),
                0x80 + ((i >> 6) & 0x3f),
                0x80 + (i & 0x3f));
          } else {
            // (This is defensive programming, since ecmascript isn't supposed
            // to handle code points that take more than 16 bits.)
            a.push(
                0xf0 + ((i >> 18) & 0x3f),
                0x80 + ((i >> 12) & 0x3f),
                0x80 + ((i >> 6) & 0x3f),
                0x80 + (i & 0x3f));
          }
          // Now convert those bytes into hex strings (don't do anything with
          // a[0] as that's got the empty string that lets us use join(),
          // below).
          for (i = a.length - 1; i > 0; --i) {
            a[i] = a[i].toString(16);
	    if (a[i].length == 1)
	    {
	    	a[i] = '0' + a[i];
	    }
          }
          // Form the string with = before each byte.
	  var tmp = a.join('=');
	  //if (tmp.match(/^=a$/))
	  // {
	  //return(a.join('=') + '<foo>' + a[0] + a[1] + '>');
		  // }
	  return a.join('=');
        }) + '';
  }

  var RFC2045Encode2IN = /.{1,72}(?!\r\n)[^=]{0,3}/g;
  var RFC2045Encode2OUT = function (sMatch) 
  	{
		if (sMatch.substr(sMatch.length - 2) === '\r\n') 
		{
			return sMatch;
		}
		return sMatch + '=\r\n';
        };

	 str = str.replace(RFC2045Encode2IN, RFC2045Encode2OUT);    // Strip last softline break
      return str.substr(0, str.length - 2);


  return str;
};

var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}


function encodeHeaderIfNecessary(str)
{

	if (str.search(/[^ -~]/g) >= 0)
	{
		return("=?UTF-8?B?" + Base64.encode(str) + "?=");
	}

	return(str);
}

]]></msxsl:script>

<xsl:template match="/"><xsl:value-of select="imlogic:setup(.)"/>
<xsl:if test="imlogic:getExportSystem() = 'KVS' or imlogic:getExportSystem() = 'Exchange' or imlogic:getExportSystem() = 'HP'">X-Receiver: <xsl:value-of select="imlogic:getKVSJournalingEmailboxname()"/><xsl:text>&#10;</xsl:text></xsl:if>
<xsl:if test="imlogic:getExportSystem() = 'Legato' and imlogic:getlegatoXReceiver() = 'true'">X-Receiver: <xsl:value-of select="imlogic:getKVSJournalingEmailboxname()"/><xsl:text>&#10;</xsl:text></xsl:if>
<xsl:if test="imlogic:getExportSystem() = 'Legato'"><xsl:text>X-MsgClass:16</xsl:text><xsl:text disable-output-escaping="yes">&#10;</xsl:text></xsl:if>
<xsl:if test="imlogic:getExportSystem() = 'KVS'"><xsl:text>x-KVS-MessageType:IM.imlogic</xsl:text><xsl:text disable-output-escaping="yes">&#10;</xsl:text></xsl:if>
<xsl:if test="imlogic:getExportSystem() = 'AXSOne'">
<xsl:text>X-Sender: </xsl:text><xsl:value-of select="imlogic:getKVSJournalingEmailboxname()"/><xsl:text disable-output-escaping="yes">&#10;</xsl:text>
<xsl:text>X-Receiver: </xsl:text><xsl:value-of select="imlogic:getKVSJournalingEmailboxname()"/><xsl:text disable-output-escaping="yes">&#10;</xsl:text>
<xsl:text>X-AXSONE-Sender: </xsl:text><xsl:value-of select="imlogic:getXSenderName(IMManagerExport/conversation)"/><xsl:text disable-output-escaping="yes">&#10;</xsl:text>
<xsl:text>X-AXSONE-Recipient: </xsl:text><xsl:value-of select="imlogic:getXRecipientNames(IMManagerExport/conversation)"/><xsl:text disable-output-escaping="yes">&#10;</xsl:text>
<xsl:text>X-IMService: </xsl:text><xsl:value-of select="imlogic:getIMService(string(IMManagerExport/conversation/network))"/><xsl:text disable-output-escaping="yes">&#10;</xsl:text>
</xsl:if>Message-ID: <xsl:text disable-output-escaping="yes">&lt;</xsl:text><xsl:value-of select="IMManagerExport/conversation/conversationID" /><xsl:value-of select="IMManagerExport/conversation/timestamp" />@<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
Received: by immanager; <xsl:value-of select="imlogic:threeCharDayMonth(concat(IMManagerExport/@dateOfFirstMessage, ' UTC'))" />
Date: <xsl:value-of select="imlogic:threeCharDayMonth(concat(IMManagerExport/@dateOfFirstMessage, ' UTC'))" />
From: <xsl:choose>
<xsl:when test="imlogic:getParticipantsFromEmailAddress() = 'true' and imlogic:getExportSystem() != 'HP'">
  <xsl:value-of select="imlogic:getFromEmailaddress(IMManagerExport/conversation, true)"/>; <xsl:value-of select="imlogic:getToListOfEmails(IMManagerExport/conversation, false )"/>
</xsl:when>
<xsl:when test="imlogic:getParticipantsFromEmailAddress() = 'true' and imlogic:getExportSystem() = 'HP'">
<xsl:value-of select="imlogic:getToListOfEmails(IMManagerExport/conversation, false )"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="imlogic:getFromEmailaddress(IMManagerExport/conversation, true)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="imlogic:getExportSystem() = 'Zantaz'">
To: <xsl:value-of select="imlogic:getZantazAddress()"/>
</xsl:if>
<xsl:if test="(imlogic:getExportSystem() != 'Zantaz')">
	<xsl:text>&#10;To:</xsl:text>
<xsl:value-of select="imlogic:limitHeaderLength('To', 970, ',', 1, imlogic:getToListOfEmails(IMManagerExport/conversation, false))"/>
</xsl:if>
Subject: <xsl:value-of select="imlogic:limitHeaderLength('Subject', 970, ':::', 0, string(imlogic:getSubject(IMManagerExport, IMManagerExport/conversation)))"/>
<xsl:if test="(imlogic:getExportSystem() = 'HP')">
Return-Path: <xsl:value-of select="imlogic:getFromEmailaddress(IMManagerExport/conversation, true)"/>
</xsl:if>
<xsl:if test="imlogic:getExportSystem() = 'Zantaz'">
X-ZANTAZDOCCLASS: IMCONVERSATIONS
X-ZANTAZ-PARTICIPANT-NAMES: <xsl:value-of select="IMManagerExport/conversation/participants" />
X-ZANTAZ-IMNETWORK: <xsl:value-of select="IMManagerExport/conversation/network" />
X-ZANTAZ-MESSAGE-DATE: <xsl:value-of select="imlogic:limitHeaderLength('X-ZANTAZ-MESSAGE-DATE', 970, ';', 1, imlogic:getDateList(IMManagerExport/conversation))"/>
X-ZANTAZ-PARTICIPANT-IMNAMES: <xsl:value-of select="imlogic:getRecipientList(IMManagerExport/conversation, 'imname')"/>
X-ZANTAZ-RECIPIENT-NAME: <xsl:value-of select="imlogic:getRecipientList(IMManagerExport/conversation, 'username')"/>
X-ZANTAZ-PARTICIPANT-IMNAMES: <xsl:value-of select="imlogic:getSenderList(IMManagerExport/conversation, 'imname')"/>
X-ZANTAZ-SENDER-NAME: <xsl:value-of select="imlogic:getSenderList(IMManagerExport/conversation, 'username')"/>
X-ZANTAZ-GUID: <xsl:value-of select="IMManagerExport/conversation/conversationID" /><xsl:value-of select="IMManagerExport/conversation/timestamp" />
<xsl:text>
X-ZANTAZ-URL: notused</xsl:text>
</xsl:if>
<xsl:if test="(imlogic:getExportSystem() = 'HP')">
X-PT-START-TIME: <xsl:value-of select="imlogic:getLocalDate(string(IMManagerExport/conversation/startDate/date))" />
X-PT-END-TIME:  <xsl:value-of select="imlogic:getLocalDate(string(IMManagerExport/conversation/endDate/date))" />
X-PT-MESSAGE-COUNT: <xsl:value-of select="imlogic:getNumberOfMessages(IMManagerExport/conversation)" />
X-PT-IM-SERVICE: <xsl:value-of select="IMManagerExport/conversation/network" /> 
X-PT-USERNAMES: <xsl:value-of select="imlogic:getParticipantsForXpath(IMManagerExport/conversation)"/>
</xsl:if>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="--_Part_1_187698766763.2348979637477"

----_Part_1_187698766763.2348979637477
Content-Type: text/html; charset="utf-8";
Content-Transfer-Encoding: quoted-printable

<xsl:call-template name="encode_conversation">
	<xsl:with-param name="value">
		<xsl:text disable-output-escaping="yes">&lt;</xsl:text>br<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
		<xsl:text>&lt;b&gt;IM Network&lt;/b&gt;: </xsl:text><xsl:value-of select="IMManagerExport/conversation/network"/>
		<xsl:text disable-output-escaping="yes">&lt;</xsl:text>br<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

		<xsl:text disable-output-escaping="yes">&lt;</xsl:text>br<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
		<xsl:text>&lt;b&gt;IM Participants&lt;/b&gt; </xsl:text>
		<xsl:text disable-output-escaping="yes">&lt;</xsl:text>br<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

		<xsl:value-of select="imlogic:formatForHTML(imlogic:getParticipantsForDisplay(IMManagerExport/conversation))"/>


<xsl:text disable-output-escaping="yes">&lt;</xsl:text>br<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;b&gt;IM Dialog&lt;/b&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
		<xsl:apply-templates select="IMManagerExport/conversation" />
	</xsl:with-param>
</xsl:call-template>


<xsl:apply-templates select="IMManagerExport/conversation/filetransfer"/>


----_Part_1_187698766763.2348979637477--

</xsl:template>

<xsl:template name="encode_conversation">
	<xsl:param name="value"/>
	<xsl:value-of select="imlogic:googencode(string($value))"/>
</xsl:template>

<xsl:template match="conversation">
<xsl:text disable-output-escaping="yes">&lt;table border="1"&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getLocalDate(string(imlogic:getFirstParticipantNode(.)/date))" />
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getDisplayName(string(imlogic:getFirstParticipantNode(.)/userName))"/>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;i&gt;Started Conversation&lt;/i&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
<xsl:apply-templates select="partEntered|partLeft|message"/>
</xsl:template>

<xsl:template match="message">
<xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getLocalDate(string(date))" /><xsl:text> </xsl:text>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getDisplayName(string(userName))"/>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
		<xsl:choose>
			<xsl:when test="contenttype = 1">
				<xsl:variable name="temp" select="content"/>
				<xsl:for-each select="//IMManagerExport/conversation/filetransfer">
					<xsl:if test="fileID = $temp">
						<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
						<xsl:text> &lt;i&gt;File Transfer&lt;/i&gt; </xsl:text>
						<xsl:value-of select="filename"/>
						<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
						<xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
					</xsl:if>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>td<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
<xsl:value-of select="imlogic:formatForHTML(string(content))" xml:space="preserve"/>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>/td<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>/tr<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
</xsl:template>

<xsl:template match="partEntered">
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getLocalDate(string(date))"/>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getDisplayName(string(userName))"/>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;i&gt;Entered Conversation&lt;/i&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
</xsl:template>

<xsl:template match="partLeft">
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getLocalDate(string(date))" />
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:value-of select="imlogic:getDisplayName(string(userName))"/>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;td&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;i&gt;Left Conversation&lt;/i&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
</xsl:template>
	<xsl:template match="filetransfer">
		<xsl:if test="filesize > 0">
----_Part_1_187698766763.2348979637477
Content-Type: application/octet-stream;
	name&#061;&quot;<xsl:value-of select="filename"/>&quot;
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename&#061;&quot;<xsl:value-of select="filename"/>&quot;&#10;
<xsl:value-of select="filecontents"/>
		</xsl:if>
	</xsl:template>

</xsl:stylesheet>

