One possible solution is serialise the value of unread into a file.
Then change your check from if the number of mails is greater than 0, to if the number of mails is greater than zero or different from the last serialised count from file.
An extension of this is to also serialise the time when a notification is run along with the mail count, this way you extend the check to show the repeat notification (showing 4 emails twice, not every 5 minutes say, but every 3 hours).
So your original check was if unread != "0" :
it would become something like if unread != "0" && unread != serialisedvalue:
. In the show repeat notification time threshold case
it becomes
if unread != "0":
if ((datetime.now() - serialiseddate) < threshold) :
if unread != serialisedvalue:
Where threshold = 3600*3
is for 3 hours.
Sample code for serialising and deserialising is below
#Serialising
try:
# This will create a new file or **overwrite an existing file**.
f = open("mailcount.txt", "w")
try:
f.write(unread + "\n") # Write a string to a file
f.write(datetime.now().strftime('%b %d %Y %I:%M%p'))
finally:
f.close()
except IOError:
pass
#Deserialising
try:
f = open("mailcount.txt", "r")
try:
# Read the entire contents of a file at once.
serialisedvalue = f.readline()
serialseddate = datetime.strptime(f.readline(), '%b %d %Y %I:%M%p')
finally:
f.close()
except IOError:
pass
Another possible solution would be to get the current active notification count somehow and add that to your condition, though I couldn't find a method for doing that using the API that Notify uses.