Esempio n. 1
0
        public IEnumerable <IIncomingEmailMessage> ReadMessages()
        {
            var folder = FolderNameResolver.FindFolderByName(_mailFolder, _service);

            if (folder == null)
            {
                Logger.ErrorFormat("Couldn't find incoming mail folder ({0})", _mailFolder);
                throw new MailFolderNotFoundException(_mailFolder);
            }

            if (folder.TotalCount == 0)
            {
                Logger.DebugFormat("No items found in folder '{0}'. Returning empty list.", _mailFolder);
                return(new List <IIncomingEmailMessage>());
            }

            var items = folder.FindItems(new ItemView(folder.TotalCount)).OrderBy(x => x.DateTimeReceived);

            if (_recipients == null)
            {
                return(items
                       .Where(item => item is EmailMessage)
                       .OrderBy(message => message.DateTimeReceived)
                       .Select(message => new EWSIncomingMessage(message as EmailMessage, this._useConversationGuidOnly))
                       .AsEnumerable());
            }
            else
            {
                return(items
                       .Where(item => item is EmailMessage && ShouldConsiderMessage(item as EmailMessage, _recipients.ToArray()))
                       .OrderBy(message => message.DateTimeReceived)
                       .Select(message => new EWSIncomingMessage(message as EmailMessage, this._useConversationGuidOnly))
                       .AsEnumerable());
            }
        }
        private FolderId GetFolderId(string folderName, ExchangeService service)
        {
            var folder = FolderNameResolver.FindFolderByName(folderName, service);

            if (folder == null)
            {
                Logger.ErrorFormat("Can't find archive folder ({0})", folderName);
                throw new MailFolderNotFoundException(folderName);
            }

            return(folder.Id);
        }