Example :

Normal when i delete an email ( through lockscreen and quickview)the quickview screen shows the next first unread email.
But if there were only 2 unread emails left then quickview hides, when i delete the first unread mail, instead of showing the last unread mail.
So to see the last email i must click again on the last mail to see it in quickview.
When i delete that last unread mail the quickview doesn't hide automatticly.

I think there must be a +1 or -1 at one of the "new email counter" in your code

Hope you can fix this.