Token replacement for MultiPart in MailService

Hi Everyone,

I have just started using the MailService plugin for a project we are
doing. It's an excellent component. One part I like, in particular,
is the Token replacement.

However, the Token replacement only appears to work with the standard
setBody and not against any body in a multi-part.

Firstly, if anyone has already resolved this, I'd like to know.

Otherwise.... I will look at implementing it.

Regards
Gary

Hi Gary, you can update it and then comitt the patch to the list so we can apply it to the main trunk or just post your updates here.

Thanks

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Luis....

Here is my updated parseTokens method (just the body code - the method
signature has not changed). My brace coding style is not quite the
same as the Coldbox code base - but that can be resolved by whoever
moves it into the trunk. Essentially, the code checks to see if there
are mailParts and then treats them accordingly. The previous code for
a non-multipart message remains as the primary path. I have tested
this with two parts (HTML and TEXT).

  var tokens = arguments.Mail.getBodyTokens();
  var body = arguments.Mail.getBody();
  var mailParts = arguments.Mail.getMailParts();
  var key = 0;
  var mailPart = 0;

  if(arrayLen(mailParts)==0)
  {
    for(key in tokens)
    {
      body = replaceNoCase(body,"@#key#@", tokens[key],"all");
    }
    arguments.Mail.setBody(body);
  }
  else
  {
    for(mailPart=1;mailPart<=arrayLen(mailParts);mailPart++)
    {
      body = mailParts[mailPart].body;
      for(key in tokens)
      {
        body = replaceNoCase(body,"@#key#@", tokens[key],"all");
      }
      mailParts[mailPart].body = body;
    }
  }

Regards,
Gary