Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.pagePermissionDefault = new PermissionSet(Permission.CanSendLocalMail);

        PanelTestSent.Visible = false;

        if (!Page.IsPostBack)
        {
            Geographies geoList = _authority.GetGeographiesForOrganization(Organization.PPSE);  // Hack. Should be org agnostic.
            geoList = geoList.RemoveRedundant();
            ViewState["actingOrg"] = Organization.PPSEid;

            if (geoList.Count == 0)
            {
                // Quick Hack for PPFI
                geoList = _authority.GetGeographiesForOrganization(Organization.FromIdentity(Organization.PPFIid));
                geoList = geoList.RemoveRedundant();
                if (geoList.Count != 0)
                {
                    ViewState["actingOrg"] = Organization.PPFIid;
                }
            }


            if (geoList.Count == 0)
            {
                ViewState["actingOrg"] = 0;

                this.LabelGeographies.Text = "You don't have access to any geographic area.";
            }
            else
            {
                this.GeographyTree.Roots = geoList;
            }

            UpdateActivistCount();
            UpdateSmsCosts();

            if (PhoneMessageTransmitter.CheckServiceStatus() == false)
            {
                CheckSms.Enabled = false;
                CheckSms.Text    = "SMS-service not available currently. No reply from server.";
            }
        }
        if (Organization.PPSEid != (int)ViewState["actingOrg"])
        {
            SmsPanel.Visible = false;
        }
        TextSms.Attributes["onkeydown"] = "updateSmsLength(this);";

        //Add the necessary AJAX setting programmatically -- commented out
        // RadAjaxManager1.AjaxSettings.AddAjaxSetting(GeographyTree.FindControl("DropGeographies"), this.PanelRestOfPage);
        // RadAjaxManager1.AjaxSettings.AddAjaxSetting(GeographyTree.FindControl("DropGeographies"), this.LabelGeographies);
        // Controls_v4_WSGeographyTreeDropDown.EmitScripts(this);
    }
Example #2
0
        public static void NotifyBouncingEmails()
        {
            Regex regex = new Regex(@"(?<email>[a-z_0-9\.\+\-]+\@[a-z_0-9\.\-]+)",
                                    RegexOptions.Compiled | RegexOptions.IgnoreCase);

            string  SMSBouncingEmail = ("" + Persistence.Key["SMSBouncingEmail"]).ToUpper().Trim();
            Regex   reIsNo           = new Regex(@"(NO)|(N)|(NEJ)", RegexOptions.IgnoreCase);
            Boolean dontSendSMS      = reIsNo.IsMatch(SMSBouncingEmail);
            Boolean holdSMS          = SMSBouncingEmail == "HOLD";
            int     lastCaseHandled  = 0;

            if (PhoneMessageTransmitter.CheckServiceStatus() == false)
            {
                dontSendSMS = true;
            }

            SupportCase[] cases = null;
            while (lastCaseHandled == 0 || (cases != null && cases.Length > 0))
            {
                cases = GetUndeliverableCases(lastCaseHandled, 100);

                if (cases.Length == 0) // very very important bugfix
                {
                    break;
                }

                foreach (SupportCase @case in cases)
                {
                    lastCaseHandled = @case.Identity;
                    bool attemptRecovery = true;

                    if (@case.Title.ToLower().Contains("ditt medlemskap har"))
                    {
                        // "Ditt medlemskap har gått ut"

                        attemptRecovery = false;
                    }

                    if (@case.Title.ToLower().Contains("press"))
                    {
                        // Press release

                        attemptRecovery = false;
                    }

                    if (attemptRecovery)
                    {
                        string body = GetFirstEventText(@case.Identity);

                        // Strip the mail header

                        int bodySeparator = body.IndexOf("\r\n\r\n");

                        if (bodySeparator > 0)
                        {
                            body = body.Substring(bodySeparator + 4);
                        }
                        else
                        {
                            body = string.Empty;
                        }

                        Match match = regex.Match(body);
                        if (match.Success)
                        {
                            string email  = match.Groups["email"].Value;
                            People people = People.FromMail(email);

                            if (people.Count > 2)
                            {
                                CloseWithComment(@case.Identity,
                                                 "Bounced message closed. More than one person matches the email address. Both marked unreachable.");

                                foreach (Person person in people)
                                {
                                    person.MailUnreachable = true;
                                }
                            }

                            else if (people.Count < 1)
                            {
                                CloseWithComment(@case.Identity,
                                                 "Bounced message closed. No person in the database matches the email address.");
                            }

                            else
                            {
                                // When we get here, there is exactly one person matching in the database

                                Person person = people[0];

                                bool hasActiveMemberships = false;

                                Memberships memberships = person.GetMemberships();

                                foreach (Membership membership in memberships)
                                {
                                    if (membership.Active)
                                    {
                                        hasActiveMemberships = true;
                                    }
                                }

                                if (hasActiveMemberships)
                                {
                                    // Attempt to contact by SMS.
                                    if (!holdSMS)
                                    {
                                        if (person.Phone.Trim().Length > 2)
                                        {
                                            if (dontSendSMS)
                                            {
                                                CloseWithComment(@case.Identity,
                                                                 "The person at phone# " + person.Phone + ", " + person.Name +
                                                                 " (#" + person.Identity +
                                                                 "), was not contacted due to that SMS notification is currently turned off. Bounced message closed.");
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    person.SendPhoneMessage(
                                                        "Piratpartiet: den mailadress vi har till dig (" +
                                                        person.Mail +
                                                        ") studsar. Kontakta [email protected] med ny adress.");
                                                    CloseWithComment(@case.Identity,
                                                                     "Successfully notified the member at phone# " + person.Phone +
                                                                     ", " + person.Name + " (#" + person.Identity +
                                                                     "), about the bounced email using an SMS message. Case closed.");
                                                }
                                                catch (Exception)
                                                {
                                                    CloseWithComment(@case.Identity,
                                                                     "The person at phone# " + person.Phone + ", " + person.Name +
                                                                     " (#" + person.Identity +
                                                                     "), could not be reached over SMS. This member has been marked unreachable. Bounced message closed.");
                                                    person.MailUnreachable = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            CloseWithComment(@case.Identity,
                                                             person.Name + " (#" + person.Identity +
                                                             ") does not have a listed phone number. This member has been marked unreachable. Bounced message closed.");
                                            person.MailUnreachable = true;
                                        }
                                    }
                                }
                                else
                                {
                                    CloseWithComment(@case.Identity,
                                                     "The person at phone# " + person.Phone + ", " + person.Name + " (#" +
                                                     person.Identity +
                                                     ") has no active memberships. Bounced message closed.");
                                }
                            }
                        }
                        else
                        {
                            CloseWithComment(@case.Identity,
                                             "Bounced message closed. No email address could be located.");
                        }
                    }
                    else
                    {
                        CloseWithComment(@case.Identity, "Bounced message closed without attempt of recovery.");
                    }
                }
            }
        }