Exemplo n.º 1
0
        private void runner_messages_received(object sender, MessageListEventArgs e)
        {
            try
            {
                IEnumerable <SidePOPMailMessage> messages = e.Messages;

                foreach (SidePOPMailMessage message in messages)
                {
                    Email mail_message = Map.from(message).to <Email>();
                    parse_and_send_response(mail_message);
                    save_email_message(mail_message);
                }
            }
            catch (Exception ex)
            {
                Log.bound_to(this).Error("{0} service had an error processing messages on {1} (with user {2}):{3}{4}", ApplicationParameters.name,
                                         Environment.MachineName, Environment.UserName,
                                         Environment.NewLine, ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void parse_and_send_response(Email mail_message)
        {
            string        respond_to = mail_message.from_address.to_lower();
            MailQueryType query_type = mail_processor.parse(mail_message, monitors, authorization_dictionary);

            Log.bound_to(this).Info("{0} received a message from {1} of type {2}.", ApplicationParameters.name, respond_to, query_type.ToString());

            string response_text = string.Empty;

            if (query_type == MailQueryType.Authorized || query_type == MailQueryType.Denied)
            {
                string[] body_words = mail_message.message_body.Split(' ');
                foreach (string body_word in body_words)
                {
                    if (body_word.Contains("@"))
                    {
                        respond_to = body_word.Replace(Environment.NewLine, "");
                        break;
                    }
                }
            }

            switch (query_type)
            {
            case MailQueryType.Denied:
                authorization_dictionary.Add(respond_to, ApprovalType.Denied);
                return;

                break;

            case MailQueryType.Authorized:
                if (!authorization_dictionary.ContainsKey(respond_to.to_lower()))
                {
                    authorization_dictionary.Add(respond_to.to_lower(), ApprovalType.Approved);
                }
                response_text = string.Format("Congratulations - you have been approved!{0}Send 'help' for options", Environment.NewLine);
                break;

            case MailQueryType.Help:
                response_text =
                    string.Format(
                        "Options- send 1:{0}help{0}status{0}config{0}down - errors{0}version{0}sub{0}unsub",
                        Environment.NewLine);
                break;

            case MailQueryType.Status:
                TimeSpan up_time_current = up_time.Elapsed;
                response_text = string.Format("{0} has been up and running for {1} days {2} hours {3} minutes and {4} seconds.", ApplicationParameters.name,
                                              up_time_current.Days, up_time_current.Hours, up_time_current.Minutes, up_time_current.Seconds);
                break;

            case MailQueryType.CurrentDownItems:
                response_text = string.Format("Services currently down:{0}", Environment.NewLine);
                foreach (IMonitor monitor in monitors)
                {
                    if (monitor.who_to_notify_as_comma_separated_list.to_lower().Contains(respond_to))
                    {
                        if (!monitor.status_is_good)
                        {
                            response_text += string.Format("{0}{1}", monitor.name, Environment.NewLine);
                        }
                    }
                }
                break;

            case MailQueryType.Authorizing:
                response_text =
                    string.Format("Bombali notified admin to add you to approved list. If you are added, you will receive a response.");
                break;

            case MailQueryType.Version:
                response_text = string.Format("Bombali is currently running version {0}.", Version.get_version());
                break;

            case MailQueryType.Subscribe:
                if (!subscribers.ContainsKey(respond_to.to_lower()))
                {
                    subscribers.Add(respond_to.to_lower(), respond_to);
                }
                response_text = string.Format("You are now subscribed to receive daily status messages");
                break;

            case MailQueryType.Unsubscribe:
                if (subscribers.ContainsKey(respond_to.to_lower()))
                {
                    subscribers.Remove(respond_to.to_lower());
                }
                response_text = string.Format("You are now unsubscribed from daily status messages");
                break;

            default:
                response_text = string.Format("{0} has not been implemented yet. Please watch for updates.", query_type);
                break;
            }

            send_notification(respond_to, response_text);

            if (query_type == MailQueryType.Authorizing)
            {
                send_notification(BombaliConfiguration.settings.administrator_email,
                                  string.Format("{0} reqests approval. Send approve/deny w/email address. Ex. 'deny [email protected]'", respond_to));
            }
        }
Exemplo n.º 3
0
 private void save_email_message(Email mail_message)
 {
     Log.bound_to(this).Info("{0} is archiving message \"{1}\".", ApplicationParameters.name, mail_message.message_id);
     repository.save_or_update(mail_message);
 }