using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using CommunityToolkit.Mvvm.Messaging; using Google.Apis.Gmail.v1; using Google.Apis.Gmail.v1.Data; using Google.Apis.Http; using Google.Apis.PeopleService.v1; using Google.Apis.Requests; using Google.Apis.Services; using MailKit; using Microsoft.IdentityModel.Tokens; using MimeKit; using MoreLinq; using Serilog; using Wino.Core.Domain.Entities.Mail; using Wino.Core.Domain.Entities.Shared; using Wino.Core.Domain.Enums; using Wino.Core.Domain.Exceptions; using Wino.Core.Domain.Interfaces; using Wino.Core.Domain.Models.Accounts; using Wino.Core.Domain.Models.MailItem; using Wino.Core.Domain.Models.Synchronization; using Wino.Core.Extensions; using Wino.Core.Http; using Wino.Core.Integration.Processors; using Wino.Core.Requests; using Wino.Core.Requests.Bundles; using Wino.Messaging.UI; namespace Wino.Core.Synchronizers.Mail { public class GmailSynchronizer : BaseMailSynchronizer, IHttpClientFactory { public override uint BatchModificationSize => 1000; public override uint InitialMessageDownloadCountPerFolder => 1200; // It's actually 100. But Gmail SDK has internal bug for Out of Memory exception. // https://github.com/googleapis/google-api-dotnet-client/issues/2603 private const uint MaximumAllowedBatchRequestSize = 10; private readonly ConfigurableHttpClient _googleHttpClient; private readonly GmailService _gmailService; private readonly PeopleServiceService _peopleService; private readonly IGmailAuthenticator _authenticator; private readonly IGmailChangeProcessor _gmailChangeProcessor; private readonly ILogger _logger = Log.ForContext(); public GmailSynchronizer(MailAccount account, IGmailAuthenticator authenticator, IGmailChangeProcessor gmailChangeProcessor) : base(account) { var messageHandler = new GmailClientMessageHandler(authenticator, account); var initializer = new BaseClientService.Initializer() { HttpClientFactory = this }; _googleHttpClient = new ConfigurableHttpClient(messageHandler); _gmailService = new GmailService(initializer); _peopleService = new PeopleServiceService(initializer); _authenticator = authenticator; _gmailChangeProcessor = gmailChangeProcessor; } public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args) => _googleHttpClient; public override async Task GetProfileInformationAsync() { var profileRequest = _peopleService.People.Get("people/me"); profileRequest.PersonFields = "names,photos"; string senderName = string.Empty, base64ProfilePicture = string.Empty, address = string.Empty; var gmailUserData = _gmailService.Users.GetProfile("me"); var gmailProfile = await gmailUserData.ExecuteAsync(); address = gmailProfile.EmailAddress; var userProfile = await profileRequest.ExecuteAsync(); senderName = userProfile.Names?.FirstOrDefault()?.DisplayName ?? Account.SenderName; var profilePicture = userProfile.Photos?.FirstOrDefault()?.Url ?? string.Empty; if (!string.IsNullOrEmpty(profilePicture)) { base64ProfilePicture = await GetProfilePictureBase64EncodedAsync(profilePicture).ConfigureAwait(false); } return new ProfileInformation(senderName, base64ProfilePicture, address); } protected override async Task SynchronizeAliasesAsync() { var sendAsListRequest = _gmailService.Users.Settings.SendAs.List("me"); var sendAsListResponse = await sendAsListRequest.ExecuteAsync(); var remoteAliases = sendAsListResponse.GetRemoteAliases(); await _gmailChangeProcessor.UpdateRemoteAliasInformationAsync(Account, remoteAliases).ConfigureAwait(false); } protected override async Task SynchronizeInternalAsync(SynchronizationOptions options, CancellationToken cancellationToken = default) { _logger.Information("Internal synchronization started for {Name}", Account.Name); // Gmail must always synchronize folders before because it doesn't have a per-folder sync. bool shouldSynchronizeFolders = true; if (shouldSynchronizeFolders) { _logger.Information("Synchronizing folders for {Name}", Account.Name); await SynchronizeFoldersAsync(cancellationToken).ConfigureAwait(false); _logger.Information("Synchronizing folders for {Name} is completed", Account.Name); } // There is no specific folder synchronization in Gmail. // Therefore we need to stop the synchronization at this point // if type is only folder metadata sync. if (options.Type == SynchronizationType.FoldersOnly) return SynchronizationResult.Empty; cancellationToken.ThrowIfCancellationRequested(); bool isInitialSync = string.IsNullOrEmpty(Account.SynchronizationDeltaIdentifier); _logger.Debug("Is initial synchronization: {IsInitialSync}", isInitialSync); var missingMessageIds = new List(); var deltaChanges = new List(); // For tracking delta changes. var listChanges = new List(); // For tracking initial sync changes. /* Processing flow order is important to preserve the validity of history. * 1 - Process added mails. Because we need to create the mail first before assigning it to labels. * 2 - Process label assignments. * 3 - Process removed mails. * This affects reporting progres if done individually for each history change. * Therefore we need to process all changes in one go after the fetch. */ if (isInitialSync) { // Initial synchronization. // Google sends message id and thread id in this query. // We'll collect them and send a Batch request to get details of the messages. var messageRequest = _gmailService.Users.Messages.List("me"); // Gmail doesn't do per-folder sync. So our per-folder count is the same as total message count. messageRequest.MaxResults = InitialMessageDownloadCountPerFolder; messageRequest.IncludeSpamTrash = true; ListMessagesResponse result = null; string nextPageToken = string.Empty; while (true) { if (!string.IsNullOrEmpty(nextPageToken)) { messageRequest.PageToken = nextPageToken; } result = await messageRequest.ExecuteAsync(cancellationToken); nextPageToken = result.NextPageToken; listChanges.Add(result); // Nothing to fetch anymore. Break the loop. if (nextPageToken == null) break; } } else { var startHistoryId = ulong.Parse(Account.SynchronizationDeltaIdentifier); var nextPageToken = ulong.Parse(Account.SynchronizationDeltaIdentifier).ToString(); var historyRequest = _gmailService.Users.History.List("me"); historyRequest.StartHistoryId = startHistoryId; while (!string.IsNullOrEmpty(nextPageToken)) { // If this is the first delta check, start from the last history id. // Otherwise start from the next page token. We set them both to the same value for start. // For each different page we set the page token to the next page token. bool isFirstDeltaCheck = nextPageToken == startHistoryId.ToString(); if (!isFirstDeltaCheck) historyRequest.PageToken = nextPageToken; var historyResponse = await historyRequest.ExecuteAsync(cancellationToken); nextPageToken = historyResponse.NextPageToken; if (historyResponse.History == null) continue; deltaChanges.Add(historyResponse); } } // Add initial message ids from initial sync. missingMessageIds.AddRange(listChanges.Where(a => a.Messages != null).SelectMany(a => a.Messages).Select(a => a.Id)); // Add missing message ids from delta changes. foreach (var historyResponse in deltaChanges) { var addedMessageIds = historyResponse.History .Where(a => a.MessagesAdded != null) .SelectMany(a => a.MessagesAdded) .Where(a => a.Message != null) .Select(a => a.Message.Id); missingMessageIds.AddRange(addedMessageIds); } // Consolidate added/deleted elements. // For example: History change might report downloading a mail first, then deleting it in another history change. // In that case, downloading mail will return entity not found error. // Plus, it's a redundant download the mail. // Purge missing message ids from potentially deleted mails to prevent this. var messageDeletedHistoryChanges = deltaChanges .Where(a => a.History != null) .SelectMany(a => a.History) .Where(a => a.MessagesDeleted != null) .SelectMany(a => a.MessagesDeleted); var deletedMailIdsInHistory = messageDeletedHistoryChanges.Select(a => a.Message.Id); if (deletedMailIdsInHistory.Any()) { var mailIdsToConsolidate = missingMessageIds.Where(a => deletedMailIdsInHistory.Contains(a)).ToList(); int consolidatedMessageCount = missingMessageIds.RemoveAll(a => deletedMailIdsInHistory.Contains(a)); if (consolidatedMessageCount > 0) { // TODO: Also delete the history changes that are related to these mails. // This will prevent unwanted logs and additional queries to look for them in processing. _logger.Information($"Purged {consolidatedMessageCount} missing mail downloads. ({string.Join(",", mailIdsToConsolidate)})"); } } // Start downloading missing messages. await BatchDownloadMessagesAsync(missingMessageIds, cancellationToken).ConfigureAwait(false); // Map remote drafts to local drafts. await MapDraftIdsAsync(cancellationToken).ConfigureAwait(false); // Start processing delta changes. foreach (var historyResponse in deltaChanges) { await ProcessHistoryChangesAsync(historyResponse).ConfigureAwait(false); } // Take the max history id from delta changes and update the account sync modifier. var maxHistoryId = deltaChanges.Max(a => a.HistoryId); if (maxHistoryId != null) { // TODO: This is not good. Centralize the identifier fetch and prevent direct access here. Account.SynchronizationDeltaIdentifier = await _gmailChangeProcessor.UpdateAccountDeltaSynchronizationIdentifierAsync(Account.Id, maxHistoryId.ToString()).ConfigureAwait(false); _logger.Debug("Final sync identifier {SynchronizationDeltaIdentifier}", Account.SynchronizationDeltaIdentifier); } // Get all unred new downloaded items and return in the result. // This is primarily used in notifications. var unreadNewItems = await _gmailChangeProcessor.GetDownloadedUnreadMailsAsync(Account.Id, missingMessageIds).ConfigureAwait(false); return SynchronizationResult.Completed(unreadNewItems); } private async Task SynchronizeFoldersAsync(CancellationToken cancellationToken = default) { try { var localFolders = await _gmailChangeProcessor.GetLocalFoldersAsync(Account.Id).ConfigureAwait(false); var folderRequest = _gmailService.Users.Labels.List("me"); var labelsResponse = await folderRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false); if (labelsResponse.Labels == null) { _logger.Warning("No folders found for {Name}", Account.Name); return; } List insertedFolders = new(); List updatedFolders = new(); List deletedFolders = new(); // 1. Handle deleted labels. foreach (var localFolder in localFolders) { // Category folder is virtual folder for Wino. Skip it. if (localFolder.SpecialFolderType == SpecialFolderType.Category) continue; var remoteFolder = labelsResponse.Labels.FirstOrDefault(a => a.Id == localFolder.RemoteFolderId); if (remoteFolder == null) { // Local folder doesn't exists remotely. Delete local copy. await _gmailChangeProcessor.DeleteFolderAsync(Account.Id, localFolder.RemoteFolderId).ConfigureAwait(false); deletedFolders.Add(localFolder); } } // Delete the deleted folders from local list. deletedFolders.ForEach(a => localFolders.Remove(a)); // 2. Handle update/insert based on remote folders. foreach (var remoteFolder in labelsResponse.Labels) { var existingLocalFolder = localFolders.FirstOrDefault(a => a.RemoteFolderId == remoteFolder.Id); if (existingLocalFolder == null) { // Insert new folder. var localFolder = remoteFolder.GetLocalFolder(labelsResponse, Account.Id); insertedFolders.Add(localFolder); } else { // Update existing folder. Right now we only update the name. // TODO: Moving folders around different parents. This is not supported right now. // We will need more comphrensive folder update mechanism to support this. if (ShouldUpdateFolder(remoteFolder, existingLocalFolder)) { existingLocalFolder.FolderName = remoteFolder.Name; existingLocalFolder.TextColorHex = remoteFolder.Color?.TextColor; existingLocalFolder.BackgroundColorHex = remoteFolder.Color?.BackgroundColor; updatedFolders.Add(existingLocalFolder); } else { // Remove it from the local folder list to skip additional folder updates. localFolders.Remove(existingLocalFolder); } } } // 3.Process changes in order-> Insert, Update. Deleted ones are already processed. foreach (var folder in insertedFolders) { await _gmailChangeProcessor.InsertFolderAsync(folder).ConfigureAwait(false); } foreach (var folder in updatedFolders) { await _gmailChangeProcessor.UpdateFolderAsync(folder).ConfigureAwait(false); } if (insertedFolders.Any() || deletedFolders.Any() || updatedFolders.Any()) { WeakReferenceMessenger.Default.Send(new AccountFolderConfigurationUpdated(Account.Id)); } } catch (Exception) { throw; } } private bool ShouldUpdateFolder(Label remoteFolder, MailItemFolder existingLocalFolder) { var remoteFolderName = GoogleIntegratorExtensions.GetFolderName(remoteFolder.Name); var localFolderName = GoogleIntegratorExtensions.GetFolderName(existingLocalFolder.FolderName); bool isNameChanged = !localFolderName.Equals(remoteFolderName, StringComparison.OrdinalIgnoreCase); bool isColorChanged = existingLocalFolder.BackgroundColorHex != remoteFolder.Color?.BackgroundColor || existingLocalFolder.TextColorHex != remoteFolder.Color?.TextColor; return isNameChanged || isColorChanged; } /// /// Returns a single get request to retrieve the raw message with the given id /// /// Message to download. /// Get request for raw mail. private UsersResource.MessagesResource.GetRequest CreateSingleMessageGet(string messageId) { var singleRequest = _gmailService.Users.Messages.Get("me", messageId); singleRequest.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw; return singleRequest; } /// /// Downloads given message ids per batch and processes them. /// /// Gmail message ids to download. /// Cancellation token. private async Task BatchDownloadMessagesAsync(IEnumerable messageIds, CancellationToken cancellationToken = default) { var totalDownloadCount = messageIds.Count(); if (totalDownloadCount == 0) return; var downloadedItemCount = 0; _logger.Debug("Batch downloading {Count} messages for {Name}", messageIds.Count(), Account.Name); var allDownloadRequests = messageIds.Select(CreateSingleMessageGet); // Respect the batch size limit for batch requests. var batchedDownloadRequests = allDownloadRequests.Batch((int)MaximumAllowedBatchRequestSize); _logger.Debug("Total items to download: {TotalDownloadCount}. Created {Count} batch download requests for {Name}.", batchedDownloadRequests.Count(), Account.Name, totalDownloadCount); // Gmail SDK's BatchRequest has Action delegate for callback, not Task. // Therefore it's not possible to make sure that downloaded item is processed in the database before this // async callback is finished. Therefore we need to wrap all local database processings into task list and wait all of them to finish // Batch execution finishes after response parsing is done. var batchProcessCallbacks = new List(); foreach (var batchBundle in batchedDownloadRequests) { cancellationToken.ThrowIfCancellationRequested(); var batchRequest = new BatchRequest(_gmailService); // Queue each request into this batch. batchBundle.ForEach(request => { batchRequest.Queue(request, (content, error, index, message) => { var downloadingMessageId = messageIds.ElementAt(index); batchProcessCallbacks.Add(HandleSingleItemDownloadedCallbackAsync(content, error, downloadingMessageId, cancellationToken)); downloadedItemCount++; var progressValue = downloadedItemCount * 100 / Math.Max(1, totalDownloadCount); PublishSynchronizationProgress(progressValue); }); }); _logger.Information("Executing batch download with {Count} items.", batchRequest.Count); await batchRequest.ExecuteAsync(cancellationToken); // This is important due to bug in Gmail SDK. // We force GC here to prevent Out of Memory exception. // https://github.com/googleapis/google-api-dotnet-client/issues/2603 GC.Collect(); } // Wait for all processing to finish. await Task.WhenAll(batchProcessCallbacks).ConfigureAwait(false); } /// /// Processes the delta changes for the given history changes. /// Message downloads are not handled here since it's better to batch them. /// /// List of history changes. private async Task ProcessHistoryChangesAsync(ListHistoryResponse listHistoryResponse) { _logger.Debug("Processing delta change {HistoryId} for {Name}", Account.Name, listHistoryResponse.HistoryId.GetValueOrDefault()); foreach (var history in listHistoryResponse.History) { // Handle label additions. if (history.LabelsAdded is not null) { foreach (var addedLabel in history.LabelsAdded) { await HandleLabelAssignmentAsync(addedLabel); } } // Handle label removals. if (history.LabelsRemoved is not null) { foreach (var removedLabel in history.LabelsRemoved) { await HandleLabelRemovalAsync(removedLabel); } } // Handle removed messages. if (history.MessagesDeleted is not null) { foreach (var deletedMessage in history.MessagesDeleted) { var messageId = deletedMessage.Message.Id; _logger.Debug("Processing message deletion for {MessageId}", messageId); await _gmailChangeProcessor.DeleteMailAsync(Account.Id, messageId).ConfigureAwait(false); } } } } private async Task HandleLabelAssignmentAsync(HistoryLabelAdded addedLabel) { var messageId = addedLabel.Message.Id; _logger.Debug("Processing label assignment for message {MessageId}", messageId); foreach (var labelId in addedLabel.LabelIds) { // When UNREAD label is added mark the message as un-read. if (labelId == GoogleIntegratorExtensions.UNREAD_LABEL_ID) await _gmailChangeProcessor.ChangeMailReadStatusAsync(messageId, false).ConfigureAwait(false); // When STARRED label is added mark the message as flagged. if (labelId == GoogleIntegratorExtensions.STARRED_LABEL_ID) await _gmailChangeProcessor.ChangeFlagStatusAsync(messageId, true).ConfigureAwait(false); await _gmailChangeProcessor.CreateAssignmentAsync(Account.Id, messageId, labelId).ConfigureAwait(false); } } private async Task HandleLabelRemovalAsync(HistoryLabelRemoved removedLabel) { var messageId = removedLabel.Message.Id; _logger.Debug("Processing label removed for message {MessageId}", messageId); foreach (var labelId in removedLabel.LabelIds) { // When UNREAD label is removed mark the message as read. if (labelId == GoogleIntegratorExtensions.UNREAD_LABEL_ID) await _gmailChangeProcessor.ChangeMailReadStatusAsync(messageId, true).ConfigureAwait(false); // When STARRED label is removed mark the message as un-flagged. if (labelId == GoogleIntegratorExtensions.STARRED_LABEL_ID) await _gmailChangeProcessor.ChangeFlagStatusAsync(messageId, false).ConfigureAwait(false); // For other labels remove the mail assignment. await _gmailChangeProcessor.DeleteAssignmentAsync(Account.Id, messageId, labelId).ConfigureAwait(false); } } /// /// Prepares Gmail Draft object from Google SDK. /// If provided, ThreadId ties the draft to a thread. Used when replying messages. /// If provided, DraftId updates the draft instead of creating a new one. /// /// MailKit MimeMessage to include as raw message into Gmail request. /// ThreadId that this draft should be tied to. /// Existing DraftId from Gmail to update existing draft. /// private Draft PrepareGmailDraft(MimeMessage mimeMessage, string messageThreadId = "", string messageDraftId = "") { mimeMessage.Prepare(EncodingConstraint.None); var mimeString = mimeMessage.ToString(); var base64UrlEncodedMime = Base64UrlEncoder.Encode(mimeString); var nativeMessage = new Message() { Raw = base64UrlEncodedMime, }; if (!string.IsNullOrEmpty(messageThreadId)) nativeMessage.ThreadId = messageThreadId; var draft = new Draft() { Message = nativeMessage, Id = messageDraftId }; return draft; } #region Mail Integrations public override IEnumerable> Move(BatchMoveRequest request) { return CreateBatchedHttpBundleFromGroup(request, (items) => { // Sent label can't be removed from mails for Gmail. // They are automatically assigned by Gmail. // When you delete sent mail from gmail web portal, it's moved to Trash // but still has Sent label. It's just hidden from the user. // Proper assignments will be done later on CreateAssignment call to mimic this behavior. var batchModifyRequest = new BatchModifyMessagesRequest { Ids = items.Select(a => a.Item.Id.ToString()).ToList(), AddLabelIds = [request.ToFolder.RemoteFolderId] }; // Only add remove label ids if the source folder is not sent folder. if (request.FromFolder.SpecialFolderType != SpecialFolderType.Sent) { batchModifyRequest.RemoveLabelIds = [request.FromFolder.RemoteFolderId]; } return _gmailService.Users.Messages.BatchModify(batchModifyRequest, "me"); }); } public override IEnumerable> ChangeFlag(BatchChangeFlagRequest request) { return CreateBatchedHttpBundleFromGroup(request, (items) => { var batchModifyRequest = new BatchModifyMessagesRequest { Ids = items.Select(a => a.Item.Id.ToString()).ToList(), }; if (request.IsFlagged) batchModifyRequest.AddLabelIds = new List() { GoogleIntegratorExtensions.STARRED_LABEL_ID }; else batchModifyRequest.RemoveLabelIds = new List() { GoogleIntegratorExtensions.STARRED_LABEL_ID }; return _gmailService.Users.Messages.BatchModify(batchModifyRequest, "me"); }); } public override IEnumerable> MarkRead(BatchMarkReadRequest request) { return CreateBatchedHttpBundleFromGroup(request, (items) => { var batchModifyRequest = new BatchModifyMessagesRequest { Ids = items.Select(a => a.Item.Id.ToString()).ToList(), }; if (request.IsRead) batchModifyRequest.RemoveLabelIds = new List() { GoogleIntegratorExtensions.UNREAD_LABEL_ID }; else batchModifyRequest.AddLabelIds = new List() { GoogleIntegratorExtensions.UNREAD_LABEL_ID }; return _gmailService.Users.Messages.BatchModify(batchModifyRequest, "me"); }); } public override IEnumerable> Delete(BatchDeleteRequest request) { return CreateBatchedHttpBundleFromGroup(request, (items) => { var batchModifyRequest = new BatchDeleteMessagesRequest { Ids = items.Select(a => a.Item.Id.ToString()).ToList(), }; return _gmailService.Users.Messages.BatchDelete(batchModifyRequest, "me"); }); } public override IEnumerable> CreateDraft(BatchCreateDraftRequest request) { return CreateHttpBundle(request, (item) => { if (item is not CreateDraftRequest singleRequest) throw new ArgumentException("BatchCreateDraftRequest collection must be of type CreateDraftRequest."); Draft draft = null; // It's new mail. Not a reply if (singleRequest.DraftPreperationRequest.ReferenceMailCopy == null) draft = PrepareGmailDraft(singleRequest.DraftPreperationRequest.CreatedLocalDraftMimeMessage); else draft = PrepareGmailDraft(singleRequest.DraftPreperationRequest.CreatedLocalDraftMimeMessage, singleRequest.DraftPreperationRequest.ReferenceMailCopy.ThreadId, singleRequest.DraftPreperationRequest.ReferenceMailCopy.DraftId); return _gmailService.Users.Drafts.Create(draft, "me"); }); } public override IEnumerable> Archive(BatchArchiveRequest request) { return CreateBatchedHttpBundleFromGroup(request, (items) => { var batchModifyRequest = new BatchModifyMessagesRequest { Ids = items.Select(a => a.Item.Id.ToString()).ToList() }; if (request.IsArchiving) { batchModifyRequest.RemoveLabelIds = new[] { GoogleIntegratorExtensions.INBOX_LABEL_ID }; } else { batchModifyRequest.AddLabelIds = new[] { GoogleIntegratorExtensions.INBOX_LABEL_ID }; } return _gmailService.Users.Messages.BatchModify(batchModifyRequest, "me"); }); } public override IEnumerable> SendDraft(BatchSendDraftRequestRequest request) { return CreateHttpBundle(request, (item) => { if (item is not SendDraftRequest singleDraftRequest) throw new ArgumentException("BatchSendDraftRequestRequest collection must be of type SendDraftRequest."); var message = new Message(); if (!string.IsNullOrEmpty(singleDraftRequest.Item.ThreadId)) { message.ThreadId = singleDraftRequest.Item.ThreadId; } singleDraftRequest.Request.Mime.Prepare(EncodingConstraint.None); var mimeString = singleDraftRequest.Request.Mime.ToString(); var base64UrlEncodedMime = Base64UrlEncoder.Encode(mimeString); message.Raw = base64UrlEncodedMime; var draft = new Draft() { Id = singleDraftRequest.Request.MailItem.DraftId, Message = message }; return _gmailService.Users.Drafts.Send(draft, "me"); }); } public override async Task DownloadMissingMimeMessageAsync(IMailItem mailItem, ITransferProgress transferProgress = null, CancellationToken cancellationToken = default) { var request = _gmailService.Users.Messages.Get("me", mailItem.Id); request.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw; var gmailMessage = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false); var mimeMessage = gmailMessage.GetGmailMimeMessage(); if (mimeMessage == null) { _logger.Warning("Tried to download Gmail Raw Mime with {Id} id and server responded without a data.", mailItem.Id); return; } await _gmailChangeProcessor.SaveMimeFileAsync(mailItem.FileId, mimeMessage, Account.Id).ConfigureAwait(false); } public override IEnumerable> RenameFolder(RenameFolderRequest request) { return CreateHttpBundleWithResponse