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

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

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

I always wonder what would be the perfect development setup for me. Graphical? Command line? IDE? Text editor? VCS? Automation? Now it’s time to sum some things up for myself. (To make sure we speak the same language: i write php, javascript, html, css, and sh. Sometimes a little bit of python.)

I hate IDE’s. They are so bloathed with stuff you don’t need, 99% of the time. But they can be pretty useful… certainly when you have to work with big projects (or other people’s projects), it can help to have a good IDE at hand. Most of the time though, they’re in my way, they create stupid project files, they slow down my laptop and they cost money if you want a decent one. So that’s why i usually let NetBeans sleep, and wake Sublime Text or Vim instead.

Now to compensate for a few things text editors miss, compared to IDE’s. For version control i’m using Git. It’s fantastic. I use vagrant shared folders to have my code right on the development environment while developing.

For debugging, i usually use the php-cli tool in the terminal or Xdebug in the browser. To cope with a lot of ouput, i’ve colorized my prompt line, so that i can find it easily between two var_dumps.

Almost all the above relies on the power of the command line, and applies to both my Trisquel GNU/Linux and Mac OSX setups. I quite like it. On the contrary, everything above is unavailable at the place where i work. No git, no handy command line debugging (cygwin fails to install), no rsync… only a gedit install without plugins. Read more about that here.

That’s about it! 🙂
Toon

For a few years now, i’ve been amazed with how many methods there are for one to install software on his computer (GNU/Linux or Mac OSX).

  • Manual compilation
  • Download binary and put it in place manually
  • Download an installer and let it put the binary in place
  • Work with the package manager of your OS (eg: apt, pacman, yum on linux and fink, macports on OSX)
  • Work with an app store of some sort (Ubuntu Software Center, Mac App Store, …)
  • Various other methods

Let me just sum up some thoughts on every entry.

Manual compilation
This is the most difficult installation methods for non-power users, AND it’s very time-consuming. All dependencies need to be present, a compiler, and the knowledge of how to do it. If you want your software to be installed by a large mainstream population, offering only the source and compile instructions will not be enough. It is, on the other hand a convenient way to distribute software if your program is exclusively for power users, or if it needs every bit of speed and power it can use (since compiling it specifically for your system will make it run extra fast).

Download binary and put it in place manually
This was, until recently, the default installation method for every Mac OSX app. You’d download a compressed disk image (.dmg), mount it, and drag-and-drop the application inside of it to your /Applications directory. It’s quite convenient for installing software, and offers the user control over where to put his app. If this method is used for installing command line programs in /usr/bin or /bin directories, it gets a lot less convenient. You need su or sudo privileges to put it there.

Download an installer and let it put the binary in place
This is my least favorite installation method. You don’t know where the packages are going, and you mostly don’t have control over anything. It makes me think about MS Windows Install exe’s. Examples are the .pkg and .dpkg packages on Mac OSX.

Work with the package manager for your OS
This is a really convenient, and maybe the most convenient, way for users to install software. You look up the package you want to install, the package manager installs it, takes care of the dependencies, updates the software when new versions are released, and can uninstall the package when you want to. It’s mostly a little bit difficult if you want software to be installed on other locations than the defaults. Also, you’re dependent on repositories that other people made, the choose from. On most GNU/Linux systems, this is the preferred way to install software.

Work with an app store of some sort
Mac OSX and Ubuntu both offer an ‘app store’. It’s a convenient way to install and update software (but not to uninstall, on OSX…) for non-power users, and it’s really nice for developers who want to earn money with their apps. The good thing, AND the bad thing about this, is that it’s non-free. Not every application will be allowed in the store (which is, as said previously good and bad at the same time). For developers, it’s handy because the store offers a practical system to earn money for their apps, although Apple takes a percentage of each payment. To me, this is like a package manager for noobs.

Other methods
There are, of course, other methods to install software. Lately i found one i want to talk about. It’s a hybrid between ‘Manually put your binary in place’, and an ‘installer’, to which they added an update mechanism. The way they let you install there software is like this (in a terminal):

curl install.meteor.com | sh
or for wget fans:
wget -O - install.meteor.com | sh

What this does is this: curl or wget downloads a plaintext webpage, and tunnels the output to the sh program. Sh then interprets the text, which is shell a script that determines the OS, processor architecture, and checks if the meteor application (in this case) is already installed or not. After that, it downloads and installs or updates the right package for your OS and processor architecture. I was really amazed by this because it works on both Mac OSX and Linux, and for a whole lot of architectures, so it’s really cross-platform. Also, as a power user, you can first download the plaintext sh script, read it, make changes, and then run it. Nice.

Of course, there are pro’s and con’s to every item of this list, and i don’t even know which one i prefer. You can always try to persuade me in the comments below.

That’s it! 🙂
Toon

Not so long ago, i updated one of my previous posts on ffmpeg with a line on how to record your favourite internet stream to disk with ffmpeg.

Actually that line doesn’t really work well if you want to record a show that’s on the radio every week, on a given day and a given time. People familiar with cron, the unix schedule program, will know you can just give it some coordinates, and it will run your comments at certain intervals. So i tried feeding that particular command to cron, but cron always failed to record my show, because ffmpeg generates way too much output. I found a workaround for that too, by redirecting all output to /dev/null.

How to do it?
(for Mac OSX or any GNU/Linux distro with cron and ffmpeg installed)
1. Determine the ffmpeg command you wish to schedule. Maybe my other posts about ffmpeg can help you.
e.g.: ffmpeg -i http://mp3.streampower.be/stubru-high.mp3 -f mp3 -acodec libmp3lame -ab 128k -ar 44100 -t 02:00:00 /home/toon/Desktop/stubru.mp3

2. Open a terminal window and type this to open your crontab file in a easy editor:
EDITOR=nano crontab -e

3. Determine the 5 crontab schedule numbers to tell cron when to execute your command (1: minute, 2: hour, 3: day of the month, 4: month, 5: day of the week with 0 for sunday). You can use wildcards (*) if you want any digit to be okay, lists (,), or ranges (-). For more info, check this reference.
I want to record every sunday at 19:00h, so for me it’s
0 19 * * 0

4. Insert those in the editor, then insert your command (devide everything with spaces).
When that is done, we still need to add the magical string to make crontab and ffmpeg work together. So type another space, and add this to the end of the crontab line: > /dev/null 2>&1. For me the result looks like this:
0 19 * * 0 ffmpeg -i http://mp3.streampower.be/stubru-high.mp3 -f mp3 -acodec libmp3lame -ab 128k -ar 44100 -t 02:00:00 /home/toon/Desktop/stubru.mp3 > /dev/null 2>&1

5. Press Ctrl+O and Ctrl+X to save and quit the Nano editor.

6. Enjoy Your Scheduled Recordings! 🙂

Firefox Safe Mode

November 22, 2011

Yesterday, Firefox was giving me headaches.
I was just working away, with 20 or more tabs open. Suddenly the browser just quit and shouted out a warning message to tell me it crashed. When i tried to relaunch it, the ‘restore tabs’ window showed, and the browser crashed again two seconds after that. This behaviour was repeated everytime i restarted Firefox, even after a reboot of OSX.

I grew tired of trying and googled if Firefox had a safe mode, and YES! it has one.
On Mac OSX, start Firefox while holding the alt or option button.
On GNU/Linux, open a terminal and type firefox -safe-mode
You’ll get a window giving you some options. i chose ‘disable add-ons’.
(this also works on the free browser ‘Abrowser’ on Trisquel GNU/Linux)

After some goofing around, it seemed there was an error in the ‘HTTPS Everywhere’ add-on, i uninstalled it, and everything was back to normal. Installed the add-on again, and it still works.

Great! another problem solved…
Thanks Mozilla, for building a Safe Mode into your applications 🙂