private void ReplacePlaceholders(ContactStringReplacer replacer, string signatureName)
        {
            if (string.IsNullOrEmpty(signatureName))
            {
                return;
            }

            using (ISignatures signatures = ThisAddIn.Instance.GetSignatures())
            {
                using (ISignature signature = signatures.Get(signatureName))
                {
                    if (signature == null)
                    {
                        return;
                    }

                    foreach (ISignatureFormat format in Enum.GetValues(typeof(ISignatureFormat)))
                    {
                        string template = signature.GetContentTemplate(format);
                        if (template != null)
                        {
                            string replaced = replacer.Replace(template);
                            signature.SetContent(replaced, format);
                        }
                    }
                }
            }
        }
        private string StoreSignature(ISignatures signatures, ZPushAccount account, Signature signatureInfo)
        {
            string name = GetSignatureName(signatures, account, signatureInfo.name);

            // Remove any existing signature
            try
            {
                ISignature signature = signatures.Get(name);
                if (signature != null)
                {
                    try
                    {
                        signature.Delete();
                    }
                    finally
                    {
                        signature.Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Error(this, "Unable to delete signature {0}: {1}", name, e);
            }

            // Create the new signature
            using (ISignature signature = signatures.Add(name))
            {
                if (!HasPlaceholders(signatureInfo))
                {
                    // Simple, set signature straight away
                    signature.SetContent(signatureInfo.content, signatureInfo.isHTML ? ISignatureFormat.HTML : ISignatureFormat.Text);
                }
                else
                {
                    // There are placeholders. Create a template and hook into the GAB for patching
                    signature.SetContentTemplate(signatureInfo.content, signatureInfo.isHTML ? ISignatureFormat.HTML : ISignatureFormat.Text);

                    // Try replacing straight away
                    GABHandler gab = FeatureGAB.FindGABForAccount(account);
                    if (gab != null)
                    {
                        ReplacePlaceholders(gab, name);
                    }
                }
            }

            return(name);
        }