fixed address book
[claws.git] / src / vcard.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001 Match Grun
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Functions necessary to access VCard files. VCard files are used
22  * by GnomeCard for addressbook, and Netscape for sending business
23  * card information. Refer to RFC2426 for more information.
24  */
25
26 #include <sys/stat.h>
27 #include <glib.h>
28
29 #include "mgutils.h"
30 #include "vcard.h"
31
32 #define GNOMECARD_DIR     ".gnome"
33 #define GNOMECARD_FILE    "GnomeCard"
34 #define GNOMECARD_SECTION "[file]"
35 #define GNOMECARD_PARAM   "open"
36
37 #define VCARD_TEST_LINES  200
38
39 /*
40 * Specify name to be used.
41 */
42 void vcard_set_name( VCardFile* cardFile, const gchar *name ) {
43         /* Copy file name */
44         if( cardFile->name ) g_free( cardFile->name );
45         if( name ) cardFile->name = g_strdup( name );
46         g_strstrip( cardFile->name );
47 }
48
49 /*
50 * Specify file to be used.
51 */
52 void vcard_set_file( VCardFile* cardFile, const gchar *path ) {
53         mgu_refresh_cache( cardFile->addressCache );
54
55         /* Copy file path */
56         if( cardFile->path ) g_free( cardFile->path );
57         if( path ) cardFile->path = g_strdup( path );
58         g_strstrip( cardFile->path );
59 }
60
61 /*
62 * Create new cardfile object.
63 */
64 VCardFile *vcard_create() {
65         VCardFile *cardFile;
66         cardFile = g_new( VCardFile, 1 );
67         cardFile->name = NULL;
68         cardFile->path = NULL;
69         cardFile->file = NULL;
70         cardFile->bufptr = cardFile->buffer;
71         cardFile->addressCache = mgu_create_cache();
72         cardFile->retVal = MGU_SUCCESS;
73         return cardFile;
74 }
75
76 /*
77 * Refresh internal variables to force a file read.
78 */
79 void vcard_force_refresh( VCardFile *cardFile ) {
80         mgu_refresh_cache( cardFile->addressCache );
81 }
82
83 /*
84 * Create new cardfile object for specified file.
85 */
86 VCardFile *vcard_create_path( const gchar *path ) {
87         VCardFile *cardFile;
88         cardFile = vcard_create();
89         vcard_set_file(cardFile, path );
90         return cardFile;
91 }
92
93 /*
94 * Free up cardfile object by releasing internal memory.
95 */
96 void vcard_free( VCardFile *cardFile ) {
97         g_return_if_fail( cardFile != NULL );
98
99         // fprintf( stdout, "freeing... VCardFile\n" );
100
101         /* Close file */
102         if( cardFile->file ) fclose( cardFile->file );
103
104         /* Free internal stuff */
105         g_free( cardFile->name );
106         g_free( cardFile->path );
107
108         /* Clear cache */
109         mgu_clear_cache( cardFile->addressCache );
110         mgu_free_cache( cardFile->addressCache );
111
112         // Clear pointers
113         cardFile->file = NULL;
114         cardFile->name = NULL;
115         cardFile->path = NULL;
116         cardFile->addressCache = NULL;
117         cardFile->retVal = MGU_SUCCESS;
118
119         /* Now release file object */
120         g_free( cardFile );
121
122         // fprintf( stdout, "freeing... VCardFile done\n" );
123
124 }
125
126 /*
127 * Display object to specified stream.
128 */
129 void vcard_print_file( VCardFile *cardFile, FILE *stream ) {
130         GSList *node;
131         g_return_if_fail( cardFile != NULL );
132         fprintf( stream, "VCardFile:\n" );
133         fprintf( stream, "     name: '%s'\n", cardFile->name );
134         fprintf( stream, "file spec: '%s'\n", cardFile->path );
135         fprintf( stream, "  ret val: %d\n",   cardFile->retVal );
136         mgu_print_cache( cardFile->addressCache, stream );
137 }
138
139 /*
140 * Open file for read.
141 * return: TRUE if file opened successfully.
142 */
143 gint vcard_open_file( VCardFile* cardFile ) {
144         g_return_if_fail( cardFile != NULL );
145
146         // fprintf( stdout, "Opening file\n" );
147         cardFile->addressCache->dataRead = FALSE;
148         if( cardFile->path ) {
149                 cardFile->file = fopen( cardFile->path, "r" );
150                 if( ! cardFile->file ) {
151                         // fprintf( stderr, "can't open %s\n", cardFile->path );
152                         cardFile->retVal = MGU_OPEN_FILE;
153                         return cardFile->retVal;
154                 }
155         }
156         else {
157                 // fprintf( stderr, "file not specified\n" );
158                 cardFile->retVal = MGU_NO_FILE;
159                 return cardFile->retVal;
160         }
161
162         /* Setup a buffer area */
163         cardFile->buffer[0] = '\0';
164         cardFile->bufptr = cardFile->buffer;
165         cardFile->retVal = MGU_SUCCESS;
166         return cardFile->retVal;
167 }
168
169 /*
170 * Close file.
171 */
172 void vcard_close_file( VCardFile *cardFile ) {
173         g_return_if_fail( cardFile != NULL );
174         if( cardFile->file ) fclose( cardFile->file );
175         cardFile->file = NULL;
176 }
177
178 /*
179 * Read line of text from file.
180 * Return: ptr to buffer where line starts.
181 */
182 gchar *vcard_read_line( VCardFile *cardFile ) {
183         while( *cardFile->bufptr == '\n' || *cardFile->bufptr == '\0' ) {
184                 if( fgets( cardFile->buffer, VCARDBUFSIZE, cardFile->file ) == NULL )
185                         return NULL;
186                 g_strstrip( cardFile->buffer );
187                 cardFile->bufptr = cardFile->buffer;
188         }
189         return cardFile->bufptr;
190 }
191
192 /*
193 * Read line of text from file.
194 * Return: ptr to buffer where line starts.
195 */
196 gchar *vcard_get_line( VCardFile *cardFile ) {
197         gchar buf[ VCARDBUFSIZE ];
198         gchar *start, *end;
199         gint len;
200
201         if (vcard_read_line( cardFile ) == NULL ) {
202                 buf[0] = '\0';
203                 return;
204         }
205
206         /* Copy into private buffer */
207         start = cardFile->bufptr;
208         len = strlen( start );
209         end = start + len;
210         strncpy( buf, start, len );
211         buf[ len ] = '\0';
212         g_strstrip(buf);
213         cardFile->bufptr = end + 1;
214
215         /* Return a copy of buffer */   
216         return g_strdup( buf );
217 }
218
219 /*
220 * Free linked lists of character strings.
221 */
222 void vcard_free_lists( GSList *listName, GSList *listAddr, GSList *listRem, GSList* listID ) {
223         mgu_free_list( listName );
224         mgu_free_list( listAddr );
225         mgu_free_list( listRem );
226         mgu_free_list( listID );
227 }
228
229 /*
230 * Read quoted-printable text, which may span several lines into one long string.
231 * Param: cardFile - object.
232 * Param: tagvalue - will be placed into the linked list.
233 */
234 gchar *vcard_read_qp( VCardFile *cardFile, char *tagvalue ) {
235         GSList *listQP = NULL;
236         gint len = 0;
237         gchar *line = tagvalue;
238         while( line ) {
239                 listQP = g_slist_append( listQP, line );
240                 len = strlen( line ) - 1;
241                 if( len > 0 ) {
242                         if( line[ len ] != '=' ) break;
243                         line[ len ] = '\0';
244                 }
245                 line = vcard_get_line( cardFile );
246         }
247
248         // Coalesce linked list into one long buffer.
249         line = mgu_list_coalesce( listQP );
250
251         // Clean up
252         mgu_free_list( listQP );
253         listQP = NULL;
254         return line;
255 }
256
257 /*
258 * Parse tag name from line buffer.
259 * Return: Buffer containing the tag name, or NULL if no delimiter char found.
260 */
261 gchar *vcard_get_tagname( char* line, gchar dlm ) {
262         gint len = 0;
263         gchar *tag = NULL;
264         gchar *lptr = line;
265         while( *lptr++ ) {
266                 if( *lptr == dlm ) {
267                         len = lptr - line;
268                         tag = g_strndup( line, len+1 );
269                         tag[ len ] = '\0';
270                         g_strdown( tag );
271                         return tag;
272                 }
273         }
274         return tag;
275 }
276
277 /*
278 * Parse tag value from line buffer.
279 * Return: Buffer containing the tag value. Empty string is returned if
280 * no delimiter char found.
281 */
282 gchar *vcard_get_tagvalue( gchar* line, gchar dlm ) {
283         gchar *value = NULL;
284         gchar *start = NULL;
285         gchar *lptr;
286         gint len = 0;
287
288         for( lptr = line; *lptr; lptr++ ) {
289                 if( *lptr == dlm ) {
290                         if( ! start )
291                                 start = lptr + 1;
292                 }
293         }
294         if( start ) {
295                 len = lptr - start;
296                 value = g_strndup( start, len+1 );
297         }
298         else {
299                 // Ensure that we get an empty string
300                 value = g_strndup( "", 1 );
301         }
302         value[ len ] = '\0';
303         return value;
304 }
305
306 /*
307 * Dump linked lists of character strings (for debug).
308 */
309 void vcard_dump_lists( GSList *listName, GSList *listAddr, GSList *listRem, GSList *listID, FILE *stream ) {
310         fprintf( stream, "dump name\n" );
311         fprintf( stream, "------------\n" );
312         mgu_print_list( listName, stdout );
313         fprintf( stream, "dump address\n" );
314         fprintf( stream, "------------\n" );
315         mgu_print_list( listAddr, stdout );
316         fprintf( stream, "dump remarks\n" );
317         fprintf( stdout, "------------\n" );
318         mgu_print_list( listRem, stdout );
319         fprintf( stream, "dump id\n" );
320         fprintf( stdout, "------------\n" );
321         mgu_print_list( listID, stdout );
322 }
323
324 /*
325 * Build an address list entry and append to list of address items.
326 */
327 void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *listAddr, GSList *listRem, GSList *listID ) {
328         AddressItem *addrItem = NULL;
329         GSList *nodeName = listName;
330         GSList *nodeID = listID;
331         while( nodeName ) {
332                 GSList *nodeAddress = listAddr;
333                 GSList *nodeRemarks = listRem;
334                 while( nodeAddress ) {
335                         addrItem = mgu_create_address();
336                         addrItem->name = g_strdup( nodeName->data );
337                         addrItem->address = g_strdup( nodeAddress->data );
338                         if( nodeRemarks ) {
339                                 if( nodeRemarks->data ) {
340                                         if( g_strcasecmp( nodeRemarks->data, "internet" ) == 0 ) {
341                                                 // Trivially exclude this one (appears for most records)
342                                                 addrItem->remarks = g_strdup( "" );
343                                         }
344                                         else {
345                                                 addrItem->remarks = g_strdup( nodeRemarks->data );
346                                         }
347                                 }
348                                 else {
349                                         addrItem->remarks = g_strdup( "" );
350                                 }
351                         }
352                         else {
353                                         addrItem->remarks = g_strdup( "" );
354                         }
355 /*
356                         if( nodeID ) {
357                                 if( nodeID->data ) {
358                                         addrItem->externalID = g_strdup( nodeID->data );
359                                 }
360                                 else {
361                                         addrItem->externalID = g_strdup( "" );
362                                 }
363                         }
364                         else {
365                                 addrItem->externalID = g_strdup( "" );
366                         }
367 */
368                         mgu_add_cache( cardFile->addressCache, addrItem );
369
370                         nodeAddress = g_slist_next( nodeAddress );
371                         nodeRemarks = g_slist_next( nodeRemarks );
372                 }
373                 nodeName = g_slist_next( nodeName );
374                 nodeID = g_slist_next( nodeID );
375         }
376         addrItem = NULL;
377 }
378
379 // Unescape characters in quoted-printable string.
380 void vcard_unescape_qp( gchar *value ) {
381         gchar *ptr, *src, *dest;
382         int d, v;
383         char ch;
384         gboolean gotch;
385         ptr = value;
386         while( *ptr ) {
387                 gotch = FALSE;
388                 if( *ptr == '=' ) {
389                         v = 0;
390                         ch = *(ptr + 1);
391                         if( ch ) {
392                                 if( ch > '0' && ch < '8' ) v = ch - '0';
393                         }
394                         d = -1;
395                         ch = *(ptr + 2);
396                         if( ch ) {
397                                 if( ch > '\x60' ) ch -= '\x20';
398                                 if( ch > '0' && ch < ' ' ) d = ch - '0';
399                                 d = ch - '0';
400                                 if( d > 9 ) d -= 7;
401                                 if( d > -1 && d < 16 ) {
402                                         v = ( 16 * v ) + d;
403                                         gotch = TRUE;
404                                 }
405                         }
406                 }
407                 if( gotch ) {
408                         // Replace = with char and move down in buffer
409                         *ptr = v;
410                         src = ptr + 3;
411                         dest = ptr + 1;
412                         while( *src ) {
413                                 *dest++ = *src++;
414                         }
415                         *dest = '\0';
416                 }
417                 ptr++;
418         }
419 }
420
421 /*
422 * Read file into cache.
423 * Note that one VCard can have multiple E-Mail addresses (MAIL tags);
424 * these are broken out into separate address items. An address item
425 * is generated for the person identified by FN tag and each EMAIL tag.
426 * If a sub-type is included in the EMAIL entry, this will be used as
427 * the Remarks member. Also note that it is possible for one VCard
428 * entry to have multiple FN tags; this might not make sense. However,
429 * it will generate duplicate address entries for each person listed.
430 */
431 void vcard_read_cache( VCardFile *cardFile ) {
432         gchar *tagtemp = NULL, *tagname = NULL, *tagvalue = NULL, *tagtype = NULL, *tagrest = NULL;
433         GSList *listName = NULL, *listAddress = NULL, *listRemarks = NULL, *listID = NULL;
434         GSList *listQP = NULL;
435
436         for( ;; ) {
437                 gchar *line =  vcard_get_line( cardFile );
438                 if( line == NULL ) break;
439
440                 // fprintf( stdout, "%s\n", line );
441
442                 /* Parse line */
443                 tagtemp = vcard_get_tagname( line, VCARD_SEP_TAG );
444                 if( tagtemp ) {
445                         // fprintf( stdout, "\ttemp:  %s\n", tagtemp );
446                         tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
447                         tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
448                         tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
449                         if( tagname == NULL ) {
450                                 tagname = tagtemp;
451                                 tagtemp = NULL;
452                         }
453
454                         // fprintf( stdout, "\tname:  %s\n", tagname );
455                         // fprintf( stdout, "\ttype:  %s\n", tagtype );
456                         // fprintf( stdout, "\tvalue: %s\n", tagvalue );
457
458                         if( tagvalue ) {
459                                 if( g_strcasecmp( tagtype, VCARD_TYPE_QP ) == 0 ) {
460                                         // Quoted-Printable: could span multiple lines
461                                         tagvalue = vcard_read_qp( cardFile, tagvalue );
462                                         vcard_unescape_qp( tagvalue );
463                                         // fprintf( stdout, "QUOTED-PRINTABLE !!! final\n>%s<\n", tagvalue );
464                                 }
465
466                                 if( g_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&  g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
467                                         // fprintf( stdout, "start card\n" );
468                                         vcard_free_lists( listName, listAddress, listRemarks, listID );
469                                         listName = listAddress = listRemarks = listID = NULL;
470                                 }
471                                 if( g_strcasecmp( tagname, VCARD_TAG_FULLNAME ) == 0 ) {
472                                         // fprintf( stdout, "- full name: %s\n", tagvalue );
473                                         listName = g_slist_append( listName, g_strdup( tagvalue ) );
474                                 }
475                                 if( g_strcasecmp( tagname, VCARD_TAG_EMAIL ) == 0 ) {
476                                         // fprintf( stdout, "- address: %s\n", tagvalue );
477                                         listAddress = g_slist_append( listAddress, g_strdup( tagvalue ) );
478                                         listRemarks = g_slist_append( listRemarks, g_strdup( tagtype ) );
479                                 }
480                                 if( g_strcasecmp( tagname, VCARD_TAG_UID ) == 0 ) {
481                                         // fprintf( stdout, "- id: %s\n", tagvalue );
482                                         listID = g_slist_append( listID, g_strdup( tagvalue ) );
483                                 }
484                                 if( g_strcasecmp( tagname, VCARD_TAG_END ) == 0 && g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
485                                         // VCard is complete
486                                         // fprintf( stdout, "end card\n--\n" );
487                                         // vcard_dump_lists( listName, listAddress, listRemarks, listID, stdout );
488                                         vcard_build_items( cardFile, listName, listAddress, listRemarks, listID );
489                                         vcard_free_lists( listName, listAddress, listRemarks, listID );
490                                         listName = listAddress = listRemarks = listID = NULL;
491                                 }
492                                 g_free( tagvalue );
493                         }
494                         g_free( tagname );
495                         g_free( tagtype );
496                 }
497         }
498
499         // Free lists
500         vcard_free_lists( listName, listAddress, listRemarks, listID );
501         listName = listAddress = listRemarks = listID = NULL;
502 }
503
504 // ============================================================================================
505 /*
506 * Read file into list. Main entry point
507 * Return: TRUE if file read successfully.
508 */
509 // ============================================================================================
510 gint vcard_read_data( VCardFile *cardFile ) {
511         g_return_if_fail( cardFile != NULL );
512         cardFile->retVal = MGU_SUCCESS;
513         if( mgu_check_file( cardFile->addressCache, cardFile->path ) ) {
514                 mgu_clear_cache( cardFile->addressCache );
515                 vcard_open_file( cardFile );
516                 if( cardFile->retVal == MGU_SUCCESS ) {
517                         // Read data into the list
518                         vcard_read_cache( cardFile );
519                         vcard_close_file( cardFile );
520
521                         // Mark cache
522                         mgu_mark_cache( cardFile->addressCache, cardFile->path );
523                         cardFile->addressCache->modified = FALSE;
524                         cardFile->addressCache->dataRead = TRUE;
525                 }
526         }
527         return cardFile->retVal;
528 }
529
530 /*
531 * Return link list of address items.
532 * Return: TRUE if file read successfully.
533 */
534 GList *vcard_get_address_list( VCardFile *cardFile ) {
535         g_return_if_fail( cardFile != NULL );
536         return cardFile->addressCache->addressList;
537 }
538
539 /*
540 * Validate that all parameters specified.
541 * Return: TRUE if data is good.
542 */
543 gboolean vcard_validate( const VCardFile *cardFile ) {
544         gboolean retVal;
545         g_return_if_fail( cardFile != NULL );
546
547         retVal = TRUE;
548         if( cardFile->path ) {
549                 if( strlen( cardFile->path ) < 1 ) retVal = FALSE;
550         }
551         else {
552                 retVal = FALSE;
553         }
554         if( cardFile->name ) {
555                 if( strlen( cardFile->name ) < 1 ) retVal = FALSE;
556         }
557         else {
558                 retVal = FALSE;
559         }
560         return retVal;
561 }
562
563 #define WORK_BUFLEN 1024
564
565 /*
566 * Attempt to find a valid GnomeCard file.
567 * Return: Filename, or home directory if not found. Filename should
568 *       be g_free() when done.
569 */
570 gchar *vcard_find_gnomecard( void ) {
571         gchar *homedir;
572         gchar buf[ WORK_BUFLEN ];
573         gchar str[ WORK_BUFLEN ];
574         gchar *fileSpec;
575         gint len, lenlbl, i;
576         FILE *fp;
577
578         homedir = g_get_home_dir();
579         if( ! homedir ) return NULL;
580
581         strcpy( str, homedir );
582         len = strlen( str );
583         if( len > 0 ) {
584                 if( str[ len-1 ] != G_DIR_SEPARATOR ) {
585                         str[ len ] = G_DIR_SEPARATOR;
586                         str[ ++len ] = '\0';
587                 }
588         }
589         strcat( str, GNOMECARD_DIR );
590         strcat( str, G_DIR_SEPARATOR_S );
591         strcat( str, GNOMECARD_FILE );
592
593         fileSpec = NULL;
594         if( ( fp = fopen( str, "r" ) ) != NULL ) {
595                 // Read configuration file
596                 lenlbl = strlen( GNOMECARD_SECTION );
597                 while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
598                         if( 0 == g_strncasecmp( buf, GNOMECARD_SECTION, lenlbl ) ) {
599                                 break;
600                         }
601                 }
602
603                 while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
604                         g_strchomp( buf );
605                         if( buf[0] == '[' ) break;
606                         for( i = 0; i < lenlbl; i++ ) {
607                                 if( buf[i] == '=' ) {
608                                         if( 0 == g_strncasecmp( buf, GNOMECARD_PARAM, i ) ) {
609                                                 fileSpec = g_strdup( buf + i + 1 );
610                                                 g_strstrip( fileSpec );
611                                         }
612                                 }
613                         }
614                 }
615                 fclose( fp );
616         }
617
618         if( fileSpec == NULL ) {
619                 // Use the home directory
620                 str[ len ] = '\0';
621                 fileSpec = g_strdup( str );
622         }
623
624         return fileSpec;
625 }
626
627 /*
628 * Attempt to read file, testing for valid VCard format.
629 * Return: TRUE if file appears to be valid format.
630 */
631 gint vcard_test_read_file( const gchar *fileSpec ) {
632         gboolean haveStart;
633         gchar *tagtemp = NULL, *tagname = NULL, *tagvalue = NULL, *tagtype = NULL, *tagrest = NULL, *line;
634         VCardFile *cardFile;
635         gint retVal, lines;
636
637         if( ! fileSpec ) return MGU_NO_FILE;
638
639         cardFile = vcard_create_path( fileSpec );
640         cardFile->retVal = MGU_SUCCESS;
641         vcard_open_file( cardFile );
642         if( cardFile->retVal == MGU_SUCCESS ) {
643                 cardFile->retVal = MGU_BAD_FORMAT;
644                 haveStart = FALSE;
645                 lines = VCARD_TEST_LINES;
646                 while( lines > 0 ) {
647                         lines--;
648                         if( ( line =  vcard_get_line( cardFile ) ) == NULL ) break;
649
650                         /* Parse line */
651                         tagtemp = vcard_get_tagname( line, VCARD_SEP_TAG );
652                         if( tagtemp ) {
653                                 tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
654                                 tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
655                                 tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
656                                 if( tagname == NULL ) {
657                                         tagname = tagtemp;
658                                         tagtemp = NULL;
659                                 }
660
661                                 if( tagvalue ) {
662                                         if( g_strcasecmp( tagtype, VCARD_TYPE_QP ) == 0 ) {
663                                                 // Quoted-Printable: could span multiple lines
664                                                 tagvalue = vcard_read_qp( cardFile, tagvalue );
665                                                 vcard_unescape_qp( tagvalue );
666                                         }
667
668                                         if( g_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&  g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
669                                                 haveStart = TRUE;
670                                         }
671                                         if( g_strcasecmp( tagname, VCARD_TAG_END ) == 0 && g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
672                                                 // VCard is complete
673                                                 if( haveStart ) cardFile->retVal = MGU_SUCCESS;
674                                         }
675                                         g_free( tagvalue );
676                                 }
677                                 g_free( tagname );
678                                 g_free( tagtype );
679                         }
680                 }
681                 vcard_close_file( cardFile );
682         }
683         retVal = cardFile->retVal;
684         vcard_free( cardFile );
685         cardFile = NULL;
686         return retVal;
687 }
688
689 /*
690 * End of Source.
691 */