Dump nixos config after scrubing

This commit is contained in:
Mariano Uvalle 2025-05-03 23:42:03 -07:00
commit 5fa4c76c24
854 changed files with 30072 additions and 0 deletions

View file

@ -0,0 +1,5 @@
EMAIL=
PASSWORD=
MAX_MSG_COUNT=
MAX_BODY_LENGTH=

View file

@ -0,0 +1,2 @@
.venv
.env

View file

@ -0,0 +1,54 @@
# Email widget
This widget consists of an icon with counter which shows number of unread emails: ![email icon](./em-wid-1.png)
and a popup message which appears when mouse hovers over an icon: ![email popup](./em-wid-2.png)
## Installation
1. Clone this repository to your awesome config folder:
```bash
git clone https://github.com/streetturtle/awesome-wm-widgets/email-widget ~/.config/awesome/email-widget
```
2. Make virtual environment and install dependencies:
```bash
cd ~/.config/awesome/email-widget
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
3. Fill .env file with your credentials:
```bash
cp .env.example .env
```
4. Add widget to awesome:
```lua
local email_widget = require("email-widget.email")
...
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
email_widget,
...
```
If you want to reduce time of getting emails, you can change maximum number of emails to be fetched in .env file. Default is 10.
If you want to configure width of popup window, you can change this line in email.lua file:
```lua
width = 800,
```
After this you can change MAX_BODY_LENGTH variable in .env file to change number of characters to be displayed in popup window. Default is 100.
Next step is restarting awesome. You can do this by pressing Mod+Ctrl+r.
## How it works
This widget uses the output of two python scripts, first is called every 20 seconds - it returns number of unread emails and second is called when mouse hovers over an icon and displays content of those emails. For both of them you'll need to provide your credentials and imap server. For testing, they can simply be called from console:
``` bash
python ~/.config/awesome/email-widget/count_unread_emails.py
python ~/.config/awesome/email-widget/read_emails.py
```

View file

@ -0,0 +1,25 @@
import imaplib
import re
from dotenv import load_dotenv
from pathlib import Path
import os
path_to_env = Path(__file__).parent / '.env'
load_dotenv(path_to_env)
EMAIL = os.getenv("EMAIL")
PASSWORD = os.getenv("PASSWORD")
if not EMAIL or not PASSWORD:
print("ERROR:Email or password not set in .env file.")
exit(0)
M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
M.login(EMAIL, PASSWORD)
status, counts = M.status("INBOX", "(MESSAGES UNSEEN)")
if status == "OK":
unread = re.search(r"UNSEEN\s(\d+)", counts[0].decode("utf-8")).group(1)
else:
unread = "N/A"
print(unread)

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,49 @@
local wibox = require("wibox")
local awful = require("awful")
local naughty = require("naughty")
local watch = require("awful.widget.watch")
local currentPath = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
local email_widget = wibox.widget.textbox()
email_widget:set_font('Play 9')
email_widget:set_text("Loading...")
local path_to_python_in_venv = currentPath .. "/.venv/bin/python"
watch(
path_to_python_in_venv.." "..currentPath.."count_unread_emails.py", 20, function(_, stdout)
local is_error = (stdout:match("ERROR") ~= nil)
email_widget:set_text("status: "..tostring(is_error))
if is_error then
email_widget:set_text(stdout)
return
end
local unread_emails_num = tonumber(stdout) or 0
if (unread_emails_num > 0) then
email_widget:set_text(unread_emails_num)
elseif (unread_emails_num == 0) then
email_widget:set_text("")
end
end
)
local function show_emails()
awful.spawn.easy_async(
path_to_python_in_venv.." "..currentPath.."read_unread_emails.py",
function(stdout)
naughty.notify{
text = stdout,
title = "Unread Emails",
timeout = 10, hover_timeout = 0.5,
width = 800,
parse = true,
}
end
)
end
email_widget:connect_signal("mouse::enter", function() show_emails() end)
-- show_emails()
return email_widget

View file

@ -0,0 +1,115 @@
import imaplib
import email
import html2text
import re
from email.header import make_header, decode_header
from pathlib import Path
import os
from dotenv import load_dotenv
path_to_env = Path(__file__).parent / '.env'
load_dotenv(path_to_env)
EMAIL = os.getenv("EMAIL")
PASSWORD = os.getenv("PASSWORD")
MAX_MSG_COUNT = int(os.getenv("MAX_MSG_COUNT", 5))
MAX_BODY_LENGTH = int(os.getenv("MAX_BODY_LENGTH", 100))
GREEN = "\033[1;32m"
END_COLOR = "\033[0m"
UNSEEN_FLAG = "(UNSEEN)"
BODY_PEEK_FLAG = "(BODY.PEEK[])"
def colorful_text(text, color):
"""
Function to format text with Pango markup for color.
"""
return f"<span foreground='{color}'>{text}</span>"
def format_body(body, max_length=MAX_BODY_LENGTH):
body = body.decode("utf-8", errors="ignore")
if "DOCTYPE" in body:
body = html2text.html2text(body)
body = body.replace("\n", "").replace("\r\n", "").replace("", "")
body = re.sub(r"\[.*\]\(.*\)", "", body)
return body if len(body) < max_length else body[:max_length] + "..."
def get_short_email_str(M, num_emails=MAX_MSG_COUNT):
rv, data = M.search(None, UNSEEN_FLAG)
email_list = list(reversed(data[0].split()))[:num_emails]
for num in email_list:
try:
rv, data = M.fetch(num, BODY_PEEK_FLAG)
if rv != "OK":
print("ERROR getting message", num)
continue
msg = email.message_from_bytes(data[0][1])
sender = make_header(decode_header(msg["From"]))
subject = make_header(decode_header(msg["Subject"]))
date = make_header(decode_header(msg["Date"]))
email_info = (
f"From: {colorful_text(str(sender).replace('<', '').replace('>', ''), 'green')}\n"
f"Subject: {colorful_text(str(subject), 'red')}\n"
f"Date: {date}\n"
)
if msg.is_multipart():
for part in msg.walk():
content_type = part.get_content_type()
content_disposition = str(part.get("Content-Disposition"))
if (
content_type == "text/plain"
and "attachment" not in content_disposition
):
body = part.get_payload(decode=True)
email_info += format_body(body)
break
elif (
content_type == "text/html"
and "attachment" not in content_disposition
):
body = part.get_payload(decode=True)
body = html2text.html2text(
body.decode("utf-8", errors="ignore")
)
email_info += format_body(body)
break
else:
body = msg.get_payload(decode=True)
email_info += format_body(body)
email_info += "\n" + "=" * 50 + "\n"
yield email_info
except Exception:
print("ERROR processing message: ", num)
if __name__ == "__main__":
# Example usage:
# read_unread_emails.py
import time
start = time.time()
M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
try:
M.login(EMAIL, PASSWORD)
rv, data = M.select("INBOX")
if rv == "OK":
for email_str in get_short_email_str(M, MAX_MSG_COUNT):
print(email_str)
else:
print("Error selecting INBOX")
except Exception:
print("Error logging in: ", EMAIL)
finally:
M.logout()
print(f"Time taken: {time.time() - start:.2f} seconds")

View file

@ -0,0 +1,2 @@
html2text==2020.1.16
python-dotenv==1.0.0