none
mapi can automatically recurse all users ItemClass is "IPM.Note" item? RRS feed

  • Question

  • I need to get all users more than 100 days before the mailbox, the current cycle of all users, traversing each user's folders and then compare the project one by one, this efficiency is very low, is there any more efficient way?

    Here is my code

    Folder ArchiveMsgFolderRoot = Folder.Bind(service, ID);

    int offset = 0;

    const int pageSize = 900;

     bool MoreItems = true;
    while (MoreItems)
    {
                        SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, true));
                        ItemView view = new ItemView(pageSize, offset, OffsetBasePoint.Beginning);
                        view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
                        FindItemsResults<Item> findResults = service.FindItems(ID, sf, view);
                        foreach (Item myItem in findResults.Items)
                        {
                            try
                            {
                                if (myItem.ItemClass == "IPM.Note")
                                {
                                    DateTime mailtime = myItem.DateTimeReceived;
                                    DateTime nowtime = DateTime.Now;
                                    int ts = (nowtime - mailtime).Days;
                                    if (ts > 100)
                                    {
                                        searchmailvaluebyes_shiti searchmailvaluebyesvalue = new searchmailvaluebyes_shiti();
                                        searchmailvaluebyesvalue.service = service;
                                        searchmailvaluebyesvalue.adaccountguidvalue = adaccountguidvalue;
                                        searchmailvaluebyesvalue.myItem = myItem;
                                        searchmailvaluebyesvalue.getlintoes = getlintoes;
                                        object searchmailvaluebyes_object = searchmailvaluebyesvalue;
                                    }
                                }
                            }
                            catch { }
                        }
                        if (!findResults.MoreAvailable)
                            MoreItems = false;
                        if (MoreItems)
                            offset += pageSize;
                    }
                }

    Friday, December 29, 2017 4:23 AM

Answers

  • >>I used the SearchFilterCollection, you can see the six line of my code。

    But you only have one clause so its kind of useless, the orderby isn't achieving much and also would impact on performance.

    >>I mean, if this user had 10,000 emails, but only 2 of them were 100 days ago, then if I wanted to find out the two emails, I would need to go through the 10,000 emails and compare them mapi branch does not support the direct screening of the way directly to the user to meet all the requirements of the mail

    So why don't you add DateTime restriction to your query that would mean Exchange would only return those mail older then 100 days ?

    Also your using EWS so not sure why your referring to MAPI it a different API

    • Marked as answer by 绅士aa Tuesday, March 6, 2018 9:53 AM
    Saturday, December 30, 2017 9:39 AM

All replies

  • Your question is a little unclear but if you want to make your code more efficient change your searchfilter to include the DateTimeReceived then you can just filter the message you want to look at eg use a SearchFilterCollection  https://msdn.microsoft.com/en-us/library/office/dd633695%28v=exchg.80%29.aspx or you could also do the same thing using AQS https://msdn.microsoft.com/en-us/library/office/dn579420(v=exchg.150).aspx 

    If you say something is inefficiency do a time breakdown of each operation you make to the Exchange server and see where (or if its the volume or request your making) or the time a particular request is taking. Eg because there is probably more code then is showing in your example it maybe you can utilize batching etc to make it run a little faster.

    Friday, December 29, 2017 4:50 AM
  • Hello, thanks for the reply。

    I used the SearchFilterCollection, you can see the six line of my code。

    I mean, if this user had 10,000 emails, but only 2 of them were 100 days ago, then if I wanted to find out the two emails, I would need to go through the 10,000 emails and compare them mapi branch does not support the direct screening of the way directly to the user to meet all the requirements of the mail

    Friday, December 29, 2017 6:24 AM
  • >>I used the SearchFilterCollection, you can see the six line of my code。

    But you only have one clause so its kind of useless, the orderby isn't achieving much and also would impact on performance.

    >>I mean, if this user had 10,000 emails, but only 2 of them were 100 days ago, then if I wanted to find out the two emails, I would need to go through the 10,000 emails and compare them mapi branch does not support the direct screening of the way directly to the user to meet all the requirements of the mail

    So why don't you add DateTime restriction to your query that would mean Exchange would only return those mail older then 100 days ?

    Also your using EWS so not sure why your referring to MAPI it a different API

    • Marked as answer by 绅士aa Tuesday, March 6, 2018 9:53 AM
    Saturday, December 30, 2017 9:39 AM