private static string RemoveExtraParametersFromUri(string hyperLink)
        {
            var preparedUrl = HttpUtility.UrlDecode(hyperLink);

            preparedUrl = BulkEmailUtmHelper.RemoveUtmFromUri(preparedUrl);
            return(BulkEmailHyperlinkHelper.RemoveExtraParametersFromUri(preparedUrl));
        }
Esempio n. 2
0
        /// <summary>
        /// This methid decodes a UTF8 encoded path
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string PathDecodeUTF8(string text)
        {
            var output = string.Empty;

            if (text.StartsWith("/"))
            {
                output = "/";
            }

            var elements = text.Split('/');

            foreach (var s in elements)
            {
                if (s == string.Empty)
                {
                    continue;
                }

                if (!output.EndsWith("/"))
                {
                    output += "/";
                }

                // do the normal stuff
                output += HttpUtility.UrlDecode(s);
            }

            if (text.EndsWith("/"))
            {
                output += "/";
            }

            return(output);
        }
Esempio n. 3
0
        private static string BuildUriString(Uri uri, NameValueCollection queryParameters)
        {
            string processedQuery = QueryParametersToQueryString(uri, queryParameters);
            string originalQuery  = HttpUtility.UrlDecode(uri.Query + uri.Fragment);
            string originalUri    = HttpUtility.UrlDecode(uri.OriginalString);

            if (!string.IsNullOrEmpty(originalQuery))
            {
                originalUri = originalUri.Replace(originalQuery, string.Empty);
            }
            return(originalUri + Uri.UnescapeDataString(processedQuery));
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
        /// <summary>
        /// Forming a list of links in which you need to insert utm-tags.
        /// </summary>
        /// <param name="domains">The list of domains.</param>
        /// <param name="templateCode">The email template.</param>
        /// <param name="utmParam">Parameter string with utm-labels.</param>
        /// <param name="unsubscribeMacrosAliases">The collection of aliases of the unsubscription macros.</param>
        /// <returns>List of references in which you need to insert utm-tags.</returns>
        protected static Dictionary <string, string> GetLinksForReplace(List <string> domains, string templateCode,
                                                                        bool useUtm, string utmParam, string requiredUtmParam, IEnumerable <string> unsubscribeMacrosAliases)
        {
            var hyperlinks = new Dictionary <string, string>();

            foreach (Match matchLink in Regex.Matches(templateCode, PatternLink, RegexOptions.IgnoreCase))
            {
                var    link        = matchLink.Groups["link"].Value;
                string decodedLink = HttpUtility.UrlDecode(link);
                // Exclude references in which there is one of the utm-labels
                bool isUtmExist = Regex.Matches(decodedLink, PatternUtmLabel, RegexOptions.IgnoreCase)
                                  .Count > 0 || !useUtm;
                bool isBulkEmailIdExist = Regex.Matches(decodedLink, PatternUtmEmailIdLabel, RegexOptions.IgnoreCase)
                                          .Count > 0 || string.IsNullOrEmpty(requiredUtmParam);
                bool isValidUrl         = IsWellFormedUriString(link);
                bool isUnsubscribeAlias = link.Contains("*|UNSUB");
                foreach (string alias in unsubscribeMacrosAliases)
                {
                    if (link.Contains(alias))
                    {
                        isUnsubscribeAlias = true;
                        break;
                    }
                }
                if (isUnsubscribeAlias || (isUtmExist && isBulkEmailIdExist) || !isValidUrl)
                {
                    continue;
                }
                // Checking domain in link
                bool domainMatched = true;
                var  matchDomain   = Regex.Matches(link, PatternDomain, RegexOptions.IgnoreCase);
                if ((matchDomain.Count == 0) ||
                    (!domains.Any(domain => matchDomain[0].Groups["domain"].Value.Equals(domain, StringComparison.OrdinalIgnoreCase))))
                {
                    domainMatched = false;
                }
                // Exclude a link if it is already added to the list for replacement
                if (hyperlinks.ContainsKey(matchLink.ToString()))
                {
                    continue;
                }

                var matchLinkDetails = Regex.Matches(matchLink.ToString(), PatternPartamInLink, RegexOptions.IgnoreCase);
                if (matchLinkDetails.Count == 1)
                {
                    // Creates a query string
                    string queryString   = matchLinkDetails[0].Groups["query_string"].Value;
                    bool   isLinkChanged = false;
                    if (!isBulkEmailIdExist)
                    {
                        InsertQueryString(ref queryString, requiredUtmParam);
                    }
                    if (!isUtmExist && domainMatched)
                    {
                        InsertQueryString(ref queryString, utmParam);
                    }
                    // Creates new link with utm-labels
                    string resultLink = string.Format("{0}?{1}{2}{3}",
                                                      matchLinkDetails[0].Groups["start"].Value,
                                                      queryString,
                                                      matchLinkDetails[0].Groups["fragment_id"].Value,
                                                      matchLinkDetails[0].Groups["end"].Value);
                    string decodeResultLink = HttpUtility.UrlDecode(resultLink);
                    hyperlinks.Add(matchLink.ToString(), decodeResultLink);
                }
            }
            return(hyperlinks);
        }
Esempio n. 7
0
        public bool GetRequestToken()
        {
            BuildRequestUrl();

            string      content;
            WebResponse response;

            try
            {
                var request = WebRequest.Create(requestUrl);
                request.Method = "GET";
                response       = request.GetResponse();
                using (var sr = new StreamReader(response.GetResponseStream()))
                {
                    content = sr.ReadToEnd();
                }
            }
            catch (WebException ex)
            {
                response = ex.Response;
                if (response != null)
                {
                    using (var sr = new StreamReader(response.GetResponseStream()))
                    {
                        var error = sr.ReadToEnd();
                        Syslog.Write("oauthrequest Error: " + requestUrl + " " + error);
                    }
                }
                return(false);
            }

            parameters = HttpUtility.ParseQueryString(content);

            oauth_token  = parameters["oauth_token"];
            oauth_secret = parameters["oauth_token_secret"];
            switch (type)
            {
            case OAuthTokenType.YAHOO:
                authorize_url = HttpUtility.UrlDecode(parameters["xoauth_request_auth_url"]);
                break;

            case OAuthTokenType.ETSY:
                authorize_url = HttpUtility.UrlDecode(parameters["login_url"]);
                break;

            case OAuthTokenType.TRADEME:
#if DEBUG
                authorize_url = "https://secure.tmsandbox.co.nz/Oauth/Authorize?oauth_token=" + oauth_token;
#else
                authorize_url = "https://secure.trademe.co.nz/Oauth/Authorize?oauth_token=" + oauth_token;
#endif
                break;

            default:
                throw new NotImplementedException();
                break;
            }
            if (String.IsNullOrEmpty(oauth_token) || String.IsNullOrEmpty(oauth_secret) || String.IsNullOrEmpty(authorize_url))
            {
                Syslog.Write(String.Format("{0} OAuth fail", type));
                return(false);
            }
            return(true);
        }
Esempio n. 8
0
 /// <summary>
 /// Converts a string that has been encoded for transmission in a URL into a decoded
 /// string.
 /// </summary>
 /// <param name="url">A URL-encoded string to decode.</param>
 /// <returns>A decoded string.</returns>
 public static string UrlDecode(string url)
 {
     return(HttpUtilityStd.UrlDecode(url));
 }
Esempio n. 9
0
 internal static string UrlDecode(this string encodedValue) => Utility.UrlDecode(encodedValue);
Esempio n. 10
0
 /// <summary>
 /// URL解码
 /// </summary>
 /// <param name="content"></param>
 /// <returns></returns>
 public static string UrlDecode(string content)
 {
     return(HttpHelper.UrlDecode(content));
 }