[Android General] nielshtc:
No idea where to put this, admin; feel free to move or delete.

There's a lot of really cool custom theming going on with Android and an often important part of that is the visual indication of missed phone calls, new messages, new mail, etc. (unread bubbles next to app icons, in lockscreens, etc.). There's a host of solutions to get this info but for me e-mail counts had always been a bit of a issue. Missed phone calls are tracked by the Android system, and WhatsApp notifications can be counted from the notification bar with Tasker and reset when you open the app because your phone is the only place where you will check your WhatsApp messages. E-mail however is not centralized in Android (yet) so if you use anything else than Gmail the system won't know how many unread mails you have and you could uee a notification counter on your mail app but when a new email arrives it will put the counter on +1, if you then read the e-mail on another device (for example your computer) your notification counter on your phone will still be on +1 even though you read the mail.You then have to open your mail app to get the counter back to 0 again.

That why I made this PHP / Tasker solution for my IMAP mail. This is a PHP script that checks how many unread mails there are in your inbox:

<?php

function mailCount($host, $login, $passwd) {
$mbox = imap_open($host, $login, $passwd);
$mail = '';

if($mail = imap_check($mbox)) {
$msgnos = imap_search($mbox, 'UNSEEN');
return $msgnos;
}
}

$hostname = '{imap.yourhost.com:143/imap}INBOX';
$username = 'your_username';
$password = 'your_password';

$count = mailCount($hostname, $username, $password);

if ($count != "") $number = sizeof($count);
else $number = 0;

echo $number;

Change yourhost, your_username and your_password and the port (143). (if you want to, add some extra security by doing IP or Cookie checks), put the PHP file online on your server. The script will then simply show a number of unread mails in your inbox.

Then you can use Tasker to read this number. Add a tasks (for example CheckMailCount) then add the action Net > HTTP Get. For 'Server:Port' fill in the url of your script (http://www.yourserver.com/unreadmail.php) and set the Mime Type to 'text/*'. Then in the same task add an action Variables > Variable Set. Give the variable a Name (for example: %MAILCOUNT) and set it To %HTTPD. This will set the %MAILCOUNT variable to the result of the last http Get request ie. the number of unread mails.

You now have a tasker variable with the actual number of unread mails in your inbox.

I use this on my WidgetLocker lockscreen so I trigger the task on Event > Display > On. I added a third action in the CheckMailCount action to set a Zooper Variable (Plugin > Zooper Widget Pro >Edit > ZW Variable = MAILNOTI, ZW Text = %MAILCOUNT) you could also make this %HTTPD straight away if you don't use the variable for anything else. You then have the #TMAILNOTI# variable in Zooper to use to display how many unread mails you have in a widget. I don't use the count but I display a mail icon indicating that I have a new mail if the #TMAILNOTI# is anything but 0. I do this by adding a bitmap in Zooper of a mail icon and then in Avanced Parameters I put

$#TMAILNOTI#=0?/sdcard/icons/nomail.png$

This tells Zooper that if the variable #TMAILNOTI# = 0 it should use the bitmap nomail.png in my icons folder on the sd card. nomail.png in my case is simply an empty transparent png.

Hope this helps somebody!