Пример #1
0
        private static void ParseBody(Rule r, MyRule mr)
        {
            if (r.Conditions.Body.Enabled)
            {
                string[] temp = r.Conditions.Body.Text;

                for (int i = 0; i < temp.Length; i++)
                {
                    mr.HasTheWord += temp[i];

                    if (i != temp.Length - 1)
                    {
                        mr.HasTheWord += " OR ";
                    }
                }
            }
        }
Пример #2
0
        private static void ParseSubject(Rule r, MyRule mr)
        {
            if (r.Conditions.Subject.Enabled)
            {
                string[] temp = r.Conditions.Subject.Text;

                for (int i = 0; i < temp.Length; i++)
                {
                    mr.Subject += temp[i];

                    if (i != temp.Length - 1)
                    {
                        mr.Subject += " OR ";
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Parses a rule for the CopyToFolder action
 /// Converts the action of a GMail label but does not set the ShouldArchive option
 /// </summary>
 /// <param name="r"></param>
 /// <param name="mr"></param>
 private static void ParseLabelCopy(Rule r, MyRule mr, string storeName)
 {
     try
     {
         if (r.Actions.CopyToFolder.Enabled)
         {
             MAPIFolder folder = r.Actions.CopyToFolder.Folder;
             if (folder != null)
             {
                 mr.Label = CleanRuleActions(folder.FolderPath, storeName);
             }
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Пример #4
0
        /// <summary>
        /// condition from email address & move to folder
        /// mupports multiple addresses in the from
        /// </summary>
        /// <param name="r"></param>
        /// <param name="mr"></param>
        private static void ParseFromAddresses(Rule r, MyRule mr)
        {
            if (r.Conditions.From.Recipients.Count > 0)
            {
                for (int i = 1; i <= r.Conditions.From.Recipients.Count; i++)
                {
                    string temp = "";
                    // voodo to extract email addresses
                    try
                    {
                        OlAddressEntryUserType addressType = r.Conditions.From.Recipients[i].AddressEntry.AddressEntryUserType;

                        if ((addressType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) || (addressType == OlAddressEntryUserType.olExchangeUserAddressEntry))
                        {
                            temp = r.Conditions.From.Recipients[i].AddressEntry.GetExchangeUser().PrimarySmtpAddress;
                        }
                        else
                        {
                            if (addressType == OlAddressEntryUserType.olSmtpAddressEntry)
                            {
                                temp = r.Conditions.From.Recipients[i].AddressEntry.Address;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    // compose the address string if there are mutlitple addresses in the from
                    if (!String.IsNullOrEmpty(temp))
                    {
                        if (i == 1)
                        {
                            mr.FromAddress += temp;
                        }
                        else
                        {
                            mr.FromAddress += "," + temp;
                        }
                    }
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Parses a rule for MoveToFolder actions
 /// Converts this to a GMail label also sets the ShouldArchive option on the
 /// gmail filter which applies the label makes the mail skip the gmail inbox
 ///
 /// </summary>
 /// <param name="r"></param>
 /// <param name="mr"></param>
 private static void ParseLabelMove(Rule r, MyRule mr, string storeName)
 {
     try
     {
         if (r.Actions[1].ActionType == OlRuleActionType.olRuleActionMoveToFolder)
         {
             if (r.Actions.MoveToFolder.Enabled)
             {
                 MAPIFolder folder = r.Actions.MoveToFolder.Folder;
                 if (folder != null)
                 {
                     mr.Label         = CleanRuleActions(folder.FolderPath, storeName);
                     mr.ShouldArchive = true;
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Пример #6
0
        /// <summary>
        /// Gets a list of rules and associated actions from the given store
        /// Currently only working for rules defined on from addresses, will add support for other rules soon
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static List <MyRule> GetRules(Store s, string storeName)
        {
            Rules         rules     = s.GetRules();
            List <MyRule> rulesList = new List <MyRule>();

            foreach (Rule r in rules)
            {
                if (r.Enabled)
                {
                    MyRule mr = new MyRule();

                    ParseFromAddresses(r, mr);
                    ParseLabelMove(r, mr, storeName);
                    ParseLabelCopy(r, mr, storeName);
                    ParseSubject(r, mr);
                    ParseBody(r, mr);

                    rulesList.Add(mr);
                }
            }

            return(rulesList);
        }
Пример #7
0
        /// <summary>
        /// Gets a list of rules and associated actions from the given store
        /// Currently only working for rules defined on from addresses, will add support for other rules soon
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static List<MyRule> GetRules(Store s, string storeName)
        {
            Rules rules = s.GetRules();
            List<MyRule> rulesList = new List<MyRule>();

            foreach (Rule r in rules)
            {
                if (r.Enabled)
                {
                    MyRule mr = new MyRule();

                    ParseFromAddresses(r, mr);
                    ParseLabelMove(r, mr, storeName);
                    ParseLabelCopy(r, mr, storeName);
                    ParseSubject(r, mr);
                    ParseBody(r, mr);

                    rulesList.Add(mr);
                }
            }

            return rulesList;
        }
Пример #8
0
        private static void ParseSubject(Rule r, MyRule mr)
        {
            if (r.Conditions.Subject.Enabled)
            {
                string[] temp = r.Conditions.Subject.Text;

                for (int i = 0; i < temp.Length; i++)
                {
                    mr.Subject += temp[i];

                    if (i != temp.Length - 1)
                        mr.Subject += " OR ";
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Parses a rule for MoveToFolder actions
 /// Converts this to a GMail label also sets the ShouldArchive option on the 
 /// gmail filter which applies the label makes the mail skip the gmail inbox
 /// 
 /// </summary>
 /// <param name="r"></param>
 /// <param name="mr"></param>
 private static void ParseLabelMove(Rule r, MyRule mr, string storeName)
 {
     try
     {
         if (r.Actions[1].ActionType == OlRuleActionType.olRuleActionMoveToFolder)
         {
             if (r.Actions.MoveToFolder.Enabled)
             {
                 MAPIFolder folder = r.Actions.MoveToFolder.Folder;
                 if (folder != null)
                 {
                     mr.Label = CleanRuleActions(folder.FolderPath, storeName);
                     mr.ShouldArchive = true;
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Пример #10
0
 /// <summary>
 /// Parses a rule for the CopyToFolder action
 /// Converts the action of a GMail label but does not set the ShouldArchive option
 /// </summary>
 /// <param name="r"></param>
 /// <param name="mr"></param>
 private static void ParseLabelCopy(Rule r, MyRule mr, string storeName)
 {
     try
     {
         if (r.Actions.CopyToFolder.Enabled)
         {
             MAPIFolder folder = r.Actions.CopyToFolder.Folder;
             if (folder != null)
             {
                 mr.Label = CleanRuleActions(folder.FolderPath, storeName);
             }
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Пример #11
0
        /// <summary>
        /// condition from email address & move to folder
        /// mupports multiple addresses in the from
        /// </summary>
        /// <param name="r"></param>
        /// <param name="mr"></param>
        private static void ParseFromAddresses(Rule r, MyRule mr)
        {
            if (r.Conditions.From.Recipients.Count > 0)
            {
                for (int i = 1; i <= r.Conditions.From.Recipients.Count; i++)
                {
                    string temp = "";
                    // voodo to extract email addresses
                    try
                    {
                        OlAddressEntryUserType addressType = r.Conditions.From.Recipients[i].AddressEntry.AddressEntryUserType;

                        if ((addressType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) || (addressType == OlAddressEntryUserType.olExchangeUserAddressEntry))
                        {
                            temp = r.Conditions.From.Recipients[i].AddressEntry.GetExchangeUser().PrimarySmtpAddress;
                        }
                        else
                        {
                            if (addressType == OlAddressEntryUserType.olSmtpAddressEntry)
                            {
                                temp = r.Conditions.From.Recipients[i].AddressEntry.Address;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    // compose the address string if there are mutlitple addresses in the from
                    if (!String.IsNullOrEmpty(temp))
                    {
                        if (i == 1)
                        {
                            mr.FromAddress += temp;
                        }
                        else
                        {
                            mr.FromAddress += "," + temp;
                        }
                    }
                }
            }
        }
Пример #12
0
        private static void ParseBody(Rule r, MyRule mr)
        {
            if (r.Conditions.Body.Enabled)
            {
                string[] temp = r.Conditions.Body.Text;

                for (int i = 0; i < temp.Length; i++)
                {
                    mr.HasTheWord += temp[i];

                    if (i != temp.Length - 1)
                        mr.HasTheWord += " OR ";
                }
            }
        }