2007-12-07 [colin] 3.1.0cvs66
[claws.git] / src / vcard.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2007 Match Grun and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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 <glib.h>
27 #include <sys/stat.h>
28 #include <string.h>
29
30 #include "mgutils.h"
31 #include "vcard.h"
32 #include "addritem.h"
33 #include "addrcache.h"
34 #include "adbookbase.h"
35 #include "utils.h"
36
37 #define GNOMECARD_DIR     ".gnome"
38 #define GNOMECARD_FILE    "GnomeCard"
39 #define GNOMECARD_SECTION "[file]"
40 #define GNOMECARD_PARAM   "open"
41
42 #define VCARD_TEST_LINES  200
43
44 /*
45 * Create new cardfile object.
46 */
47 VCardFile *vcard_create() {
48         VCardFile *cardFile;
49         cardFile = g_new0( VCardFile, 1 );
50         cardFile->type = ADBOOKTYPE_VCARD;
51         cardFile->addressCache = addrcache_create();
52         cardFile->retVal = MGU_SUCCESS;
53
54         cardFile->file = NULL;
55         cardFile->path = NULL;
56         cardFile->bufptr = cardFile->buffer;
57         return cardFile;
58 }
59
60 /*
61 * Properties...
62 */
63 void vcard_set_name( VCardFile* cardFile, const gchar *value ) {
64         g_return_if_fail( cardFile != NULL );
65         addrcache_set_name( cardFile->addressCache, value );
66 }
67 void vcard_set_file( VCardFile* cardFile, const gchar *value ) {
68         g_return_if_fail( cardFile != NULL );
69         addrcache_refresh( cardFile->addressCache );
70         cardFile->path = mgu_replace_string( cardFile->path, value );
71         g_strstrip( cardFile->path );
72 }
73 void vcard_set_accessed( VCardFile *cardFile, const gboolean value ) {
74         g_return_if_fail( cardFile != NULL );
75         cardFile->addressCache->accessFlag = value;
76 }
77
78 /*
79 * Test whether file was modified since last access.
80 * Return: TRUE if file was modified.
81 */
82 gboolean vcard_get_modified( VCardFile *cardFile ) {
83         g_return_val_if_fail( cardFile != NULL, FALSE );
84         cardFile->addressCache->modified =
85                 addrcache_check_file( cardFile->addressCache, cardFile->path );
86         return cardFile->addressCache->modified;
87 }
88 gboolean vcard_get_accessed( VCardFile *cardFile ) {
89         g_return_val_if_fail( cardFile != NULL, FALSE );
90         return cardFile->addressCache->accessFlag;
91 }
92
93 /*
94 * Test whether file was read.
95 * Return: TRUE if file was read.
96 */
97 gboolean vcard_get_read_flag( VCardFile *cardFile ) {
98         g_return_val_if_fail( cardFile != NULL, FALSE );
99         return cardFile->addressCache->dataRead;
100 }
101
102 /*
103 * Return status code from last file operation.
104 * Return: Status code.
105 */
106 gint vcard_get_status( VCardFile *cardFile ) {
107         g_return_val_if_fail( cardFile != NULL, -1 );
108         return cardFile->retVal;
109 }
110
111 ItemFolder *vcard_get_root_folder( VCardFile *cardFile ) {
112         g_return_val_if_fail( cardFile != NULL, NULL );
113         return addrcache_get_root_folder( cardFile->addressCache );
114 }
115 gchar *vcard_get_name( VCardFile *cardFile ) {
116         g_return_val_if_fail( cardFile != NULL, NULL );
117         return addrcache_get_name( cardFile->addressCache );
118 }
119
120 /*
121 * Create new cardfile object for specified file.
122 */
123 static VCardFile *vcard_create_path( const gchar *path ) {
124         VCardFile *cardFile;
125         cardFile = vcard_create();
126         vcard_set_file(cardFile, path);
127         return cardFile;
128 }
129
130 /*
131 * Free up cardfile object by releasing internal memory.
132 */
133 void vcard_free( VCardFile *cardFile ) {
134         g_return_if_fail( cardFile != NULL );
135
136         /* Close file */
137         if( cardFile->file ) fclose( cardFile->file );
138
139         /* Clear cache */
140         addrcache_clear( cardFile->addressCache );
141         addrcache_free( cardFile->addressCache );
142
143         /* Free internal stuff */
144         g_free( cardFile->path );
145
146         /* Clear pointers */
147         cardFile->file = NULL;
148         cardFile->path = NULL;
149         cardFile->bufptr = NULL;
150
151         cardFile->type = ADBOOKTYPE_NONE;
152         cardFile->addressCache = NULL;
153         cardFile->retVal = MGU_SUCCESS;
154
155         /* Now release file object */
156         g_free( cardFile );
157 }
158
159 /*
160 * Open file for read.
161 * return: TRUE if file opened successfully.
162 */
163 static gint vcard_open_file( VCardFile* cardFile ) {
164         g_return_val_if_fail( cardFile != NULL, -1 );
165
166         /* g_print( "Opening file\n" ); */
167         cardFile->addressCache->dataRead = FALSE;
168         if( cardFile->path ) {
169                 cardFile->file = g_fopen( cardFile->path, "rb" );
170                 if( ! cardFile->file ) {
171                         /* g_printerr( "can't open %s\n", cardFile->path ); */
172                         cardFile->retVal = MGU_OPEN_FILE;
173                         return cardFile->retVal;
174                 }
175         }
176         else {
177                 /* g_printerr( "file not specified\n" ); */
178                 cardFile->retVal = MGU_NO_FILE;
179                 return cardFile->retVal;
180         }
181
182         /* Setup a buffer area */
183         cardFile->buffer[0] = '\0';
184         cardFile->bufptr = cardFile->buffer;
185         cardFile->retVal = MGU_SUCCESS;
186         return cardFile->retVal;
187 }
188
189 /*
190 * Close file.
191 */
192 static void vcard_close_file( VCardFile *cardFile ) {
193         g_return_if_fail( cardFile != NULL );
194         if( cardFile->file ) fclose( cardFile->file );
195         cardFile->file = NULL;
196 }
197
198 /*
199 * Read line of text from file.
200 * Return: ptr to buffer where line starts.
201 */
202 static gchar *vcard_read_line( VCardFile *cardFile ) {
203         while( *cardFile->bufptr == '\n' || *cardFile->bufptr == '\0' ) {
204                 if( fgets( cardFile->buffer, VCARDBUFSIZE, cardFile->file ) == NULL )
205                         return NULL;
206                 g_strstrip( cardFile->buffer );
207                 cardFile->bufptr = cardFile->buffer;
208         }
209         return cardFile->bufptr;
210 }
211
212 /*
213 * Read line of text from file.
214 * Return: ptr to buffer where line starts.
215 */
216 static gchar *vcard_get_line( VCardFile *cardFile ) {
217         gchar buf[ VCARDBUFSIZE ];
218         gchar *start, *end;
219         gint len;
220
221         if (vcard_read_line( cardFile ) == NULL ) {
222                 buf[0] = '\0';
223                 return NULL;
224         }
225
226         /* Copy into private buffer */
227         start = cardFile->bufptr;
228         len = strlen( start );
229         end = start + len;
230         strncpy( buf, start, len );
231         buf[ len ] = '\0';
232         g_strstrip(buf);
233         cardFile->bufptr = end + 1;
234
235         /* Return a copy of buffer */   
236         return g_strdup( buf );
237 }
238
239 /*
240 * Free linked lists of character strings.
241 */
242 static void vcard_free_lists( GSList *listName, GSList *listAddr, GSList *listRem, GSList* listID ) {
243         mgu_free_list( listName );
244         mgu_free_list( listAddr );
245         mgu_free_list( listRem );
246         mgu_free_list( listID );
247 }
248
249 /*
250 * Read quoted-printable text, which may span several lines into one long string.
251 * Param: cardFile - object.
252 * Param: tagvalue - will be placed into the linked list.
253 */
254 static gchar *vcard_read_qp( VCardFile *cardFile, char *tagvalue ) {
255         GSList *listQP = NULL;
256         gint len = 0;
257         gchar *line = tagvalue;
258         while( line ) {
259                 listQP = g_slist_append( listQP, line );
260                 len = strlen( line ) - 1;
261                 if( line[ len ] != '=' ) break;
262                 line[ len ] = '\0';
263                 line = vcard_get_line( cardFile );
264         }
265
266         /* Coalesce linked list into one long buffer. */
267         line = mgu_list_coalesce( listQP );
268
269         /* Clean up */
270         mgu_free_list( listQP );
271         listQP = NULL;
272         return line;
273 }
274
275 /*
276 * Parse tag name from line buffer.
277 * Return: Buffer containing the tag name, or NULL if no delimiter char found.
278 */
279 static gchar *vcard_get_tagname( char* line, gchar dlm ) {
280         gint len = 0;
281         gchar *tag = NULL;
282         gchar *lptr = line;
283
284         while( *lptr++ ) {
285                 if( *lptr == dlm ) {
286                         len = lptr - line;
287                         tag = g_strndup( line, len+1 );
288                         tag[ len ] = '\0';
289                         g_strdown( tag );
290                         return tag;
291                 }
292         }
293         return tag;
294 }
295
296 /*
297 * Parse tag value from line buffer.
298 * Return: Buffer containing the tag value. Empty string is returned if
299 * no delimiter char found.
300 */
301 static gchar *vcard_get_tagvalue( gchar* line, gchar dlm ) {
302         gchar *value = NULL;
303         gchar *start = NULL;
304         gchar *lptr;
305         gint len = 0;
306
307         for( lptr = line; *lptr; lptr++ ) {
308                 if( *lptr == dlm ) {
309                         if( ! start )
310                                 start = lptr + 1;
311                 }
312         }
313         if( start ) {
314                 len = lptr - start;
315                 value = g_strndup( start, len+1 );
316         }
317         else {
318                 /* Ensure that we get an empty string */
319                 value = g_strndup( "", 1 );
320         }
321         value[ len ] = '\0';
322         return value;
323 }
324
325 /*
326 * Build an address list entry and append to list of address items.
327 */
328 static void vcard_build_items(
329         VCardFile *cardFile, GSList *listName, GSList *listAddr,
330         GSList *listRem, GSList *listID )
331 {
332         GSList *nodeName = listName;
333         GSList *nodeID = listID;
334         gchar *str;
335         while( nodeName ) {
336                 GSList *nodeAddress = listAddr;
337                 GSList *nodeRemarks = listRem;
338                 ItemPerson *person = addritem_create_item_person();
339                 addritem_person_set_common_name( person, nodeName->data );
340                 while( nodeAddress ) {
341                         str = nodeAddress->data;
342                         if( *str != '\0' ) {
343                                 ItemEMail *email = addritem_create_item_email();
344                                 addritem_email_set_address( email, str );
345                                 str = nodeRemarks->data;
346                                 if( nodeRemarks ) {
347                                         if( str ) {
348                                                 if( g_utf8_collate( str, "internet" ) != 0 ) {
349                                                         if( *str != '\0' )
350                                                                 addritem_email_set_remarks( email, str );
351                                                 }
352                                         }
353                                 }
354                                 addrcache_id_email( cardFile->addressCache, email );
355                                 addrcache_person_add_email( cardFile->addressCache, person, email );
356                         }
357                         nodeAddress = g_slist_next( nodeAddress );
358                         nodeRemarks = g_slist_next( nodeRemarks );
359                 }
360                 if( person->listEMail ) {
361                         addrcache_id_person( cardFile->addressCache, person );
362                         addrcache_add_person( cardFile->addressCache, person );
363                         if( nodeID ) {
364                                 str = nodeID->data;
365                                 addritem_person_set_external_id( person, str );
366                         }
367                 }
368                 else {
369                         addritem_free_item_person( person );
370                 }
371                 nodeName = g_slist_next( nodeName );
372                 nodeID = g_slist_next( nodeID );
373         }
374 }
375
376 /* Unescape characters in quoted-printable string. */
377 static gchar *vcard_unescape_qp( gchar *value ) {
378         gchar *res = NULL;
379         gint len;
380         if (value == NULL)
381                 return NULL;
382                 
383         len = strlen(value);
384         res = g_malloc(len);
385         qp_decode_const(res, len-1, value);
386         if (!g_utf8_validate(res, -1, NULL)) {
387                 gchar *mybuf = g_malloc(strlen(res)*2 +1);
388                 conv_localetodisp(mybuf, strlen(res)*2 +1, res);
389                 g_free(res);
390                 res = mybuf;
391         }
392         return res;
393 }
394
395  /*
396 * Read file data into root folder.
397 * Note that one vCard can have multiple E-Mail addresses (MAIL tags);
398 * these are broken out into separate address items. An address item
399 * is generated for the person identified by FN tag and each EMAIL tag.
400 * If a sub-type is included in the EMAIL entry, this will be used as
401 * the Remarks member. Also note that it is possible for one vCard
402 * entry to have multiple FN tags; this might not make sense. However,
403 * it will generate duplicate address entries for each person listed.
404 */
405 static void vcard_read_file( VCardFile *cardFile ) {
406         gchar *tagtemp = NULL, *tagname = NULL, *tagvalue = NULL, *tagtype = NULL;
407         GSList *listName = NULL, *listAddress = NULL, *listRemarks = NULL, *listID = NULL;
408         /* GSList *listQP = NULL; */
409
410         for( ;; ) {
411                 gchar *line =  vcard_get_line( cardFile );
412                 if( line == NULL ) break;
413
414                 /* g_print( "%s\n", line ); */
415
416                 /* Parse line */
417                 tagtemp = vcard_get_tagname( line, VCARD_SEP_TAG );
418                 if( tagtemp == NULL ) {
419                         g_free( line );
420                         continue;
421                 }
422
423                 /* g_print( "\ttemp:  %s\n", tagtemp ); */
424                 tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
425                 if( tagvalue == NULL ) {
426                         g_free( tagtemp );
427                         g_free( line );
428                         continue;
429                 }
430
431                 tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
432                 tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
433                 if( tagname == NULL ) {
434                         tagname = tagtemp;
435                         tagtemp = NULL;
436                 }
437
438                 /* g_print( "\tname:  %s\n", tagname ); */
439                 /* g_print( "\ttype:  %s\n", tagtype ); */
440                 /* g_print( "\tvalue: %s\n", tagvalue ); */
441
442                 if( g_utf8_collate( tagtype, VCARD_TYPE_QP ) == 0 ) {
443                         gchar *tmp;
444                         /* Quoted-Printable: could span multiple lines */
445                         tagvalue = vcard_read_qp( cardFile, tagvalue );
446                         tmp = vcard_unescape_qp( tagvalue );
447                         g_free(tagvalue);
448                         tagvalue=tmp;
449                         /* g_print( "QUOTED-PRINTABLE !!! final\n>%s<\n", tagvalue ); */
450                 }
451
452                 if( g_utf8_collate( tagname, VCARD_TAG_START ) == 0 &&
453                         g_ascii_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
454                         /* g_print( "start card\n" ); */
455                         vcard_free_lists( listName, listAddress, listRemarks, listID );
456                         listName = listAddress = listRemarks = listID = NULL;
457                 }
458                 if( g_utf8_collate( tagname, VCARD_TAG_FULLNAME ) == 0 ) {
459                         /* g_print( "- full name: %s\n", tagvalue ); */
460                         listName = g_slist_append( listName, g_strdup( tagvalue ) );
461                 }
462                 if( g_utf8_collate( tagname, VCARD_TAG_EMAIL ) == 0 ) {
463                         /* g_print( "- address: %s\n", tagvalue ); */
464                         listAddress = g_slist_append( listAddress, g_strdup( tagvalue ) );
465                         listRemarks = g_slist_append( listRemarks, g_strdup( tagtype ) );
466                 }
467                 if( g_utf8_collate( tagname, VCARD_TAG_UID ) == 0 ) {
468                         /* g_print( "- id: %s\n", tagvalue ); */
469                         listID = g_slist_append( listID, g_strdup( tagvalue ) );
470                 }
471                 if( g_utf8_collate( tagname, VCARD_TAG_END ) == 0 &&
472                         g_ascii_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
473                         /* vCard is complete */
474                         /* g_print( "end card\n--\n" ); */
475                         /* vcard_dump_lists( listName, listAddress, listRemarks, listID, stdout ); */
476                         vcard_build_items( cardFile, listName, listAddress, listRemarks, listID );
477                         vcard_free_lists( listName, listAddress, listRemarks, listID );
478                         listName = listAddress = listRemarks = listID = NULL;
479                 }
480
481                 g_free( tagname );
482                 g_free( tagtype );
483                 g_free( tagvalue );
484                 g_free( tagtemp );
485                 g_free( line );
486                 line = NULL;
487         }
488
489         /* Free lists */
490         vcard_free_lists( listName, listAddress, listRemarks, listID );
491         listName = listAddress = listRemarks = listID = NULL;
492 }
493
494 /* ============================================================================================ */
495 /*
496 * Read file into list. Main entry point
497 * Return: TRUE if file read successfully.
498 */
499 /* ============================================================================================ */
500 gint vcard_read_data( VCardFile *cardFile ) {
501         g_return_val_if_fail( cardFile != NULL, -1 );
502
503         cardFile->retVal = MGU_SUCCESS;
504         cardFile->addressCache->accessFlag = FALSE;
505         if( addrcache_check_file( cardFile->addressCache, cardFile->path ) ) {
506                 addrcache_clear( cardFile->addressCache );
507                 vcard_open_file( cardFile );
508                 if( cardFile->retVal == MGU_SUCCESS ) {
509                         /* Read data into the list */
510                         vcard_read_file( cardFile );
511                         vcard_close_file( cardFile );
512
513                         /* Mark cache */
514                         addrcache_mark_file( cardFile->addressCache, cardFile->path );
515                         cardFile->addressCache->modified = FALSE;
516                         cardFile->addressCache->dataRead = TRUE;
517                 }
518         }
519         return cardFile->retVal;
520 }
521
522 /*
523 * Return link list of persons.
524 */
525 GList *vcard_get_list_person( VCardFile *cardFile ) {
526         g_return_val_if_fail( cardFile != NULL, NULL );
527         return addrcache_get_list_person( cardFile->addressCache );
528 }
529
530 /*
531 * Return link list of folders. This is always NULL since there are
532 * no folders in GnomeCard.
533 * Return: NULL.
534 */
535 GList *vcard_get_list_folder( VCardFile *cardFile ) {
536         g_return_val_if_fail( cardFile != NULL, NULL );
537         return NULL;
538 }
539
540 /*
541 * Return link list of all persons. Note that the list contains references
542 * to items. Do *NOT* attempt to use the addrbook_free_xxx() functions...
543 * this will destroy the addressbook data!
544 * Return: List of items, or NULL if none.
545 */
546 GList *vcard_get_all_persons( VCardFile *cardFile ) {
547         g_return_val_if_fail( cardFile != NULL, NULL );
548         return addrcache_get_all_persons( cardFile->addressCache );
549 }
550
551 #define WORK_BUFLEN 1024
552
553 /*
554 * Attempt to find a valid GnomeCard file.
555 * Return: Filename, or home directory if not found. Filename should
556 *       be g_free() when done.
557 */
558 gchar *vcard_find_gnomecard( void ) {
559         const gchar *homedir;
560         gchar buf[ WORK_BUFLEN ];
561         gchar str[ WORK_BUFLEN ];
562         gchar *fileSpec;
563         gint len, lenlbl, i;
564         FILE *fp;
565
566         homedir = get_home_dir();
567         if( ! homedir ) return NULL;
568
569         strcpy( str, homedir );
570         len = strlen( str );
571         if( len > 0 ) {
572                 if( str[ len-1 ] != G_DIR_SEPARATOR ) {
573                         str[ len ] = G_DIR_SEPARATOR;
574                         str[ ++len ] = '\0';
575                 }
576         }
577         strcat( str, GNOMECARD_DIR );
578         strcat( str, G_DIR_SEPARATOR_S );
579         strcat( str, GNOMECARD_FILE );
580
581         fileSpec = NULL;
582         if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
583                 /* Read configuration file */
584                 lenlbl = strlen( GNOMECARD_SECTION );
585                 while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
586                         if( 0 == g_ascii_strncasecmp( buf, GNOMECARD_SECTION, lenlbl ) ) {
587                                 break;
588                         }
589                 }
590
591                 while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
592                         g_strchomp( buf );
593                         if( buf[0] == '[' ) break;
594                         for( i = 0; i < lenlbl; i++ ) {
595                                 if( buf[i] == '=' ) {
596                                         if( 0 == g_ascii_strncasecmp( buf, GNOMECARD_PARAM, i ) ) {
597                                                 fileSpec = g_strdup( buf + i + 1 );
598                                                 g_strstrip( fileSpec );
599                                         }
600                                 }
601                         }
602                 }
603                 fclose( fp );
604         }
605
606         if( fileSpec == NULL ) {
607                 /* Use the home directory */
608                 str[ len ] = '\0';
609                 fileSpec = g_strdup( str );
610         }
611
612         return fileSpec;
613 }
614
615 /*
616 * Attempt to read file, testing for valid vCard format.
617 * Return: TRUE if file appears to be valid format.
618 */
619 gint vcard_test_read_file( const gchar *fileSpec ) {
620         gboolean haveStart;
621         gchar *tagtemp = NULL, *tagname = NULL, *tagvalue = NULL, *tagtype = NULL, *line;
622         VCardFile *cardFile;
623         gint retVal, lines;
624
625         if( ! fileSpec ) return MGU_NO_FILE;
626
627         cardFile = vcard_create_path( fileSpec );
628         cardFile->retVal = MGU_SUCCESS;
629         vcard_open_file( cardFile );
630         if( cardFile->retVal == MGU_SUCCESS ) {
631                 cardFile->retVal = MGU_BAD_FORMAT;
632                 haveStart = FALSE;
633                 lines = VCARD_TEST_LINES;
634                 while( lines > 0 ) {
635                         lines--;
636                         if( ( line =  vcard_get_line( cardFile ) ) == NULL ) break;
637
638                         /* Parse line */
639                         tagtemp = vcard_get_tagname( line, VCARD_SEP_TAG );
640                         if( tagtemp == NULL ) {
641                                 g_free( line );
642                                 continue;
643                         }
644
645                         tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
646                         if( tagvalue == NULL ) {
647                                 g_free( tagtemp );
648                                 g_free( line );
649                                 continue;
650                         }
651
652                         tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
653                         tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
654                         if( tagname == NULL ) {
655                                 tagname = tagtemp;
656                                 tagtemp = NULL;
657                         }
658
659                         if( g_utf8_collate( tagtype, VCARD_TYPE_QP ) == 0 ) {
660                                 gchar *tmp;
661                                 /* Quoted-Printable: could span multiple lines */
662                                 tagvalue = vcard_read_qp( cardFile, tagvalue );
663                                 tmp = vcard_unescape_qp( tagvalue );
664                                 g_free(tagvalue);
665                                 tagvalue=tmp;
666                         }
667                         if( g_utf8_collate( tagname, VCARD_TAG_START ) == 0 &&
668                                 g_ascii_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
669                                 haveStart = TRUE;
670                         }
671                         if( g_utf8_collate( tagname, VCARD_TAG_END ) == 0 &&
672                                 g_ascii_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
673                                 /* vCard is complete */
674                                 if( haveStart ) cardFile->retVal = MGU_SUCCESS;
675                         }
676
677                         g_free( tagname );
678                         g_free( tagtype );
679                         g_free( tagvalue );
680                         g_free( tagtemp );
681                         g_free( line );
682                 }
683                 vcard_close_file( cardFile );
684         }
685         retVal = cardFile->retVal;
686         vcard_free( cardFile );
687         cardFile = NULL;
688         return retVal;
689 }
690
691 /*
692 * End of Source.
693 */
694