So, broad-stroke, what you'll want to do is look at FolderStorage._refreshSlice in mailslice.js.  If you look in there, you'll see that it knows when we're doing a sync and we're synchronizing through 'now'.  That's the headerIsYoungestKnown case where we set endTS to null.

So now the question are: 1) how do we figure out how many new messages there are, and 2) How do we report it?

1)

I think the best thing may be to latch slice.endTS and slice.endUID before we perform the sync.  After the sync is completed, we can find out the absolute position of that message in the folder now that the sync has completed.  By definition, it had position 0 at the start.  If it has position 4 now, then there are 4 new messages.

There is currently no way to determine the absolute position of a message in the list, but we are thinking about adding a virtual scrolling implementation (or rather, @lightsofapollo is :) which will require us to being able to provide such numbers.  Probably the easiest thing to do is modify FolderStorage.getMessageHeader() to calculate such a value and pass it as an additional argument to the callback on request.  It already knows the 'idx' of the message in a block, so then the only other thing to run along the headerBlockInfos prior to that block and count up the number of messages they know about.  Sum them together, pass in the value.  Bingo bingo bango.

2)

I'm a bit conflicted here.  The easiest way to do this is to add an additional flag to SliceBridgeProxy in mailbridge.js which we send via sendSplice.  I'm not crazy about how much stuff we propagate each time because it seems inelegant, but it works.  I'm definitely open to ideas here.