Skip to content

Commit

Permalink
MoveMessageToTrash() - 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 97e87e5 commit 277cd59
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions GmailAPIHelper/GmailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,17 @@ public static bool MoveMessageToTrash(this GmailService gmailService, string que
}
if (messages.Count > 0)
{
var isMoved = false;
var latestMessage = messages.OrderByDescending(item => item.InternalDate).FirstOrDefault();
var moveToTrashRequest = service.Users.Messages.Trash(userId, latestMessage.Id);
moveToTrashRequest.Execute();
if (latestMessage != null)
{
var moveToTrashRequest = service.Users.Messages.Trash(userId, latestMessage.Id);
moveToTrashRequest.Execute();
isMoved = true;
}
if (disposeGmailService)
service.DisposeGmailService();
return true;
return isMoved;
}
if (disposeGmailService)
service.DisposeGmailService();
Expand Down

0 comments on commit 277cd59

Please sign in to comment.