Unknown winmail.dat attachment in email Tuesday, Jul 29 2008 

From my colleague I received an email but with unknown type : winmail.dat
He should send me office document.
I asked him to sent it again, he forwarded the email again but I still received winmail.dat in attachment.

After googling about this I found out that winmail.dat is generated by Outlook (I using thunderbird).
From About.com :

It’s Outlook’s fault, in a way. Or the recipient’s email client’s. If Outlook sends a message using the RTF format (which is not very common outside Outlook) for bold text and other text enhancements, it includes the formatting commands in the winmail.dat file. Receiving email clients that do not understand the code therein display it as a stale attachment. To make matters worse, Outlook may also pack other, regular file attachments in the winmail.dat file.

Fortunately, you can get rid of winmail.dat altogether by making sure Outlook does not even try to send mail using RTF.

And there’s also a way to disable this feature on Outlook. You can open it for more detail.
I would focus on how non-Outlook user can handle this format.
I know I can not ask all Outlook user who sent me attachment to turn off this feature.

So I search a program to open this content type “application/ms-tnef”.
I encounter this good console program : WMdecode
You just need to extract this. When running the program it’ll search winmail.dat in current folder and extract it.
The program working great although it just console application, no GUI.

Other tool I search is add on for Thunderbird.
I found : LookOut
This add on will automatically decode the winmail.dat
Also working great but it won’t decode winmail.dat in emails that you received before installing the add-on.
So I think it’ll only decode winmail.dat on new email received.

Cheers 🙂


Java Application – Make sure only single/one instance running – with File Lock and ShutdownHook Monday, Jul 21 2008 

Often we want to make sure that only 1 instance our application running.
Because something terrible could happen when more than 1 instance running (for example the whole server would exploded and that would make you fired 😉 )

Nevertheless what the reason, one of the way to make this happen is by creating a lock file as a sign that an instance is currently running.
So you application will have this flow:

  1. Check if the lock file exists.
  2. Try to delete the lock file to check if there’s really a running process lock the file.
  3. Get the file lock.
  4. If failed to get the lock file, show error that there’s already an instance running –> the end
  5. If successfully get the lock then go on with your application want to do.
  6. When application ended/closed release the lock and delete the file lock.

package test.jimmy.filelock;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

public class MyApp {

    private static File f;
    private static FileChannel channel;
    private static FileLock lock;

    public static void main(String[] args) {
        try {
            f = new File("RingOnRequest.lock");
            // Check if the lock exist
            if (f.exists()) {
                // if exist try to delete it
            // Try to get the lock
            channel = new RandomAccessFile(f, "rw").getChannel();
            lock = channel.tryLock();
            if(lock == null)
                // File is lock by other application
                throw new RuntimeException("Only 1 instance of MyApp can run.");
            // Add shutdown hook to release lock when application shutdown
            ShutdownHook shutdownHook = new ShutdownHook();

            //Your application tasks here..
            try {
            } catch (InterruptedException e) {

        catch(IOException e)
            throw new RuntimeException("Could not start process.", e);


    public static void unlockFile() {
        // release and delete file lock
        try {
            if(lock != null) {
        } catch(IOException e) {

    static class ShutdownHook extends Thread {

        public void run() {


Technorati Tags: , , , , , ,