I'm building a website and one of the requirements is for users to export their contacts from their email client to import them into the site.
Because each email client exports their contacts in a slightly different format this has got my head scratching has to the best way to approach it. As I don't know what the fields are, or what the delimiter is.
I'm only looking to target the main email client/address books (outlook, apple mail, entourage, thunderbird). All of these have an entirely different format. Entourage uses tab as a delimiter where as the rest use a comma etc. I only need to pluck out the email address and (if available) a name. The name gets trickier as some clients have separate fields for first name / last name.
Using FileHelpers would be ideal, but it seems I need to know the structure of the csv before I can hook up a solution. I'd rather not go writing my own csv parser if possible.
Here's my thoughts for the collective hive mind:
Plan A
- Read the first line of the csv file (all of the formats have a heading as the first row) and count the number of tabs vs commas. Determine from this the delimiter.
- Use some type of csv reader such as Lumenworks to give me basic csv reading capabilities for the rest of the file.
- Perform a Regex match on each field to determine the email column.
- No idea on how to figure out the name of the user...
Plan B
- Prompt user for type of email client, and individually code it up for each different client <- seems really clunky.
Plan C
....Use / purchase an existing component that already does this?! (I sure can't find one!!)
Thoughts?