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\nUID
as-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\nUID
as-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