andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

Support Question #91

Closed sevzas closed 12 years ago

sevzas commented 12 years ago

Apologies - I can't find a support forun for AE.NET.MAIL.

How can I write C# code to create the following SEARCH using SearchCondition objects?

UID SEARCH (OR (ON 20-JUL-2012) (ON 19-JUL-2012)) (FROM address@domain.com) (SUBJECT "NOTIFICATION")

sevzas commented 12 years ago

Something like this will work:

        SearchCondition OnConditions = null;

        for(var currentDate = range.StartDate; currentDate<=range.EndDate; currentDate = currentDate.AddDays(1))
        {
            var theNewCondition = new SearchCondition { Field = SearchCondition.Fields.On, Value = currentDate };
            if (OnConditions == null)
                OnConditions = theNewCondition;
            else
                OnConditions = OnConditions.Or(theNewCondition);
        }

        var searchCondition = OnConditions.And(SearchCondition.From(fromEmailAddress)).And(SearchCondition.Subject(subjectContains));