IMAP email debugging

November 21, 2013

Isn’t it a problem when you have to debug a problem with emails in an existing project? You never know if they are sent and to whom? I just found out that python has an awesome IMAP debugger built in! Just set your project to use these email settings:

IMAP host: localhost
IMAP port: 1025
IMAP user: {leave empty}
IMAP password: {leave empty}

Then you run this in your terminal:

python -m smtpd -n -c DebuggingServer localhost:1025

You’ll now see every mail that’s sent from your application displayed in your terminal!

That’s it… Have fun debugging

Advertisements

1. Check your screen name

Open a terminal and type this command:
xrandr

You’ll get a list of available screen sizes, along with the name of your screen. In my case, that’s default.

2. Run xrandr as an OpenBox startup command

Open the ~/.config/openbox/autostart file, and add this line:
xrandr --output {screen name} --mode {window size} &

e.g.:
xrandr --output default --mode 1280x800 &

That’s it! OpenBox will now use your desired screen resolution at startup.

I recently discovered the awesome GNU Stow application (works on unix-like systems like GNU/Linux or Mac OSX). Stow is a symlink manager, that allows you to easily deploy and remove files to or from a directory.

Setup

Let’s say you have some configuration files in your home directory (eg: .bashrc, .vimrc and a config directory .vim) and you want to have them in git to be able to track your changes and such. It’s not a really good idea to make your whole home directory a git repo. That’s where Stow comes in. Just create a configuration directory, for instance ‘dotfiles’, and create a subdirectory for every app you have configs for. Then place the appropriate files into the right subdirectory, like this:

/home
    /{user}
        /dotfiles
            /vim
                .vimrc
                /.vim
                    ...
            /bash
                .bashrc

You can now make the dotfiles directory a git repository, and keep your dotfiles safe in git. But they’re not yet in the right place, so we’ll ask our symlink manager to fix that for us.

Create symlinks

  1. cd to the dotfiles directory
  2. You can make Stow symlink the files to your homedir like so:
    stow {package}
    where you replace {package} with the name of the subdirectory you created earlier.
  3. If you now want to remove a certain package’s config files, just do this:
    stow --delete {package}

How to install Stow

On Mac OSX

Use Homebrew:
brew install stow

On GNU/Linux

Install stow using your favorite package manager, e.g.:
apt-get install stow

That’s it!

Important

  • This procedure assumes that you’re running a debian based OS, on your local machine. It might work from MacOSX too, possibly using Homebrew to install Privoxy, and from Windows, using the .exe installer for Privoxy and a *nix-like terminal like Mingw or Git Bash.
  • The server OS needs to be unix based for this to work, and you’ll need root access over SSH.
  • We will not have to install anything on the server.

How this works

To allow the server to access the internet, we’ll tunnel the server’s internet traffic through our local computer. To do this, we’ll need to run a simple proxy on our own computer. This proxy usually listens only for local connections. We’ll then port-forward the local port to a port on the server. From the server’s point of view, it then looks as if a proxy server is available on a local port. We can then tunnel certain server’s application’s traffic through that proxy.

Setting up the proxy over SSH

Install Privoxy proxy server and run it

On your local machine
sudo apt-get install privoxy
sudo service restart privoxy

Privoxy should now be running and accepting connections from localhost only, on port 8118.

Log in to the server over ssh and port-forward the privoxy port (8118) over that connection

ssh -R 8118:localhost:8118 root@{server}
This makes the server open port 8118 for connections, which will be forwarded to port 8118 on your local machine, on which privoxy will be listening. Privoxy will then handle the request.

Forwarding traffic over the Proxy

APT

Create or edit the /etc/apt/apt.conf file to set proxy settings for APT
On the server:
vim /etc/apt/apt.conf

Insert this line:
Acquire::http::Proxy "http://127.0.0.1:8118";

At this point, apt will work over the proxy.

The problem now is that we can’t resolve DNS requests over the proxy (We can’t use a SOCKS5 proxy because apt doesn’t work with SOCKS5 out of the box). To solve that problem we’ll edit the /etc/hosts file to contain the repository record.
On the server:
vim /etc/hosts

Insert this line (replace the x’s with the actual ip):
{xx.xx.xx.xx} archive.debian.org

If you don’t know how to get the ip address for archive.debian.org
On your local machine:
nslookup archive.debian.org

Now you should be able to use apt to update or install packages.
Example:
apt-get install git

Other programs

If you want to use the proxy for other programs on the server, like wget or git use this:
http_proxy=127.0.0.1:8118 {command}

This way you’re setting the proxy as an environment variable, while running the command {command}. Most (well-written) command line software will use that variable, but sometimes this won’t work.

Example:
http_proxy=127.0.0.1:8118 wget github.com

That’s it!

Lately, i’ve been working a lot on my ubuntu machine at work. For several reasons, i’ve wanted to swap the ctrl and alt keys:

  1. I’m used to the OSX command key being right there where your thumb rests on the keyboard.
  2. The pinky+index finger combination of ctrl+t or ctrl+v hurted my wrist

since i’m a heavy shortcut/keyboard user, the default ubuntu setup wasn’t working very well for me.

I found the solution here. Create a file in your home dir: ~/.Xmodmap and put this in it:

clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 64 = Control_L
add control = Control_L Control_R
add mod1 = Alt_L Meta_L

It swaps the ctrl and alt keys, and makes your wrists and thumbs happy. There’s only one downside though. The ‘switch application’ key combination of ctrl+tab now becomes a little less handy… But that can be fixed too (keyboard settings > shortcuts).

Regards
Toon

Ubuntu Quick Work Setup

January 4, 2013

Today i installed a dual boot Ubuntu setup on my computer at work. I used the Wubi installer with Ubuntu 12.04 LTS. Here’s what i did to get started pretty quick:

1. Update and upgrade:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

2. Install some software

  • sudo apt-get install git tig chromium-browser apache2 php5 php5-mysql php5-sqlite php5-gd php5-curl php5-xdebug php5-memcached php5-imagick php5-intl phpunit mysql-server vim ffmpeg curl inkscape vlc tree
  • I manually installed Sublime Text 2, a launcher, and some add-ons for it

3. Configure some software

  • Firefox and chrome: tabs, startpage, sync
  • Thunderbird + Exchange setup: my previous post
  • git: global settings (user, email, colors)
  • apache:
    • sudo a2enmod rewrite to enable mod_rewrite
    • sudo a2enmod vhost_alias to enable VirtualHosts
    • Added VirtualDocumentRoot phrase to /etc/apache2/sites-available/default
  • I also set up dropbox to brainlessly sync between my work’s windows and ubuntu setups

That’s about it. Took me less time than i thought it would.

Regards
Toon

Yes, you can use Mozilla’s great e-mail client ‘Thunderbird’ with your Microsoft Exchange account! I’m doing it at work since september now, and it’s working like a charm. Sadly, it’s not very easy to get it to work. We’ll use only free (as in speech) software for this, and this will work on every major operating system (Mac OSX, GNU/Linux, Windows). Here we go!

1. What you’ll need

You can get these programs from their websites, or install them using your favorite package manager.

2. Setup DavMail

First, we’re going to set up DavMail. DavMail is a gateway for the exchange protocol. It will connect to the exchange server for us, and translate everything to standard e-mail and calendar protocols, like IMAP, LDAP, etc… You can then connect Thunderbird to Davmail, instead of connecting it directly to the Exchange server.
The installation of DavMail on every operating system is pretty straightforward, but if you can’t get it installed, there are instructions on the DavMail project site (installation on ubuntu needs a little terminal command to show the system tray icon). Once the program is installed, open the settings panel and fill in the url of your Exchange server in the “URL OWA” field.
http://mail.server.com/owa
Also make sure the ports listed under that field are not in use by other programs, and do not require root permissions. Therefore it’s best to use ports with numbers above 1000.

3. Setup Thunderbird e-mail

If DavMail is installed and set up correctly, you can now install Thunderbird, and add your Exchange account to it. Fill in your name, e-mail address, and password. Thunderbird will most likely try to find your host in it’s database and fail. You’ll have to insert your connection data manually.

First, choose the IMAP protocol. Then, you’ll have to enter hostnames and ports for IMAP and SMTP servers. Use localhost as your host, since the DavMail program is your host and listens on localhost. For the port numbers, insert the portnumbers you chose in the DavMail settings (IMAP will most likely be 2143 and SMTP 2025). As username use your full e-mail address, and as password you should use your e-mail’s password.

If that went right, you can now send and receive e-mails through Thunderbird. But that’s not all there is to Exchange, right?

More info: DavMail howto

4. Setup Thunderbird calendar (Lightning)

Install the Lightning add-on in Thunderbird. Then create a new network calendar. Select CalDav as format, and insert this in the location field (edit the port number, 2080 in my case, to match your DavMail settings, and the e-mail address to match yours):
http://localhost:2080/users/your.name@your.company.com/calendar
Choose a name and a color for the calendar in the next step. After that you’ll be prompted for your username and password. Use your full e-mail address as username and as password you should use your e-mail’s password.

More info: DavMail howto

5. Setup Thunderbird contacts

This will also be handled by DavMail. In Thunderbird, open your address book (‘Contacts’) and click File > New > LDAP Directory
Again, insert the port number you chose in the DavMail settings, and localhost as hostname. Set base context to ou=people, and as user you’ll insert your full e-mail address again. When that’s done, go to Thunderbird’s settings, and in the ‘write’ or ‘compose’ tab, tell Thunderbird to use this directory for address autocompletion.

More info: DavMail howto

That’s it! You can use Thunderbird with your Microsoft Exchange account from now. Say goodbye to Outlook and use the force with Thunderbird! There might be some small bugs here and there, but i’ve been using it for a while now, and never needed outlook for anything. Have fun!

Regards
Toon