/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Match Grun
+ * Copyright (C) 2001-2002 Match Grun
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "vcard.h"
#include "addritem.h"
#include "addrcache.h"
+#include "adbookbase.h"
#define GNOMECARD_DIR ".gnome"
#define GNOMECARD_FILE "GnomeCard"
VCardFile *vcard_create() {
VCardFile *cardFile;
cardFile = g_new0( VCardFile, 1 );
- cardFile->name = NULL;
- cardFile->path = NULL;
- cardFile->file = NULL;
- cardFile->bufptr = cardFile->buffer;
+ cardFile->type = ADBOOKTYPE_VCARD;
cardFile->addressCache = addrcache_create();
cardFile->retVal = MGU_SUCCESS;
- cardFile->accessFlag = FALSE;
+
+ cardFile->file = NULL;
+ cardFile->path = NULL;
+ cardFile->bufptr = cardFile->buffer;
return cardFile;
}
*/
void vcard_set_name( VCardFile* cardFile, const gchar *value ) {
g_return_if_fail( cardFile != NULL );
- cardFile->name = mgu_replace_string( cardFile->name, value );
- g_strstrip( cardFile->name );
+ addrcache_set_name( cardFile->addressCache, value );
}
void vcard_set_file( VCardFile* cardFile, const gchar *value ) {
g_return_if_fail( cardFile != NULL );
}
void vcard_set_accessed( VCardFile *cardFile, const gboolean value ) {
g_return_if_fail( cardFile != NULL );
- cardFile->accessFlag = value;
+ cardFile->addressCache->accessFlag = value;
}
/*
* Test whether file was modified since last access.
* Return: TRUE if file was modified.
*/
-gboolean vcard_get_modified( VCardFile *vcardFile ) {
- g_return_val_if_fail( vcardFile != NULL, FALSE );
- return addrcache_check_file( vcardFile->addressCache, vcardFile->path );
+gboolean vcard_get_modified( VCardFile *cardFile ) {
+ g_return_val_if_fail( cardFile != NULL, FALSE );
+ cardFile->addressCache->modified =
+ addrcache_check_file( cardFile->addressCache, cardFile->path );
+ return cardFile->addressCache->modified;
}
-gboolean vcard_get_accessed( VCardFile *vcardFile ) {
- g_return_val_if_fail( vcardFile != NULL, FALSE );
- return addrcache_check_file( vcardFile->addressCache, vcardFile->path );
+gboolean vcard_get_accessed( VCardFile *cardFile ) {
+ g_return_val_if_fail( cardFile != NULL, FALSE );
+ return cardFile->addressCache->accessFlag;
}
/*
* Test whether file was read.
* Return: TRUE if file was read.
*/
-gboolean vcard_get_read_flag( VCardFile *vcardFile ) {
- g_return_val_if_fail( vcardFile != NULL, FALSE );
- return vcardFile->addressCache->dataRead;
+gboolean vcard_get_read_flag( VCardFile *cardFile ) {
+ g_return_val_if_fail( cardFile != NULL, FALSE );
+ return cardFile->addressCache->dataRead;
+}
+void vcard_set_read_flag( VCardFile *cardFile, const gboolean value ) {
+ g_return_if_fail( cardFile != NULL );
+ cardFile->addressCache->dataRead = value;
}
/*
}
gchar *vcard_get_name( VCardFile *cardFile ) {
g_return_val_if_fail( cardFile != NULL, NULL );
- return cardFile->name;
+ return addrcache_get_name( cardFile->addressCache );
}
/*
/* Close file */
if( cardFile->file ) fclose( cardFile->file );
- /* Free internal stuff */
- g_free( cardFile->name );
- g_free( cardFile->path );
-
/* Clear cache */
addrcache_clear( cardFile->addressCache );
addrcache_free( cardFile->addressCache );
+ /* Free internal stuff */
+ g_free( cardFile->path );
+
/* Clear pointers */
cardFile->file = NULL;
- cardFile->name = NULL;
cardFile->path = NULL;
+ cardFile->bufptr = NULL;
+
+ cardFile->type = ADBOOKTYPE_NONE;
cardFile->addressCache = NULL;
cardFile->retVal = MGU_SUCCESS;
- cardFile->accessFlag = FALSE;
/* Now release file object */
g_free( cardFile );
-
}
/*
g_return_if_fail( cardFile != NULL );
fprintf( stream, "VCardFile:\n" );
- fprintf( stream, " name: '%s'\n", cardFile->name );
fprintf( stream, "file spec: '%s'\n", cardFile->path );
fprintf( stream, " ret val: %d\n", cardFile->retVal );
addrcache_print( cardFile->addressCache, stream );
/* fprintf( stdout, "Opening file\n" ); */
cardFile->addressCache->dataRead = FALSE;
if( cardFile->path ) {
- cardFile->file = fopen( cardFile->path, "r" );
+ cardFile->file = fopen( cardFile->path, "rb" );
if( ! cardFile->file ) {
/* fprintf( stderr, "can't open %s\n", cardFile->path ); */
cardFile->retVal = MGU_OPEN_FILE;
while( line ) {
listQP = g_slist_append( listQP, line );
len = strlen( line ) - 1;
- if( len > 0 ) {
- if( line[ len ] != '=' ) break;
- line[ len ] = '\0';
- }
+ if( line[ len ] != '=' ) break;
+ line[ len ] = '\0';
line = vcard_get_line( cardFile );
}
gint len = 0;
gchar *tag = NULL;
gchar *lptr = line;
+
while( *lptr++ ) {
if( *lptr == dlm ) {
len = lptr - line;
return value;
}
-/*
-* Dump linked lists of character strings (for debug).
-*/
-static void vcard_dump_lists( GSList *listName, GSList *listAddr, GSList *listRem, GSList *listID, FILE *stream ) {
- fprintf( stream, "dump name\n" );
- fprintf( stream, "------------\n" );
- mgu_print_list( listName, stdout );
- fprintf( stream, "dump address\n" );
- fprintf( stream, "------------\n" );
- mgu_print_list( listAddr, stdout );
- fprintf( stream, "dump remarks\n" );
- fprintf( stdout, "------------\n" );
- mgu_print_list( listRem, stdout );
- fprintf( stream, "dump id\n" );
- fprintf( stdout, "------------\n" );
- mgu_print_list( listID, stdout );
-}
-
/*
* Build an address list entry and append to list of address items.
*/
-static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *listAddr, GSList *listRem,
- GSList *listID )
+static void vcard_build_items(
+ VCardFile *cardFile, GSList *listName, GSList *listAddr,
+ GSList *listRem, GSList *listID )
{
GSList *nodeName = listName;
GSList *nodeID = listID;
if( nodeRemarks ) {
if( str ) {
if( g_strcasecmp( str, "internet" ) != 0 ) {
- if( *str != '\0' ) addritem_email_set_remarks( email, str );
+ if( *str != '\0' )
+ addritem_email_set_remarks( email, str );
}
}
}
if( person->listEMail ) {
addrcache_id_person( cardFile->addressCache, person );
addrcache_add_person( cardFile->addressCache, person );
+ if( nodeID ) {
+ str = nodeID->data;
+ addritem_person_set_external_id( person, str );
+ }
}
else {
addritem_free_item_person( person );
}
- if( nodeID ) {
- str = nodeID->data;
- addritem_person_set_external_id( person, str );
- }
nodeName = g_slist_next( nodeName );
nodeID = g_slist_next( nodeID );
}
/* Parse line */
tagtemp = vcard_get_tagname( line, VCARD_SEP_TAG );
- if( tagtemp ) {
- /* fprintf( stdout, "\ttemp: %s\n", tagtemp ); */
- tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
- tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
- tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
- if( tagname == NULL ) {
- tagname = tagtemp;
- tagtemp = NULL;
- }
+ if( tagtemp == NULL ) {
+ g_free( line );
+ continue;
+ }
+
+ /* fprintf( stdout, "\ttemp: %s\n", tagtemp ); */
+ tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
+ if( tagvalue == NULL ) {
+ g_free( tagtemp );
+ g_free( line );
+ continue;
+ }
- /* fprintf( stdout, "\tname: %s\n", tagname ); */
- /* fprintf( stdout, "\ttype: %s\n", tagtype ); */
- /* fprintf( stdout, "\tvalue: %s\n", tagvalue ); */
+ tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
+ tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
+ if( tagname == NULL ) {
+ tagname = tagtemp;
+ tagtemp = NULL;
+ }
- if( tagvalue ) {
- if( g_strcasecmp( tagtype, VCARD_TYPE_QP ) == 0 ) {
- /* Quoted-Printable: could span multiple lines */
- tagvalue = vcard_read_qp( cardFile, tagvalue );
- vcard_unescape_qp( tagvalue );
- /* fprintf( stdout, "QUOTED-PRINTABLE !!! final\n>%s<\n", tagvalue ); */
- }
+ /* fprintf( stdout, "\tname: %s\n", tagname ); */
+ /* fprintf( stdout, "\ttype: %s\n", tagtype ); */
+ /* fprintf( stdout, "\tvalue: %s\n", tagvalue ); */
- if( g_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&
- g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
- /* fprintf( stdout, "start card\n" ); */
- vcard_free_lists( listName, listAddress, listRemarks, listID );
- listName = listAddress = listRemarks = listID = NULL;
- }
- if( g_strcasecmp( tagname, VCARD_TAG_FULLNAME ) == 0 ) {
- /* fprintf( stdout, "- full name: %s\n", tagvalue ); */
- listName = g_slist_append( listName, g_strdup( tagvalue ) );
- }
- if( g_strcasecmp( tagname, VCARD_TAG_EMAIL ) == 0 ) {
- /* fprintf( stdout, "- address: %s\n", tagvalue ); */
- listAddress = g_slist_append( listAddress, g_strdup( tagvalue ) );
- listRemarks = g_slist_append( listRemarks, g_strdup( tagtype ) );
- }
- if( g_strcasecmp( tagname, VCARD_TAG_UID ) == 0 ) {
- /* fprintf( stdout, "- id: %s\n", tagvalue ); */
- listID = g_slist_append( listID, g_strdup( tagvalue ) );
- }
- if( g_strcasecmp( tagname, VCARD_TAG_END ) == 0 &&
- g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
- /* vCard is complete */
- /* fprintf( stdout, "end card\n--\n" ); */
- /* vcard_dump_lists( listName, listAddress, listRemarks, listID, stdout ); */
- vcard_build_items( cardFile, listName, listAddress, listRemarks, listID );
- vcard_free_lists( listName, listAddress, listRemarks, listID );
- listName = listAddress = listRemarks = listID = NULL;
- }
- g_free( tagvalue );
- }
- g_free( tagname );
- g_free( tagtype );
+ if( g_strcasecmp( tagtype, VCARD_TYPE_QP ) == 0 ) {
+ /* Quoted-Printable: could span multiple lines */
+ tagvalue = vcard_read_qp( cardFile, tagvalue );
+ vcard_unescape_qp( tagvalue );
+ /* fprintf( stdout, "QUOTED-PRINTABLE !!! final\n>%s<\n", tagvalue ); */
+ }
+
+ if( g_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&
+ g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
+ /* fprintf( stdout, "start card\n" ); */
+ vcard_free_lists( listName, listAddress, listRemarks, listID );
+ listName = listAddress = listRemarks = listID = NULL;
+ }
+ if( g_strcasecmp( tagname, VCARD_TAG_FULLNAME ) == 0 ) {
+ /* fprintf( stdout, "- full name: %s\n", tagvalue ); */
+ listName = g_slist_append( listName, g_strdup( tagvalue ) );
+ }
+ if( g_strcasecmp( tagname, VCARD_TAG_EMAIL ) == 0 ) {
+ /* fprintf( stdout, "- address: %s\n", tagvalue ); */
+ listAddress = g_slist_append( listAddress, g_strdup( tagvalue ) );
+ listRemarks = g_slist_append( listRemarks, g_strdup( tagtype ) );
}
+ if( g_strcasecmp( tagname, VCARD_TAG_UID ) == 0 ) {
+ /* fprintf( stdout, "- id: %s\n", tagvalue ); */
+ listID = g_slist_append( listID, g_strdup( tagvalue ) );
+ }
+ if( g_strcasecmp( tagname, VCARD_TAG_END ) == 0 &&
+ g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
+ /* vCard is complete */
+ /* fprintf( stdout, "end card\n--\n" ); */
+ /* vcard_dump_lists( listName, listAddress, listRemarks, listID, stdout ); */
+ vcard_build_items( cardFile, listName, listAddress, listRemarks, listID );
+ vcard_free_lists( listName, listAddress, listRemarks, listID );
+ listName = listAddress = listRemarks = listID = NULL;
+ }
+
+ g_free( tagname );
+ g_free( tagtype );
+ g_free( tagvalue );
+ g_free( tagtemp );
g_free( line );
line = NULL;
}
g_return_val_if_fail( cardFile != NULL, -1 );
cardFile->retVal = MGU_SUCCESS;
- cardFile->accessFlag = FALSE;
+ cardFile->addressCache->accessFlag = FALSE;
if( addrcache_check_file( cardFile->addressCache, cardFile->path ) ) {
addrcache_clear( cardFile->addressCache );
vcard_open_file( cardFile );
*/
gboolean vcard_validate( const VCardFile *cardFile ) {
gboolean retVal;
+ gchar *name;
g_return_val_if_fail( cardFile != NULL, FALSE );
else {
retVal = FALSE;
}
- if( cardFile->name ) {
- if( strlen( cardFile->name ) < 1 ) retVal = FALSE;
+ name = addrcache_get_name( cardFile->addressCache );
+ if( name ) {
+ if( strlen( name ) < 1 ) retVal = FALSE;
}
else {
retVal = FALSE;
* be g_free() when done.
*/
gchar *vcard_find_gnomecard( void ) {
- gchar *homedir;
+ const gchar *homedir;
gchar buf[ WORK_BUFLEN ];
gchar str[ WORK_BUFLEN ];
gchar *fileSpec;
strcat( str, GNOMECARD_FILE );
fileSpec = NULL;
- if( ( fp = fopen( str, "r" ) ) != NULL ) {
+ if( ( fp = fopen( str, "rb" ) ) != NULL ) {
/* Read configuration file */
lenlbl = strlen( GNOMECARD_SECTION );
while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
/* Parse line */
tagtemp = vcard_get_tagname( line, VCARD_SEP_TAG );
- if( tagtemp ) {
- tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
- tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
- tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
- if( tagname == NULL ) {
- tagname = tagtemp;
- tagtemp = NULL;
- }
+ if( tagtemp == NULL ) {
+ g_free( line );
+ continue;
+ }
- if( tagvalue ) {
- if( g_strcasecmp( tagtype, VCARD_TYPE_QP ) == 0 ) {
- /* Quoted-Printable: could span multiple lines */
- tagvalue = vcard_read_qp( cardFile, tagvalue );
- vcard_unescape_qp( tagvalue );
- }
- if( g_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&
- g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
- haveStart = TRUE;
- }
- if( g_strcasecmp( tagname, VCARD_TAG_END ) == 0 &&
- g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
- /* vCard is complete */
- if( haveStart ) cardFile->retVal = MGU_SUCCESS;
- }
- g_free( tagvalue );
- }
- g_free( tagname );
- g_free( tagtype );
+ tagvalue = vcard_get_tagvalue( line, VCARD_SEP_TAG );
+ if( tagvalue == NULL ) {
+ g_free( tagtemp );
+ g_free( line );
+ continue;
}
+
+ tagname = vcard_get_tagname( tagtemp, VCARD_SEP_TYPE );
+ tagtype = vcard_get_tagvalue( tagtemp, VCARD_SEP_TYPE );
+ if( tagname == NULL ) {
+ tagname = tagtemp;
+ tagtemp = NULL;
+ }
+
+ if( g_strcasecmp( tagtype, VCARD_TYPE_QP ) == 0 ) {
+ /* Quoted-Printable: could span multiple lines */
+ tagvalue = vcard_read_qp( cardFile, tagvalue );
+ vcard_unescape_qp( tagvalue );
+ }
+ if( g_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&
+ g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
+ haveStart = TRUE;
+ }
+ if( g_strcasecmp( tagname, VCARD_TAG_END ) == 0 &&
+ g_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
+ /* vCard is complete */
+ if( haveStart ) cardFile->retVal = MGU_SUCCESS;
+ }
+
+ g_free( tagname );
+ g_free( tagtype );
+ g_free( tagvalue );
+ g_free( tagtemp );
g_free( line );
- line = NULL;
}
vcard_close_file( cardFile );
}