protected void Page_Load(object sender, EventArgs e) { Title = Format(TitleTag, PublicMasterPage.SiteName); H1.InnerHtml = Format(H1Tag, PublicMasterPage.SiteName); MetaDescription = Format(MetaDescriptionTag); var email = GetQueryString("email"); if (Validation.IsValidEmailAddress(email)) { EmailEntry.Visible = false; EmailFixedAddress.InnerText = email; } else { EmailFixed.Visible = false; AddressEntryBlock.Style.Add(HtmlTextWriterStyle.Display, "none"); } }
protected static bool ValidateEmail(DataItemBase item) { item.StripRedundantWhiteSpace(); var value = item.DataControl.GetValue(); if (value.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase)) { value = value.Substring(7); } if (!IsNullOrWhiteSpace(value) && !Validation.IsValidEmailAddress(value)) { item.Feedback.PostValidationError(item.DataControl, "We do not recognize the Email as valid"); return(false); } item.DataControl.SetValue(Validation.StripWebProtocol(value)); return(true); }
public static DonorInfo ExtractDonorInfoFromMsg(Stream stream) { var info = new DonorInfo(); var message = new Storage.Message(stream); if (message.BodyText == null) { throw new VoteException("BodyText missing from message"); } var lines = message.BodyText.NormalizeNewLines() .Split('\n') .Select(l => l.Trim()) .ToList(); info.IsReversal = lines.Any(l => l.Contains("reverse their charge")); var dateTimeLine = lines.FirstOrDefault(l => DonorDateTimeRegex.IsMatch(l)); if (dateTimeLine == null) { throw new VoteException("Could not find date and time"); } var match = DonorDateTimeRegex.Match(dateTimeLine); var parsedDate = match.Groups["date"].Value; var parsedTime = match.Groups["time"].Value; if (!DateTime.TryParse(parsedDate + " " + parsedTime, out info.Date)) { throw new VoteException("Could not parse date and time"); } if (!info.IsReversal) { var amountLine = lines.FirstOrDefault(l => DonorAmountRegex.IsMatch(l)); if (amountLine == null) { throw new VoteException("Could not find amount"); } match = DonorAmountRegex.Match(amountLine); var parsedAmount = match.Groups["amount"].Value; if (!decimal.TryParse(parsedAmount, out info.Amount)) { throw new VoteException("Could not parse amount"); } } var billingInfoIndex = lines.FindIndex(l => l == "Billing Information"); if (billingInfoIndex < 0) { throw new VoteException("Could not find Billing Information"); } // Old format : there is a "+++" line after Billing Information that starts the // "real" billing info var plusesIndex = lines.FindIndex(billingInfoIndex + 1, l => l == "+++"); int billingInfoTerminatorIndex; if (plusesIndex >= 0) // old format { billingInfoIndex = plusesIndex; // Billing Information is delimited by a line of all "=" billingInfoTerminatorIndex = lines.FindIndex(billingInfoIndex + 1, l => l.All(c => c == '=')); } else // new format { // Billing Information is delimited by a blank line billingInfoTerminatorIndex = lines.FindIndex(billingInfoIndex + 1, string.IsNullOrWhiteSpace); } if (billingInfoTerminatorIndex < 0) { throw new VoteException("Could not find Billing Information delimiter"); } var billingInfo = lines.Skip(billingInfoIndex + 1) .Take(billingInfoTerminatorIndex - billingInfoIndex - 1) .Where(l => !string.IsNullOrWhiteSpace(l)) .ToList(); // assume last line is email var email = billingInfo.Count > 0 ? billingInfo[billingInfo.Count - 1].Replace("Email: ", string.Empty) : null; if (!Validation.IsValidEmailAddress(email)) { throw new VoteException("Could not find Email"); } info.Email = email; billingInfo.RemoveAt(billingInfo.Count - 1); if (!info.IsReversal) { // assume first line is name if (billingInfo.Count == 0) { throw new VoteException("Could not find Name"); } info.FullName = billingInfo[0]; billingInfo.RemoveAt(0); var parsedName = info.FullName.ParseName(); if (string.IsNullOrWhiteSpace(parsedName.First) || string.IsNullOrWhiteSpace(parsedName.Last)) { throw new VoteException("Could not parse Name"); } info.FirstName = parsedName.First; info.LastName = parsedName.Last; // find the city, state zip line var cityIndex = billingInfo.FindLastIndex(l => DonorCityRegex.IsMatch(l)); if (cityIndex < 0) { throw new VoteException("Could not find City, State Zip"); } match = DonorCityRegex.Match(billingInfo[cityIndex]); info.City = match.Groups["city"].Value; info.StateCode = match.Groups["state"].Value; if (!StateCache.IsValidStateCode(info.StateCode)) { // might be state name info.StateCode = StateCache.GetStateCode(info.StateCode); if (!StateCache.IsValidStateCode(info.StateCode)) { throw new VoteException("Invaid state or state code"); } } info.Zip5 = match.Groups["zip5"].Value; info.Zip4 = match.Groups["zip4"].Value; // everything before city, state zip is address info.Address = string.Join(", ", billingInfo.Take(cityIndex)); // last remaining line is assumed to be phone if it contains any digits info.Phone = billingInfo.Skip(cityIndex + 1) .LastOrDefault() ?? string.Empty; info.Phone = info.Phone.Replace("Phone: ", string.Empty); if (!info.Phone.Any(char.IsDigit)) { info.Phone = string.Empty; } } return(info); }