Don't scan if it's at the end

The IMAP scanner will not check if it has reached the end of the string.
Check this first of all and just return NULL if that's the case.

Signed-off-by: Marcus Karlsson <mk@acc.umu.se>