private int GetInitialResponseCode(IDataReader reader, BulkEmailRecipientInfo recipientInfo, int responseCodeColumnIndex) { var initialResponseCode = reader.GetInt32(responseCodeColumnIndex); if (initialResponseCode != (int)MailingResponseCode.PostedProvider) { return(initialResponseCode); } if (!MailingUtilities.ValidateEmail(recipientInfo.EmailAddress)) { initialResponseCode = (int)MailingResponseCode.CanceledIncorrectEmail; } else if (_limitedRecipients.Value.ContainsKey(recipientInfo.ContactId)) { initialResponseCode = _limitedRecipients.Value[recipientInfo.ContactId]; } else if (_duplicatingRecipients.Value.ContainsKey(recipientInfo.Id)) { initialResponseCode = _duplicatingRecipients.Value[recipientInfo.Id]; } else if (recipientInfo.ReplicaId == Guid.Empty) { initialResponseCode = (int)MailingResponseCode.CanceledTemplateNotFound; } return(initialResponseCode); }
private void InitProvider() { Guid _providerId = MailingUtilities.GetActiveProviderId(UserConnection); SysMailingProvider provider = GetProvider(_providerId); if (provider == null) { string msg = string.Format("Could not load provider data from DB. Provider UId: {0}", _providerId); throw new Exception(msg); } Type providerType = Type.GetType(provider.ClassName); if (providerType != null) { IMailingProviderConfigFactory configFactory = CreateConfigFactory(provider.ConfigFactoryClassName); _mailingProvider = CreateProviderInstance(providerType, configFactory); var configurableProvider = _mailingProvider as IConfigurableMailingProvider; if (configurableProvider != null) { configurableProvider.Configure(); } } else { string msg = string.Format("Could not initiate provider instance. Provider UId: {0}", _providerId); throw new Exception(msg); } }
/// <summary> /// Modifies <paramref name="templateBody"/>. /// </summary> /// <param name="templateBody">Template body.</param> /// <returns>Modified template body.</returns> public static string ModifyTemplate(string templateBody) { List <string> anchorElements = MailingUtilities.ParseHtmlAnchorElement(templateBody); Dictionary <string, string> modifiedLinks = ModifyTemplateLinks(anchorElements); return(ReplaceLinksInTemplate(templateBody, modifiedLinks)); }
private static Select AppendWhereClauseByHash(Guid bulkEmailId, string preparedUrl, Select rIdSelect) { var urlHash = MailingUtilities.GetMD5HashGuid(preparedUrl.ToLower()); rIdSelect = rIdSelect .Where("Hash").IsEqual(Column.Parameter(urlHash)) .And("BulkEmailId").IsEqual(Column.Parameter(bulkEmailId)) as Select; return(rIdSelect); }
/// <summary> /// Validates the sender email from the FromEmailMacro. /// </summary> /// <param name="recipient">Recipient of bulk email.</param> protected override void InternalValidate(IMessageRecipientInfo recipient) { var valueFromEmail = GetMacroValueFromRecipient(recipient, MailingConsts.FromEmailMacroKey); if (valueFromEmail != null && !MailingUtilities.ValidateEmail(valueFromEmail.Value.MacroValue)) { recipient.InitialResponseCode = (int)MailingResponseCode.CanceledSendersDomainNotVerified; } }
/// <summary> /// Returns all anchor elements from <paramref name="src"/>. /// </summary> /// <param name="src">Source text.</param> /// <returns>Collection of anchor elements, element definition as key and href parameter as value.</returns> private Dictionary <string, string> ParseHtmlAnchorElements(string src) { var result = new Dictionary <string, string>(); List <string> anchorElements = MailingUtilities.ParseHtmlAnchorElement(src); foreach (string anchorElement in anchorElements) { result[anchorElement] = MailingUtilities.ParseHtmlHrefValue(anchorElement); } return(result); }
/// <summary> /// Enables handlers of the active mailing provider. /// </summary> /// <param name="userConnection">Instance of user connection.</param> public static void EnableActiveProviderHandlers(UserConnection userConnection) { Guid providerId = MailingUtilities.GetActiveProviderId(userConnection); EntityCollection mailingHandlers = GetMailingHandlers(userConnection); IEnumerable <string> activeHandlersNames = GetProviderHandlers(providerId, mailingHandlers); IEnumerable <string> inactiveHandlersNames = GetDisabledHandlers(mailingHandlers, activeHandlersNames); IEnumerable <IMailingHandler> activeHandlers = InstantiateHandlers(activeHandlersNames); IEnumerable <IMailingHandler> inactiveHandlers = InstantiateHandlers(inactiveHandlersNames); DeactivateHandlers(inactiveHandlers); ActivateHandlers(activeHandlers, userConnection); }
private void InsertWebHook(string webHookEventJson, string webhookType) { byte[] compressedJson = MailingUtilities.Compress(webHookEventJson); var insert = new Insert(UserConnectionSafe) .Into("RawWebHooks") .Set("Id", Column.Parameter(Guid.NewGuid())) .Set("JsonData", Column.Parameter(compressedJson)); if (webhookType != null && int.TryParse(webhookType, out var type)) { insert.Set("Type", Column.Parameter(type)); } insert.Execute(); }
private void CreateReminding(Entity entity, string lczStringName, string caption, params object[] parameters) { string description = string.Empty; if (parameters.Any()) { description = string.Format(GetLczStringValue(lczStringName), parameters); } else { description = GetLczStringValue(lczStringName); } MailingUtilities.CreateReminding(UserConnection, entity, description, caption); }
public static void SaveBulkEmailHyperlinks(Guid bulkEmailId, string templateBody, bool replace, UserConnection userConnection) { if (replace) { ClearBulkEmailHyperlinks(bulkEmailId, userConnection); } if (string.IsNullOrEmpty(templateBody)) { return; } IDictionary <string, string> hyperlinks = MailingUtilities.ParseHtmlHyperlinks(templateBody); foreach (KeyValuePair <string, string> hyperlink in hyperlinks) { try { if (HasMacros(hyperlink.Key)) { continue; } string decodeUrl = HttpUtility.UrlDecode(hyperlink.Key); string url = UtmHelper.RemoveUtmFromUri(decodeUrl); string caption = string.IsNullOrEmpty(hyperlink.Value) ? url : hyperlink.Value; decodeUrl = HttpUtility.UrlDecode(url.ToLower()); Guid hashLink = MailingUtilities.GetMD5HashGuid(decodeUrl); var bulkEmailHyperlink = new BulkEmailHyperlink(userConnection); Dictionary <string, object> conditions = new Dictionary <string, object> { { "BulkEmail", bulkEmailId }, { "Hash", hashLink } }; if (!bulkEmailHyperlink.FetchFromDB(conditions)) { bulkEmailHyperlink.SetDefColumnValues(); bulkEmailHyperlink.BulkEmailId = bulkEmailId; bulkEmailHyperlink.Caption = caption; bulkEmailHyperlink.Url = url; bulkEmailHyperlink.Hash = hashLink; bulkEmailHyperlink.Save(); } } catch (Exception e) { MailingUtilities.Log.ErrorFormat( "[BulkEmailHyperlinkHelper.SaveBulkEmailHyperlinks]: Error while saving BulkEmailHyperlink" + " \"{0}\" for BulkEmail with Id: {1}", e, hyperlink, bulkEmailId); } } }
/// <summary> /// Adds parameters to template <paramref name="links"/>. /// </summary> /// <param name="links">Template links.</param> private static Dictionary <string, string> ModifyTemplateLinks(IEnumerable <string> links) { var results = new Dictionary <string, string>(); foreach (string link in links) { string modifiedLink = link; string linkHref = MailingUtilities.ParseHtmlHrefValue(modifiedLink); if (!string.IsNullOrEmpty(linkHref)) { string decodedLinkHref = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(linkHref)); string modifiedLinkHref = AddParametersToLink(decodedLinkHref); modifiedLink = link.ReplaceFirstInstanceOf(linkHref, HttpUtility.HtmlEncode(modifiedLinkHref)); } results[link] = modifiedLink; } return(results); }
/// <summary> /// Parses the web hook. /// </summary> /// <param name="data">The web hook data.</param> /// <returns>The web hook.</returns> private JArray ParseWebHook(byte[] data) { var webhook = new JArray(); if (data == null) { return(webhook); } var stream = new MemoryStream(data); try { string jsonString = MailingUtilities.DecompressToString(stream); webhook = JArray.Parse(jsonString); } catch (Exception e) { webhook = null; MailingUtilities.WebHookLog.ErrorFormat("[WebHookHandler.WebHookLog]", e); } return(webhook); }
protected bool IsMandrillProviderActive() { return(MandrillProviderId == MailingUtilities.GetActiveProviderId(_userConnection)); }
private IEnumerable <string> GetUrlElementsWithMacro(string src) { var urlHtmlElements = MailingUtilities.ParseHtmlAnchorElement(src); return(urlHtmlElements.Where(x => _macroNameRegex.IsMatch(x))); }
private void CreateReminding(Entity entity, string lczStringName, string caption, params object[] parameters) { var description = parameters.Any() ? string.Format(GetLczStringValue(lczStringName), parameters) : GetLczStringValue(lczStringName); MailingUtilities.CreateReminding(Context.UserConnection, entity, description, caption); }