Get a desktop alert when Thunderbird gets constipated

Monday, May 29, 2023

An occasional annoyance with Thunderbird, especially when I travel, is that it gets constipated when the network status changes and won’t send mail. I always send messages in the background with mailnews.sendInBackground = true so they are expected to queue in the local cache file for a bit while I continue productive work and TB does the send negotiation processes in the background without locking me out. Most of the time this works fine but occasionally it hangs and that can be problematic when mail I expected to go out never left my inbox and there’s no notification in TB that the inbox is backed up. Worse, people’s mail clients sort this delayed mail weirdly depending on their local preferences and it may effectively be lost and suddenly everyone seems to be ignoring me, more than usual.

So i wrote a wee python script that will check the Unsent Messages file location and if the file there is larger than a specific size (1 Byte), it sends a message to the desktop using notify-send.

Calling the script from cron every 10 minutes or so uses just 4 msec of CPU according to time, not much of a hit.

You need to know where your local Unsent Messages file is, which TB can tell you if you right click on the Local Folders Outbox and select properties. This path goes into the variable file_name ="..." and you could change the max_size = int(x) to be a larger value than 1 if that’s useful.

How to find the location of your Thunderbird Unsent Messages file

The code to make this work is pretty simple, just:

#!/usr/bin/env python3
import os
import subprocess

# environnement vars
os.environ.setdefault('XAUTHORITY', '/home/user/.Xauthority')
os.environ.setdefault('DISPLAY', ':0.0')
###############################################################
# Enter reasonable values for the Local Folders Outbox which is
# usually in ~/user/.thunderbird/id.user/Mail/Local Folders/Unsent Messages
# and some test file size in bytes, e.g. 1
###############################################################

file_name = "/home/gessel/.thunderbird/idstring.gessel/Mail/Local Folders/Unsent Messages"
max_size = int(1)

def check_file_size(file_name, max_size):
  """Check if a file is larger than a specific size.

  Args:
    file_name: The name of the file to check.
    max_size: The maximum size of the file, in bytes.

  Returns:
    True if the file is larger than max_size, False otherwise.
  """

  file_size = os.path.getsize(file_name)
  return file_size > max_size

def send_notification(message):
  """Send a notification via notify-send.

  Args:
    message: The message to send.
  """

  subprocess.Popen(["notify-send", message])


# Check if the file is larger than the maximum size.
if check_file_size(file_name, max_size):
  # Send a notification.
  message = "Check for constipated mail, the outbox is larger than {} bytes.".format(max_size)
  send_notification(message)

If the test is triggered, you should get a desktop alert:

1x1.trans

Then I created a crontab entry like:

*/10 * * * * /home/gessel/projects/checkoutbox/checkoutbox.py

That’s it. You can test it if want to make sure it will do the right thing by pointing it intentionally at a larger than 0 byte file, assuming your Unsent Messages file is properly 0 bytes most of the time.

I hope you find this useful; please note the usual terms.

Posted at 07:49:17 GMT-0700

Category: HowToLinux

The end of a comic era

Sunday, May 14, 2023

Tonight I listened to the last episode of NPRs excellent and hilarious Ask Me Another, though originally broadcast on 2021-09-24, it didn’t reach my ears until tonight thanks to the magic of podcasts. It was genuinely hard to hear them sign off for the last time. I will really miss this show and the warmth and good spirits of Ophira Eisenberg and Jonathan Coulton.

I’ve been listening to this show since it started, back so far as to have been over syndicated FM broadcast on KQED at home and since on various digital media over the years wherever I’ve been, even here in Iraq. It suffered when Covid hit, the energy and charm didn’t translate well to zoom and without an audience as so many things didn’t and sadly didn’t live to see Covid restrictions lifted. It would have been fitting if they’d been able to record their last show at The Bell House one more time. Maybe someday they can have a reunion show.

US Public Radio has been an anchor of good quality programming, from Car Talk, which I still listen to weekly despite the questions being increasingly out of touch (though the cars have long been fairly irrelevant) and Fresh Air and Terry Gross‘ voice, which came from my mother’s kitchen radio every afternoon from WHYY about as far back as I can remember.

Posted at 17:42:12 GMT-0700

Category: EventsFunnyMediaPositiveReviews

WordPress forward and back navigation I find pleasing

Sunday, May 7, 2023

A new addition to this site is forward-back navigation at the bottom of posts. I’m not sure why I went 15 years or so without thinking about a reader who might want to browse the scintillating and inspiring topics I cover on a semi-regular basis in details and with such stunning insight but it just never occurred to me until I was messing around with creating topically relevant featured images using Stable Diffusion, but in time the thought came and I’m happy with the result.

This guide from wpbeginner was my starting point. I used their wpb_posts_nav function as a basis, but removed the SVG arrows and navigation aid text to simplify presentation. It ends up looking like this, which I simply added to functions.php of my custom child theme using the theme editor just before the final ; and last line ?>. This version is 100% derivative of the wpbbinner code with some minor deletions to my taste and reversing left/right of previous next as I tend to think of time as flowing left-to-right.

function wpb_posts_nav(){
    $next_post = get_next_post();
    $prev_post = get_previous_post();
      
    if ( $next_post || $prev_post ) : ?>
      
         
      
    

There’s a bit of css that adds some styling. I made a few small changes to my preferences and removed the bits no longer needed and appended this to the very end of the style.css that comes with my template.

/* Post Navigation Code */
.wpb-posts-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 50px;
    align-items: center;
    max-width: 1200px;
    margin: 25px auto;
}
  
.wpb-posts-nav a {
    display: grid;
    grid-gap: 20px;
    align-items: center;
}
  
.wpb-posts-nav > div:nth-child(1) a {
    grid-template-columns: 100px 1fr;
    text-align: left;
}
  
.wpb-posts-nav > div:nth-child(2) a {
    grid-template-columns: 1fr 100px;
    text-align: right;
}
  
.wpb-posts-nav__thumbnail {
    display: block;
    margin: 0;
}
  
.wpb-posts-nav__thumbnail img {
    border-radius: 0px;
}

The last step is to add the nav function call to your single.php page. In my page, it works well just after the endwhile, the code is just and for my theme is placed thus:

...


  
...

I’m happy with the results.

https://www.wpbeginner.com/wp-tutorials/how-to-add-next-previous-links-in-wordpress-ultimate-guide/

Posted at 06:51:51 GMT-0700

Category: CodeSelf-publishingTechnology