LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-08-2010, 02:05 AM   #1
tushs
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Rep: Reputation: 1
How to: Importing outlook's Global address list contacts to evolution


I found simple solution for importing GAL to evolution, It may be helpful for others too so I am posting steps,
1. In Xp open MS-Access create blank database.
2. From File->Get External Data->Import, Select file type as exchange()
3. Import contacts to new table, u can delete unwanted columns from this table. Now export this table to a csv file.
4. Following is simple code which takes contacts.csv as input and convert these contacts to vcf file which can be imported to evolution.
5. The contact.csv should be of format
FirstName,LastName,emailID

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <uuid/uuid.h>

#define MAX_NO_OF_TOK 10

static char token[MAX_NO_OF_TOK][256] = {0};

void fnRemoveNl(char *buffer)
{
int
n = strlen(buffer);
for(; n >= 0; n--)
{
if(buffer[n] == '\r' || (buffer[n] == '\n'))
buffer[n] = 0;
}
}

int fnReadToken(FILE *fp)
{
char buffer[1024] = {0};
int n = 0;
char *ptr = NULL;
int index = 0;

if(NULL == fgets(buffer, sizeof(buffer), fp))
return 0;

memset(token,0,sizeof(token));

fnRemoveNl(buffer);

ptr = buffer;

while(1)
{
n = sscanf(ptr,"%[^, ]s",token[index]);
if(n <= 0)
break;
n = strlen(token[index]);
//printf("index %d : [%s]\n",index,token[index]);
index++;
if(n)
ptr += n + 1;
else
break;
if(index >= MAX_NO_OF_TOK)
break;
}
return index;
}

int fnValidateEmailId(char *email)
{
int index = 0;
int n = strlen(email);
int flag = 0;

for(index = 0; index < n; index++)
{
if(email[index] == '.')
flag = 1;
if(email[index] == '@')
break;
}
if(!flag)
{
printf("Mail ID [%s] might be invalid, skipping\n",email);
return -1;
}
return 0;
}

int fnWriteVcfContact(FILE *fp)
{
unsigned char uuid[100] = {0};
unsigned char buffer[1024] = {0};
int n = 0;
FILE *lsofFile_p = popen("uuidgen", "r");
fgets(uuid, sizeof(uuid), lsofFile_p);
pclose(lsofFile_p);

fnRemoveNl(uuid);

sprintf(buffer,"BEGIN:VCARD\nVERSION:3.0\nUIDas-id-%s\nEMAIL;TYPE=OTHER:%s\nX-EVOLUTION-FILE-AS:%s\\, %s\nN:%s;%s;;;\nFN:%s %s\nEND:VCARD\n\n",uuid,token[2],token[1],token[0],token[1],token[0],token[0],token[1]);
n = fprintf(fp,"BEGIN:VCARD\nVERSION:3.0\nUIDas-id-%s\nEMAIL;TYPE=OTHER:%s\nX-EVOLUTION-FILE-AS:%s\\, %s\nN:%s;%s;;;\nFN:%s %s\nEND:VCARD\n\n",uuid,token[2],token[1],token[0],token[1],token[0],token[0],token[1]);

//printf("n =[%d] [%s]\n",n,buffer);
if(n < 0)
{
printf("Output file write error [%s]\n",strerror(errno));
return -1;
}
return 0;
}

int main(int argc, char *argv[])
{
FILE *fp_read = NULL;
FILE *fp_write = NULL;
int n = 0;

if(argc != 3)
{
printf("%s input_contact_file output.vcf\n");
return -1;
}

fp_read = fopen(argv[1],"r");
if(fp_read == NULL)
{
printf("File open failed [%s]\n",strerror(errno));
return -1;
}

fp_write = fopen(argv[2],"w");
if(fp_write == NULL)
{
fclose(fp_read);
printf("File open failed [%s]\n",strerror(errno));
return -1;
}
while(1)
{
n = fnReadToken(fp_read);
if(n == 0)
break;
if(n != 3)
{
printf("contact of mail ID [%s] is in invalid format skipping it\n",token[0]);
continue;
}
fnValidateEmailId(token[2]);
if(0 != fnWriteVcfContact(fp_write))
break;
//break;
}
fclose(fp_read);
fclose(fp_write);
return 0;
}

6. Please note that uuidgen should be present on your linux box. you can have other validations and field too as per your need. but these three fields worked best for m
7. ./a.out contact.csv output.vcf
Now in evolution go to Contacts->File Import->Import single file, select output.vcf and File type as vcf.
8. Done!!!


Tushar

Last edited by pixellany; 04-10-2010 at 09:36 AM. Reason: edited title with "How to"
 
Old 05-04-2010, 07:27 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
Thank you for sharing your solution
 
  


Reply

Tags
contacts, evolution, global, list


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global address list Help!!! cklis Linux - Server 1 08-30-2007 12:05 PM
Global Address List (Exchange Server 2003) gravitek Linux - Software 2 01-13-2007 07:05 AM
Importing MS Outlook Contacts into Evolution Gomi Linux - Newbie 3 01-05-2005 03:13 AM
Importing Outlook contacts into Evolution linuxpyro Linux - Software 3 05-26-2004 10:18 PM
importing evolution contacts rvqbl Linux - Software 0 04-16-2004 05:24 AM


All times are GMT -5. The time now is 10:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration