/// <summary>
        /// Get the next set of emails async.
        /// </summary>
        /// <returns>Task which returns all the pages for the next set of emails.</returns>
        private async Task <IEnumerable <Email> > GetEmailsAsync()
        {
            try
            {
                await UpdatePages();

                IList <Email> emails = new List <Email>();
                ProcessMessages(ref emails);

                while (_nextEmailPageRequest != null)
                {
                    _curEmailPage = await _nextEmailPageRequest.GetAsync();

                    ProcessMessages(ref emails);
                    _nextEmailPageRequest = _curEmailPage.NextPageRequest;
                }
                return(emails);
            }

            catch (ServiceException ex)
            {
                Console.WriteLine("Error getting emails:");
                Console.WriteLine(ex);
                return(null);
            }
        }
 /// <summary>
 /// Get unread emails from a date.
 /// </summary>
 /// <param name="date">date to retrieve emails from.</param>
 /// <returns>Task containing a list of emails from a date.</returns>
 public async Task <IEnumerable <Email> > GetEmailsFromDate(DateTimeOffset date)
 {
     _nextEmailPageRequest = _graphClient.Me.MailFolders.Inbox.Messages
                             .Delta()
                             .Request()
                             .Select("sender,subject,receivedDateTime,body,isread")
                             .Filter($"ReceivedDateTime gt {date.UtcDateTime.ToString("O")}");
     return(await GetEmailsAsync());
 }
Пример #3
0
 /// <summary>
 /// Initializes the NextPageRequest property.
 /// </summary>
 public void InitializeNextPageRequest(IBaseClient client, string nextPageLinkString)
 {
     if (!string.IsNullOrEmpty(nextPageLinkString))
     {
         this.NextPageRequest = new MessageDeltaRequest(
             nextPageLinkString,
             client,
             null);
     }
 }
 /// <summary>
 /// Get the latest emails. This uses the delta token obtained from the last batch.
 /// </summary>
 /// <returns>Task containing list of the latest emails.</returns>
 public async Task <IEnumerable <Email> > GetLatestEmails()
 {
     _nextEmailPageRequest = DeltaRequest();
     _nextEmailPageRequest.QueryOptions.Add(new QueryOption("$deltatoken", GetEmailDeltaToken()));
     return(await GetEmailsAsync());
 }
 /// <summary>
 /// Get all the unread emails (since Jam 2019) and mark them as read.
 /// </summary>
 /// <returns>Task which contains list of unread emails. </returns>
 public async Task <IEnumerable <Email> > GetAllEmails()
 {
     _nextEmailPageRequest = DeltaRequest();
     return(await GetEmailsAsync());
 }
        /// <summary>
        /// Update to the next set of pages.
        /// </summary>
        /// <returns>Task containing the next set of pages.</returns>
        private async Task UpdatePages()
        {
            _curEmailPage = await _nextEmailPageRequest.GetAsync();

            _nextEmailPageRequest = _curEmailPage.NextPageRequest;
        }