Beispiel #1
0
        /// <summary>
        /// List all Messages of the user's mailbox matching the query.
        /// </summary>
        /// <param name="query">String used to filter Messages returned.</param>
        public List <Message> ListMessages(GmailSearch query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            List <Message> result = new List <Message>();

            UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List(userId);
            if (query.Label != null && query.Label.Any())
            {
                request.LabelIds = new Repeatable <string>(GmailApiHelper.GetLabel(query.Label));
            }
            request.Q = query.ToString();
            do
            {
                ListMessagesResponse response = request.Execute();
                if (response.Messages != null)
                {
                    result.AddRange(response.Messages);
                }
                if (response.NextPageToken != null)
                {
                    request.PageToken = response.NextPageToken;
                }
            }while (!string.IsNullOrEmpty(request.PageToken));
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// List all detailed messages of the user's mailbox matching the query.
        /// </summary>
        /// <param name="query">String used to filter Messages returned.</param>
        public List <Message> ListMessagesDetails(GmailSearch query)
        {
            List <Message> result     = ListMessages(query);
            var            returnList = new List <Message>();

            foreach (var message in result)
            {
                returnList.Add(GetMessage(message.Id));
            }
            return(returnList);
        }