Beispiel #1
0
        /// <summary>
        /// Check on mail folder last received asuntos
        /// </summary>
        /// <param name="prmLastDateTimeChecked">Last date registered of check to filter folder</param>
        /// <returns></returns>
        public List <Entidades.Asunto> GetLastAsuntosAdded(DateTime prmLastDateTimeChecked)
        {
            // Generate a new asunto list to return
            List <Entidades.Asunto> lstAsuntoToProcess = new List <Entidades.Asunto>();
            // Get filtering properties for search on inbox
            SearchFilter filterCriteria = getFilterForAsuntosSearch(prmLastDateTimeChecked.AddSeconds(10));
            // Get view with specify properties for search
            ItemView viewContainer = getResultViewForAsuntoList();
            // Generate a collection for matching items
            FindItemsResults <Item> resultOfSearch = mailServiceConnection.FindItems(asuntoFolder, filterCriteria, viewContainer);

            if (resultOfSearch.TotalCount > 0)
            {
                // Generate a new ServiceResponseCollection with items saved
                ServiceResponseCollection <GetItemResponse> itemWithBodyAndDateReceived = mailServiceConnection.BindToItems(resultOfSearch.Select(item => item.Id), new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.DateTimeReceived));
                // Iterates over all results finded
                foreach (var item in itemWithBodyAndDateReceived.Select(item => item.Item).ToArray())
                {
                    // Save temporaly in a variable subject result
                    string subjectWithAsunto = item.Subject;
                    // Get Start point for cutting string resullt
                    int intStartCutString = subjectWithAsunto.IndexOf(startSubstringCut) + startSubstringCut.Length;
                    int intEndCutString   = subjectWithAsunto.LastIndexOf(endSubstringCut);
                    // With end and start can obtain asunto number
                    string asuntoNumber     = subjectWithAsunto.Substring(intStartCutString, (intEndCutString - intStartCutString));
                    string shortDescription = getShortDescriptionByFiltering(item.Body);
                    // Generate a new entidades of asunto and add to list
                    lstAsuntoToProcess.Add(new Entidades.Asunto()
                    {
                        Numero = asuntoNumber, DescripcionBreve = shortDescription, LoadedOnSolucionameDate = item.DateTimeReceived
                    });
                }
            }
            // Return processed list
            return(lstAsuntoToProcess);
        }
Beispiel #2
0
 private MailItem[] getMailItem(ServiceResponseCollection<GetItemResponse> items, ExchangeService service)
 {
     return items.Select(item =>
     {
         return new MailItem()
         {
             message = EmailMessage.Bind(service, item.Item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments, ItemSchema.HasAttachments)),
             From = ((Microsoft.Exchange.WebServices.Data.EmailAddress)item.Item[EmailMessageSchema.From]).Address,
             Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),
             Subject = item.Item.Subject,
             Body = item.Item.Body.ToString(),
             attachment = item.Item.Attachments.ToList(),
         };
     }).ToArray();
 }