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