Tech

How to computer 🤖

Download from IMAP to .eml

A snippet to download emails from an IMAP server based on a list of failed migrations on Google Workspace. These will be saved according to the IMAP folder structure, in a folder named emails.

The entries.txt should be formatted as such:

email@example.com	Email	<029776C1-7F7D-495B-8643-7B6743D6EAA0@example.com>	Sent Items
import imaplib
import email
import os

# IMAP server settings
imap_server = "imap.example.com"
username = "email@example.com"
password = "Password!"

# Read entries from the file
with open("entries.txt", "r") as file:
    entries = file.read().splitlines()

# Connect to the IMAP server
imap = imaplib.IMAP4_SSL(imap_server)
imap.login(username, password)

# Create the "emails" folder if it doesn't exist
if not os.path.exists("emails"):
    os.makedirs("emails")
    
# Iterate over the entries
for entry in entries:
    # Split the entry into its components
    parts = entry.split("\t")
    if len(parts) == 5:
        email_address, _, message_id, folder, _ = parts
    else:
        email_address, _, message_id, folder = parts
    
    # Select the appropriate folder
    quoted_folder = f'"{folder}"'.replace("/", ".")
    status, _ = imap.select(quoted_folder)

    # Replace '/' with '_' in the folder name to avoid creating subfolders
    folder = folder.replace("/", "_")

    # Create the subfolder if it doesn't exist
    subfolder = os.path.join("emails", folder)
    if not os.path.exists(subfolder):
        os.makedirs(subfolder)

    # Search for the message with the specific message ID
    _, message_numbers = imap.search(None, f'HEADER Message-ID "{message_id}"')

    # Iterate over the message numbers
    for num in message_numbers[0].split():
        # Fetch the message
        _, msg_data = imap.fetch(num, "(RFC822)")

        # Parse the message
        email_message = email.message_from_bytes(msg_data[0][1])

        # Generate a unique filename for the EML file
        filename = f"{message_id}.eml"

        # Save the email as an EML file in the corresponding subfolder
        file_path = os.path.join(subfolder, filename)
        with open(file_path, "w") as eml_file:
            eml_file.write(email_message.as_string())

        print(f"Email exported as {file_path}")

# Logout from the IMAP server
imap.logout()

Migrate to Netlify

So easy... to forget

Migrating an existing static site to Netlify. Easy peasy, but don’t want to keep figuring it out every time.

So here goes.

  1. In the existing repo, install the Netlify CLI: npm i netlify-cli
  2. Create a new site: npx netlify sites:create --manual --with-ci
    1. Select Team
    2. Set Site name
    3. Set build command to bin/hugo/hugo --environment staging -b ${DEPLOY_PRIME_URL}
    4. Set deploy dir to public
    5. Add SSH public key to repo
    6. Set SSH URL
    7. Add Webhook

In the netlify.toml ensure the following is set:

[Read More]

Energy saving for Locus Map

TL;DR

Having a permanent route on the bars can be quite useful, especially if you’re bouncing down a path at 40+ km/h and don’t have the confidence of one-handed steering to turn on the display.

For that you can always buy some energy efficient low-energy LCD navigator device, but I like the abundance of functionality of an Android smartphone running Locus Map.

[Read More]

Kubernetes with containerd using kubeadm

Wanting to learn Kubernetes, I needed to set up a cluster while maintaining a balance between learning the fundamentals and not frustrating myself on the complexity before seeing actual results.

I also want to use the GitLab Agent, as I truly enjoy using GitLab and its CI/CD setup for everyday work. Not sure if all these tools will make life better for my intended use case, I am sure that I’ll learn to use some new and interesting things along the way.

[Read More]

Adding a device to a running Docker (Swarm) container

I have an RFXcom device which allows me to send and receive signals on 433MHz to interact with for example KlikAanKlikUit devices. I’m running Home Assistant in a Docker Swarm, but that has the limitation that you can’t attach devices to the container. At least, it’s not documented…

The following allows you to add a device to any Docker container (swarm or not). The example is geared towards those deploying Docker Swarm services using a GitLab runner, but can be adjusted to any environment.

[Read More]

Decrypting a BinaryBoot TOTP Authenticator backup

After finding out the vendor lock in of this tool, I wanted to get rid of it to move my TOTP generation to Bitwarden. But for that I would either need to setup TOTP again for 20 separate services, or somehow extract the seed from the current generator.

The backup from this tool is a .encrypt file, which encrypts with the password totpauthenticator by default, You can set it under Settings->Encryption Key without knowing the previous password, if you’d like to change it.

[Read More]

OpenAuto in a Peugeot 206

with a built-in Bluetooth car radio

I’ve been using Crankshaft for about a year now, with a Raspberry Pi 3 attached to the 7 inch touch screen display just dropped into the center console with the default fascia removed. It eventually led to a cracked display, which has been mostly glued back together. Still fully operational.

Now I wanted to upgrade to Android Auto Wireless and decided to go for OpenAuto. I wanted to keep my built in radio because it has all the requirements such as a proper amplifier, Bluetooth A2DP and HFP, and steering wheel controls. This was found not to be a problem.

[Read More]

Dual apps Android

Removing the limitation on which apps can be duplicated

Some phones have software available to run two separated/isolated instances of the same app on a device. This may be called Dual Messenger on Samsung devices, or Parallel Apps on OnePlus devices.

Through adb we can add apps which aren’t allowed by default. No root required.

Add non-default app

First we need the user id of the Android user assigned to the secondary apps. Connect your phone, enable USB Debugging in Developer Options, and run the following. You do need adb of course.

[Read More]

Automating Chocolatey with Intune

Intune allows to automatically have software installed on target devices. I found a nice write-up on using this in conjunction with Chocolatey, but realized it could be made much easier. First we’ll prepare the files locally which needs to be done only once, instead of for each application.

Prepare Chocolatey

The following steps depend on Chocolatey, so first follow the previously mentioned write-up on how to install that through Intune.

[Read More]

Awesome list

Making life easier

This is a personal list of tools and manuals which I probably don’t use daily, but will help a bunch when their purpose is needed.

Tools

  • checkinstall - Replaces make install and creates an uninstallable .deb of any ‘regular’ source package.
  • 365 mail forwarding - Allows forwarding of domain mails without a (paid) mailbox in Office 365
  • appimagelauncher - Properly integrates AppImage applications into the OS.

Tricks

SSH Reverse Tunnel

Use the following to create a reverse tunnel which allows you to reach a service from a remote host, which only your local host can reach.

[Read More]