Skip to content

Commit

Permalink
UntrashMessage() - Remove null execution path
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavminhas committed Jul 27, 2024
1 parent 277cd59 commit 7afb498
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions GmailAPIHelper/GmailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,19 @@ public static bool UntrashMessage(this GmailService gmailService, string query,
}
if (messages.Count > 0)
{
var isMoved = false;
var latestMessage = messages.OrderByDescending(item => item.InternalDate).FirstOrDefault();
var untrashMessageRequest = service.Users.Messages.Untrash(userId, latestMessage.Id);
untrashMessageRequest.Execute();
var labelToAdd = new List<string> { "INBOX" };
service.AddLabels(latestMessage.Id, labelToAdd, userId: userId);
if (latestMessage != null)
{
var untrashMessageRequest = service.Users.Messages.Untrash(userId, latestMessage.Id);
untrashMessageRequest.Execute();
var labelToAdd = new List<string> { "INBOX" };
service.AddLabels(latestMessage.Id, labelToAdd, userId: userId);
isMoved = true;
}
if (disposeGmailService)
service.DisposeGmailService();
return true;
return isMoved;
}
if (disposeGmailService)
service.DisposeGmailService();
Expand Down

0 comments on commit 7afb498

Please sign in to comment.