From 7c2988d4b7bab30127bf26c0aa237c9e487dad7a Mon Sep 17 00:00:00 2001 From: crabvk Date: Thu, 28 Sep 2023 15:20:09 +0500 Subject: [PATCH] Handle header names case insensitively --- README.md | 4 +++- bar_gmail/app.py | 2 +- bar_gmail/gmail.py | 5 +++-- pyproject.toml | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ecf82a2..efe498c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ bar-gmail auth ``` Then just run `bar-gmail` or `bar-gmail --format polybar` periodically to get unread messages count and new message notifications. + Credentials and session are stored in *~/.cache/bar-gmail*. ## Waybar config example @@ -98,7 +99,8 @@ click-left = xdg-open https://mail.google.com/mail/u/0/#inbox ## Script arguments See `bar-gmail --help` for the full list of available subcommands and command arguments. -Possible values for `-s`, `--sound` can be obtained with: + +Possible values for `-s`, `--sound` is obtained with: ```shell ls /usr/share/sounds/freedesktop/stereo/ | cut -d. -f1 diff --git a/bar_gmail/app.py b/bar_gmail/app.py index 9a32721..c5b11e8 100644 --- a/bar_gmail/app.py +++ b/bar_gmail/app.py @@ -60,7 +60,7 @@ def _play_sound(self): def _send_notification(self, message): try: - Popen(['notify-send', *self.notification_args, message['From'], message['Subject']], + Popen(['notify-send', *self.notification_args, message['from'], message['subject']], stderr=open(os.devnull, 'wb')) except FileNotFoundError: pass diff --git a/bar_gmail/gmail.py b/bar_gmail/gmail.py index 38cf155..5d06aaf 100644 --- a/bar_gmail/gmail.py +++ b/bar_gmail/gmail.py @@ -31,8 +31,9 @@ def gmail(self): def _filter_headers(headers: list) -> dict: result = {} for header in headers: - if header['name'] == 'From' or header['name'] == 'Subject': - result[header['name']] = header['value'] + name = header['name'].lower() + if name in ['from', 'subject']: + result[name] = header['value'] return result def authenticate(self) -> bool: diff --git a/pyproject.toml b/pyproject.toml index 61da66e..b8afbfb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bar-gmail" -version = "1.0.2" +version = "1.0.3" description = "Get notifications and unread messages count from Gmail (Waybar/Polybar module)" license = "MIT" readme = "README.md"