HOW TO: Copy Outlook Contacts to Abook

By Sterling “Chip” Camden
Contributing Writer, [GAS]

In the mass migration of end users from Windows to Unix-based workstations, one question that’s asked over and over again is “What will I ever do without Outlook?”

Wait, wait, CUT!  Let’s try that again, from the top.

In the trickle of tech-savvy users who’ve ditched Windows for a better computer, one question that’s asked over and over again is “How did I ever use that pig, Outlook?” — often followed immediately by “How do I get all my Outlook contacts moved over to something else?”

I recently converted to FreeBSD for my main squeeze, and decided on mutt for my new email client, based on recommendations from Chad, Mackenzie, and almost every other console-oriented *n*x geek out there. Mutt, like most good Unix programs, does one thing well: email.  Its support for contact management is minimized to the concept of aliases:  short names associated with full addresses, nothing more.  However, there are a few choices of contact managers that work well with mutt, allowing you to look up contacts while still within mutt.  One that’s specifically designed for use with mutt is abook.  It’s lightweight, uses a simple text file as its database, and provides support for several import/export formats, including CSV (comma-separated values).

Outlook provides an export to CSV.  While in Contacts, select “File/Import and Export…” (Office 2007).

  • Select “Export to a file”, and click “Next”.
  • Select “Comma Separated Values.” There are two possible options here, DOS or Windows. It doesn’t seem to matter which one.  Click “Next”.
  • Select your “Contacts” folder, and click “Next”.
  • Save the file.  I saved mine directly to a Samba-shared folder on my FreeBSD system.  Otherwise, you can copy it over later.
  • Just click “Finish.”  Even though the order of fields as output by Outlook does not match what abook expects, we’ll reorder them with a Ruby script instead of fiddling with the “Map Custom Fields” GUI.  That’s because we also want to combine some fields that Outlook separates.

Now, on the Unix side, you’ll need this script:


#!/usr/bin/env ruby
class String
  def q
    '"' + self + '"'
  end
  def u
    self.sub(/^"(.*)"$/, '\1')
  end
  def c
    self + ','
  end
end
class NilClass
  def u
    ""
  end
  def c
    ','
  end
end

full = ''
$<.each do |line|
  full += line.gsub!(/[\r\n]*/,'')
  if /(,|[^,]")$/ =~ line
    f = full.split /,(?=[,"]|$)/, -1
    full = ''
    print  f[3].c +     # last name
         (f[2].length > 2 ? (f[1].u + ' ' + f[2].u).q : f[1]).c + # first
         f[5].c +       # notes (company)
         (f[3].u + ', ' + f[1].u + ' ' + f[2].u).q.c +          # nickname
         f[31].c +      # workphone
         f[37].c +      # phone
         f[30].c +      # fax
         f[40].c +      # mobile
         f[57].c +      # email
         (f[8].u + ' ' + f[9].u + ' ' + f[10].u).q.c +          # address
         f[11].c +      # city
         f[12].c +      # state
         f[13].c +      # zip
         f[14].c +      # country
         f[87].c + f[88].c + f[89].c + f[90].c + f[91].c +      # custom
         "\n"
  end
end

Save that as ol2ab.rb, and make sure it’s executable.  Then create an intermediate csv file with this shell command:

ol2ab.rb < contacts.CSV > tmpfile.csv

That remaps the columns in the order that abook expects for its “Palm CSV” format.  I chose “Palm CSV” instead of just “CSV” because it imports more fields.  I also mapped “Company” to “notes”, because abook doesn’t have a Company field.  For “nick” (Nickname), I combined the name fields (Last, First M).  And I mapped the four user-defined fields plus the “Web Page” field from Outlook to the five “custom” fields in abook. You may also notice from the script that I account for an odd line-wrapping, the cause of which I do not know.  Some lines of the Outlook-generated CSV file were wrapped on a space.  So, I collect lines until they end appropriately – with either a comma or a quote, but not with the comma-quote combination.  Then I split them into fields on a comma, but only if it is followed by another comma, a quote, or the end of the line.  The regex-savvy amongst you readers will realize that this can be broken by a text field that ends with a comma.  Oh well.

Next, run the new csv file into an abook address file.  First, install abook.  On FreeBSD, it’s in ports in /usr/ports/mail/abook.  Make sure that the directory ~/.abook exists and does not contain the file ‘addressbook’.  Then execute this shell command:

abook --convert --infile tmpfile.csv --informat palmcsv --outfile ~/.abook/addressbook --outformat abook

Voila.  Not all the fields from Outlook have been brought over, but a lot of the important ones were.

Advertisement





12 Responses to HOW TO: Copy Outlook Contacts to Abook

  1. I'm all for variety in Operating Systems. What I don't like is bias. There's no need for the "better computer" crack – as a Windows engineer, I find it does everything I need it to, with a far greater variety of tools available to me than on the Lunix/Unix side of things. Is it perfect? Of course not. But I also don't find myself needing to put down Linux, or OSX, or anything else every time I comment on it, either.

    Another thing this article doesn't touch on is what makes Outlook unique – MAPI support. For generic webmail, and other mail servers, I tend to prefer Thunderbird. But when I'm connecting to Exchange, it's all Outlook for me. In a corporate Exchange environment, there isn't even a guarantee that POP3 or IMAP will be available to use – which is exactly why I don't think Outlook should just be disregarded as a "pig" – like any other software, it serves its purpose.

  2. I’m all for variety in Operating Systems. What I don’t like is bias. There’s no need for the “better computer” crack – as a Windows engineer, I find it does everything I need it to, with a far greater variety of tools available to me than on the Lunix/Unix side of things. Is it perfect? Of course not. But I also don’t find myself needing to put down Linux, or OSX, or anything else every time I comment on it, either.

    Another thing this article doesn’t touch on is what makes Outlook unique – MAPI support. For generic webmail, and other mail servers, I tend to prefer Thunderbird. But when I’m connecting to Exchange, it’s all Outlook for me. In a corporate Exchange environment, there isn’t even a guarantee that POP3 or IMAP will be available to use – which is exactly why I don’t think Outlook should just be disregarded as a “pig” – like any other software, it serves its purpose.

  3. I'm all for people having personal preferences — even biases. What I don't like is confirmation bias and similar problems of logic, or a lack of a sense of humor.

    re: sense of humor

    There's no need to get up in arms over what is, truth be told, something of a self-deprecating joke about being a "condescending Unix computer user".

    re: confirmation bias

    The fact that you aren't aware of the incredible variety of tools available on Unix and unix-like platforms does not actually translate to a true lack of such variety.

    It's also worth noting that Sterling doesn't put down MacOS X or MS Windows or any other modern OS every time he mentions them, either. He made a joke or two about MS Windows in an article talking about how he moved away from MS Windows to another OS. It's actually on-topic for him to talk about the reasons he prefers his new digs over the old. The fact he's a little flippant about it doesn't constitute a dire insult to your manhood, or whatever it is that bothers you about the fact someone has a different preference and is willing to laugh about it.

    As for MAPI . . . that only matters if you actually care about Exchange. Furthermore, Outlook is not unique in its MAPI support; there are other tools that support it as well.

  4. I’m all for people having personal preferences — even biases. What I don’t like is confirmation bias and similar problems of logic, or a lack of a sense of humor.

    re: sense of humor

    There’s no need to get up in arms over what is, truth be told, something of a self-deprecating joke about being a “condescending Unix computer user”.

    re: confirmation bias

    The fact that you aren’t aware of the incredible variety of tools available on Unix and unix-like platforms does not actually translate to a true lack of such variety.

    It’s also worth noting that Sterling doesn’t put down MacOS X or MS Windows or any other modern OS every time he mentions them, either. He made a joke or two about MS Windows in an article talking about how he moved away from MS Windows to another OS. It’s actually on-topic for him to talk about the reasons he prefers his new digs over the old. The fact he’s a little flippant about it doesn’t constitute a dire insult to your manhood, or whatever it is that bothers you about the fact someone has a different preference and is willing to laugh about it.

    As for MAPI . . . that only matters if you actually care about Exchange. Furthermore, Outlook is not unique in its MAPI support; there are other tools that support it as well.

  5. Actually, there isn't much need to "get up in arms" about my comment, either. What I said is that it didn't serve a purpose – the article could simply have given all the praise for the utilities and tools in questions, without having to take potshots at a program used by millions of people every day. A great tool should be able to stand on its own, and not have something else dragged down to prove its superiority. A great hitter is not measured by the ineptitude of the pitcher facing him; a great racer is not deemed so if he runs in a field of sub-par atheletes, even the kindergarten spelling bee champ isn't given their trophy because none of the other kids could spell – they still have to do something well themselves. Why should the comparison of programs, utilities, and even operating systems be any different?

    In other words, if you can't convince the general population that your software and utilities are great on their own merits, then what are you really trying to prove? It's getting a little old, in the "geek" community, that everywhere I turn, there's someone else willing to tear down Microsoft and their products, to prove how "smart" and "outside the box" they are. Ho-hum.

    Assuming that I am unaware of the vast majority of *nix based tools is a poor decision you've made there. I am aware of many alternatives to common tools, and I employ them where they are useful. But do you truly mean to tell me that you fully believe there are more utilities for any given task in existence written for the *nix side of the world, than the Windows side?

    And I also note that you seem to think I have something against Sterling – I do enjoy his writing, and have learned a thing or two from his posts. What I was saying, and still am, is that I believe the space he devoted to telling the world that Outlook is a "pig" could have been far better employed spelling out the virtues of Mutt.

    As for feeling insult to my manhood…I'll note that I put my name right there at the top of my post, "apotheon". So go ahead and tell all your friends how you told that "Windows loser" what's what, while you sign with a fairly anonymous screenname.

    • It's called "humor", though based on your reaction perhaps I missed the mark. Didn't you notice that I also took a jab at those who preach that *nix will conquer the desktop?

      As far as apotheon's screen name, he makes no secret of his given name: Chad Perrin.

  6. Actually, there isn’t much need to “get up in arms” about my comment, either. What I said is that it didn’t serve a purpose – the article could simply have given all the praise for the utilities and tools in questions, without having to take potshots at a program used by millions of people every day. A great tool should be able to stand on its own, and not have something else dragged down to prove its superiority. A great hitter is not measured by the ineptitude of the pitcher facing him; a great racer is not deemed so if he runs in a field of sub-par atheletes, even the kindergarten spelling bee champ isn’t given their trophy because none of the other kids could spell – they still have to do something well themselves. Why should the comparison of programs, utilities, and even operating systems be any different?

    In other words, if you can’t convince the general population that your software and utilities are great on their own merits, then what are you really trying to prove? It’s getting a little old, in the “geek” community, that everywhere I turn, there’s someone else willing to tear down Microsoft and their products, to prove how “smart” and “outside the box” they are. Ho-hum.

    Assuming that I am unaware of the vast majority of *nix based tools is a poor decision you’ve made there. I am aware of many alternatives to common tools, and I employ them where they are useful. But do you truly mean to tell me that you fully believe there are more utilities for any given task in existence written for the *nix side of the world, than the Windows side?

    And I also note that you seem to think I have something against Sterling – I do enjoy his writing, and have learned a thing or two from his posts. What I was saying, and still am, is that I believe the space he devoted to telling the world that Outlook is a “pig” could have been far better employed spelling out the virtues of Mutt.

    As for feeling insult to my manhood…I’ll note that I put my name right there at the top of my post, “apotheon”. So go ahead and tell all your friends how you told that “Windows loser” what’s what, while you sign with a fairly anonymous screenname.

    • It's called "humor", though based on your reaction perhaps I missed the mark. Didn't you notice that I also took a jab at those who preach that *nix will conquer the desktop?

      As far as apotheon's screen name, he makes no secret of his given name: Chad Perrin.

  7. so unless you plan on rolling this out to a bunch of workstations (which you clearly never said you did), I'd think this is pretty much pointless. Just use thunderbird.

    About using outlook because it has mapi… easy.. don't use a windows exchange server and switch over to kerio mail server, get the outlook connector and enjoy all of your front end window enjoyments with a nice solid/stable back end.

    Enjoy.

  8. so unless you plan on rolling this out to a bunch of workstations (which you clearly never said you did), I’d think this is pretty much pointless. Just use thunderbird.

    About using outlook because it has mapi… easy.. don’t use a windows exchange server and switch over to kerio mail server, get the outlook connector and enjoy all of your front end window enjoyments with a nice solid/stable back end.

    Enjoy.