Skip to main content
gmailcount
==========

gmailcount is a simple script to count the number of emails in your gmail
inbox. It's primary purpose is to allow status-bar programs like xmobar or
i3bar to poll your inbox without the need to store your password in plaintext.

Installation
------------

gmailcount is tested on python 3.5. It may work on older versions of python 3.

Installation is simple:

pip3 install gmailcount

with Secret Service support (gnome-keyring):

pip3 install gmailcount[secretservice]

gnome-keyring support also requires the `dbus-python` package which can't be
installed via pip. It can be installed via system package manager (python3-dbus
on Debian) or from source.

If your system keyring isn't working you can install alternative keyring support:

pip3 install gmailcount[altkeyrings]

Alternative keyring support includes keyring backends that should work on
almost any system, but may not be as secure. For more information on keyring
configuration check out the python keyring
[documentation](https://pypi.python.org/pypi/keyring#configure-your-keyring-lib).

Usage
-----

usage: gmailcount [-h] [-s | -d | -p] [-t TIMEOUT] [--debug] email_address

Check gmail message count.

positional arguments:
email_address email address to use

optional arguments:
-h, --help show this help message and exit
-s, --set-password set the password for email_address
-d, --delete-password
delete the password for email_address
-p, --prompt have gmail-count prompt you for your password
-t TIMEOUT, --timeout TIMEOUT
request timeout
--debug print any exception traceback

Before you can use gmailcount in your status bar, you'll need to run it with
the `-s` flag to set the password for your email address. Once you've set your
password it will be stored in your system keyring. Any program using your
gmailcount will need to have access to your keyring.

When used with no flags, gmailcount will print the number of emails in your
inbox to stdout or nothing in case of failure.

Security concerns
-----------------

One of the main goals of gmailcount is to provide a minimum level of
security. To that end, all requests are sent via SSL, passwords are stored in
your system keyring (and are presumably encrypted if your system keyring is
worth anything), and the recommended use pattern is with app passwords on
accounts with two-factor authentication enabled. This allows you to keep your
password out of your dotfiles and encrypted, and to revoke your password in
case your system is compromised.

Obviously though any system that allows your computer to poll your email
without any human interaction isn't going to be ideal from a security
standpoint. gmailcount is only as secure as your system keyring, which
depending on how you use it and your configuration may not be very secure at
all. Certainly if you're using gmailcount in a status bar, any one who
manages to get access to your logged in user account will have access to your
email, and if your keyring is secured by an insufficently strong password,
someone with access to your harddrive may be able to crack your keyring
password and access your gmail password.

Use gmailcount at your own risk! Still, it should be a lot more secure than a
system that just stores your password as plain text at least.

Sample xmobar script
--------------------

Here's an example of a script suitable for use with xmobar:

#!/usr/bin/env sh

url='https://mail.google.com'
email='example@gmail.com'

full_text=$(/path/to/gmailcount -t 0.3 "$email")
full_text=${full_text:-?}

case $full_text in
''|*[!0-9]*) color=\#FF0000 ;;
0) color=\#888888 ;;
*) color=\#00FF00 ;;
esac

echo "<action=\`xdg-open $url\`><fc=$color>✉ $full_text</fc></action>"

Sample i3blocks script
----------------------

Here's one suitable for use with i3blocks:


#!/usr/bin/env sh

url='https://mail.google.com'
email='example@gmail.com'

[ "$BLOCK_BUTTON" = 1 ] && xdg-open "$url"

full_text=$(/path/to/gmailcount -t 0.3 "$email")
full_text=${full_text:-?}

case $full_text in
''|*[!0-9]*) color=\#FF0000 ;;
0) color=\#888888 ;;
*) color=\#00FF00 ;;
esac

echo "$full_text"
echo "$short_text"
echo "$color"

Sample Asynchrnous xmobar script
--------------------------------

Here's a somewhat more sophisticated script for xmobar which never blocks
waiting for the google servers. It works by writing the data asynchronously to
a temp file. The first argument to the script will set a timeout for writing
the data so that you can check gmail just before your status bar updates.
Something similar should work for i3blocks.

#!/usr/bin/env sh

STATUSFILE=/tmp/.gmail-status
GMAILCOUNT=/path/to/gmailcount
SLEEPTIME=${1:-0}
EMAIL='example@gmail.com'
URL='https://mail.google.com'

echo_status() {
echo "<action=\`xdg-open $URL\`><fc=$2><fn=1></fn> $1</fc></action>"
}

write_data() {
sleep "$SLEEPTIME"
full_text=$("$GMAILCOUNT" "$EMAIL")
full_text=${full_text:-?}

case $full_text in
''|*[!0-9]*) color=\#FF0000 ;;
0) color=\#888888 ;;
*) color=\#00FF00 ;;
esac

echo_status "$full_text" "$color" > "$STATUSFILE"
}

touch "$STATUSFILE"
output=$(cat "$STATUSFILE")
[ ! -z "$output" ] && echo "$output" || echo_status "?" \#880088
> "$STATUSFILE"
write_data &

Metadata

Release files for gmailcount 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gmailcount 0.1.5
File Size Uploaded Provenance
gmailcount-0.1.5.tar.gz 5.6 kB Without provenance Details

Release files / gmailcount-0.1.5.tar.gz

Download URL gmailcount-0.1.5.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ce12a8bfe0a4b303c0d1a398f4ad34caf7c66b7d39927f9df8b819bc34329cee
BLAKE2b-256 checksum
How to use checksums
9ab62db300e74273b22b423b4f40e7350d5515d3bfcbd2e7058636fb2877ff0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for gmailcount 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page