internal MailboxSearchScope GetScope()
        {
            MailboxSearchScopeType searchScopeType = 0;

            Enum.TryParse <MailboxSearchScopeType>(this.SourceType.ToString(), out searchScopeType);
            MailboxSearchLocation mailboxSearchLocation = 2;

            if (this.SourceLocation == SourceLocation.ArchiveOnly)
            {
                mailboxSearchLocation = 1;
            }
            else if (this.SourceLocation == SourceLocation.PrimaryOnly)
            {
                mailboxSearchLocation = 0;
            }
            MailboxSearchScope mailboxSearchScope = new MailboxSearchScope(this.ReferenceId, mailboxSearchLocation);

            mailboxSearchScope.SearchScopeType = searchScopeType;
            this.TrySaveMailboxInfo();
            foreach (KeyValuePair <string, string> keyValuePair in this.ExtendedAttributes)
            {
                mailboxSearchScope.ExtendedAttributes.Add(new ExtendedAttribute(keyValuePair.Key, keyValuePair.Value));
            }
            return(mailboxSearchScope);
        }
Exemple #2
0
        private void DoMailboxSearchPreviewItems(ExchangeService oExchangeService, string[] sMailboxIds, string sSearchText, MailboxSearchLocation oMailboxSearchLocation, SearchResultType oSearchResultType, int iPageSize, ref ListView oListView)
        {
            this.Cursor = Cursors.WaitCursor;

            //// Note: Specific RBAC Audit permissions needs to be set to use eDiscovery
            //// http://gsexdev.blogspot.com/2014/01/paging-ediscovery-results-with-ews.html
            //// http://technet.microsoft.com/en-us/library/dd298021(v=exchg.150).aspx#roles


            ServiceResponseCollection <SearchMailboxesResponse> oServiceResponseCollection = null;

            int iMbCount = 0;

            MailboxSearchScope[] oMailboxSearchScope = new MailboxSearchScope[sMailboxIds.Length];
            foreach (string sMailboxId in sMailboxIds)
            {
                oMailboxSearchScope[iMbCount] = new MailboxSearchScope(sMailboxId, oMailboxSearchLocation);
                iMbCount++;
            }
            MailboxQuery oMailboxQuery = new MailboxQuery(sSearchText, oMailboxSearchScope);

            MailboxQuery[] arrMailboxQuery = { oMailboxQuery };


            SearchMailboxesParameters oSearchMailboxesParameters = new SearchMailboxesParameters();

            oSearchMailboxesParameters.SearchQueries        = arrMailboxQuery;
            oSearchMailboxesParameters.PageSize             = iPageSize;
            oSearchMailboxesParameters.PageDirection        = SearchPageDirection.Next;
            oSearchMailboxesParameters.PerformDeduplication = false;
            oSearchMailboxesParameters.ResultType           = oSearchResultType;

            ////*********************************************************************//
            //PreviewItemResponseShape PIR = new PreviewItemResponseShape();

            //ExtendedPropertyDefinition epd1 = new
            //    ExtendedPropertyDefinition(0x001A, MapiPropertyType.String); // PR_MESSAGE_CLASS
            //ExtendedPropertyDefinition epd2 = new
            //    ExtendedPropertyDefinition(0x0037, MapiPropertyType.String);  // PR_SUBJECT
            //ExtendedPropertyDefinition[] epa = new ExtendedPropertyDefinition[] { epd1, epd2 };
            //PIR.BaseShape = PreviewItemBaseShape.Default;
            //PIR.AdditionalProperties = epa;
            //oSearchMailboxesParameters.PreviewItemResponseShape = PIR;
            ////*********************************************************************//


            ListViewItem oListItem = null;

            oListView.Clear();
            oListView.View      = View.Details;
            oListView.GridLines = true;
            oListView.Columns.Add("Count", 60, HorizontalAlignment.Left);
            oListView.Columns.Add("MailboxId", 500, HorizontalAlignment.Left);
            oListView.Columns.Add("PrimarySmtpAddress", 250, HorizontalAlignment.Left);
            oListView.Columns.Add("Id", 200, HorizontalAlignment.Left);
            oListView.Columns.Add("ParentId", 200, HorizontalAlignment.Left);
            oListView.Columns.Add("Subject", 500, HorizontalAlignment.Left);
            oListView.Columns.Add("ItemClass", 150, HorizontalAlignment.Left);
            oListView.Columns.Add("CreatedTime", 150, HorizontalAlignment.Left);
            oListView.Columns.Add("SentTime", 150, HorizontalAlignment.Left);
            oListView.Columns.Add("ToRecipients", 150, HorizontalAlignment.Left);
            oListView.Columns.Add("CcRecipients", 150, HorizontalAlignment.Left);
            oListView.Columns.Add("BccRecipients", 150, HorizontalAlignment.Left);
            oListView.Columns.Add("HasAttachment", 100, HorizontalAlignment.Left);
            oListView.Columns.Add("Importance", 100, HorizontalAlignment.Left);
            oListView.Columns.Add("OwaLink", 500, HorizontalAlignment.Left);

            oServiceResponseCollection = _CurrentService.SearchMailboxes(oSearchMailboxesParameters);
            //oSearchMailboxesParameters.PreviewItemResponseShape = new PreviewItemResponseShape( baseshape, extended properties)

            //int iMailboxCount = 0;
            int iResponseCount = 0;

            if (oServiceResponseCollection.OverallResult == ServiceResult.Success)
            {
                if ((oServiceResponseCollection.Count > 0) && (oServiceResponseCollection[0].SearchResult.PreviewItems != null))
                {
                    do
                    {
                        //iMailboxCount++;
                        //iResponseCount = 0;


                        oSearchMailboxesParameters.PageItemReference = oServiceResponseCollection[0].SearchResult.PreviewItems[oServiceResponseCollection[0].SearchResult.PreviewItems.Length - 1].SortValue;


                        foreach (SearchPreviewItem oSearchPreviewItem in oServiceResponseCollection[0].SearchResult.PreviewItems)
                        {
                            iResponseCount++;

                            oListItem = new ListViewItem(iResponseCount.ToString());
                            //oListItem = new ListViewItem(iMailboxCount.ToString() + " : " + iResponseCount.ToString(), 0);

                            oListItem.SubItems.Add(oSearchPreviewItem.Mailbox.MailboxId);
                            oListItem.SubItems.Add(oSearchPreviewItem.Mailbox.PrimarySmtpAddress);
                            oListItem.SubItems.Add(oSearchPreviewItem.Id.UniqueId);

                            if (oSearchPreviewItem.ParentId != null)
                            {
                                oListItem.SubItems.Add(oSearchPreviewItem.ParentId.UniqueId);
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            oListItem.SubItems.Add(oSearchPreviewItem.Subject);
                            oListItem.SubItems.Add(oSearchPreviewItem.ItemClass);

                            if (oSearchPreviewItem.CreatedTime != null)
                            {
                                oListItem.SubItems.Add(oSearchPreviewItem.CreatedTime.ToString());
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            if (oSearchPreviewItem.SentTime != null)
                            {
                                oListItem.SubItems.Add(oSearchPreviewItem.SentTime.ToString());
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            if (oSearchPreviewItem.Sender != null)
                            {
                                oListItem.SubItems.Add(oSearchPreviewItem.Sender);
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            if (oSearchPreviewItem.ToRecipients != null)
                            {
                                oListItem.SubItems.Add(ExpandAddrerssArray(oSearchPreviewItem.ToRecipients));
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            if (oSearchPreviewItem.CcRecipients != null)
                            {
                                oListItem.SubItems.Add(ExpandAddrerssArray(oSearchPreviewItem.CcRecipients));
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            if (oSearchPreviewItem.BccRecipients != null)
                            {
                                oListItem.SubItems.Add(ExpandAddrerssArray(oSearchPreviewItem.BccRecipients));
                            }
                            else
                            {
                                oListItem.SubItems.Add("");
                            }

                            oListItem.SubItems.Add(oSearchPreviewItem.HasAttachment.ToString());
                            oListItem.SubItems.Add(oSearchPreviewItem.Importance.ToString());
                            oListItem.SubItems.Add(oSearchPreviewItem.OwaLink);


                            //if (oSearchPreviewItem.ExtendedProperties != null)
                            //{
                            //    foreach (ExtendedProperty oProp in oSearchPreviewItem.ExtendedProperties)
                            //    {
                            //        System.Diagnostics.Debug.WriteLine("Name:" + oProp.PropertyDefinition.Name);
                            //        System.Diagnostics.Debug.WriteLine("Id:" + oProp.PropertyDefinition.Id.ToString());
                            //        System.Diagnostics.Debug.WriteLine("Tag:"  + oProp.PropertyDefinition.Tag.ToString());
                            //        System.Diagnostics.Debug.WriteLine("Value:" + oProp.Value.ToString());
                            //        System.Diagnostics.Debug.WriteLine("------------------------------");
                            //    }
                            //}


                            oListItem.Tag = new ItemTag(oSearchPreviewItem.Id, oSearchPreviewItem.ItemClass);
                            oListView.Items.AddRange(new ListViewItem[] { oListItem });;
                            oListItem = null;
                        }

                        oServiceResponseCollection = _CurrentService.SearchMailboxes(oSearchMailboxesParameters);
                    } while (oServiceResponseCollection[0].SearchResult.ItemCount > 0);
                }
            }
            else
            {
            }

            this.Cursor = Cursors.Default;
        }