searchFilter no funciona correctamente con la llamada al método FindItems de EWS
Estoy usando una colección SearchFilter para restringir qué correos electrónicos son devueltos por una solicitud a un buzón de Exchange 2010 usando EWS.
No tengo problemas para conectarme al servicio y abrir el buzón.
El problema es que mi searchFilter está siendo ignorado y la solicitud devuelve todos los correos electrónicos a EWS.
Aquí está mi código:
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(@"bbtest@bocuk.local");
// Find all items where the body contains "move reports".
//string qstring = "Body:\"move reports\"";
// Identify the item properties to return.
//view.PropertySet = new PropertySet(BasePropertySet.IdOnly,
//ItemSchema.Subject);
//creates a folder object that will point to inbox fold
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
//this will bind the mailbox you're looking for using your service instance
Folder inbox = Folder.Bind(service, fid);
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)));
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true)));
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "FATS")));
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Assignment")));
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Sandbox: Assignment")));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
ItemView view = new ItemView(100);
string sAttachmentPath = "C:\\Dev\\EWSHelloWorld\\attachments\\";
// Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
foreach (EmailMessage email in results)
// looping through all the emails
{
System.Diagnostics.Debug.Write("Found attachemnt on msg with subject: " + email.Subject);
.... code removed for brevity!
Por lo tanto, según tengo entendido el searchFilter, solo los correos electrónicos no leídos con archivos adjuntos deben devolverse y debenno tengo GRASAS oSandbox: Asignación como el sujeto.
Pero eso no funciona, la solicitud a EWS simplemente devuelve todos los correos electrónicos.
¿Qué estoy haciendo mal por favor?