/* * Read specified file into address book. * Enter: harvester Harvester object. * fileName File to read. * cache Address cache to load. * Return: Status. */ static gint addrharvest_readfile( AddressHarvester *harvester, const gchar *fileName, AddressCache *cache, GList *listHdr ) { gint retVal; FILE *msgFile; gchar *buf, *addr, *p; HeaderEntry *entry; GSList *list; gboolean done; msgFile = fopen( fileName, "rb" ); if( ! msgFile ) { /* Cannot open file */ retVal = MGU_OPEN_FILE; return retVal; } done = FALSE; while( TRUE ) { list = addrharvest_get_header( msgFile, listHdr, &done ); if( done ) break; if( list == NULL ) { continue; } buf = mgu_list_coalesce( list ); mgu_free_list( list ); if(( p = strchr( buf, ':' ) ) != NULL ) { addr = p + 1; *p = '\0'; entry = addrharvest_find( harvester, buf ); if( entry && entry->selected ) { /* Sanitize control characters */ p = addr; while( *p ) { if( *p == '\r' || *p == '\n' || *p == '\t' ) *p = ' '; p++; } addrharvest_parse_address( harvester, entry, cache, addr ); } } g_free( buf ); } fclose( msgFile ); return MGU_SUCCESS; }
/* * Read file data into address cache. * Enter: muttFile MUTT control data. * cache Address cache. */ static void mutt_read_file( MuttFile *muttFile, AddressCache *cache ) { GSList *listValue = NULL; gboolean flagEOF = FALSE, flagCont = FALSE, lastCont = FALSE; gchar *line = NULL, *lineValue = NULL; long posEnd = 0L; long posCur = 0L; /* Find EOF for progress indicator */ fseek( muttFile->file, 0L, SEEK_END ); posEnd = ftell( muttFile->file ); fseek( muttFile->file, 0L, SEEK_SET ); while( ! flagEOF ) { flagCont = FALSE; line = mutt_get_line( muttFile, &flagCont ); posCur = ftell( muttFile->file ); if( muttFile->cbProgress ) { /* Call progress indicator */ ( muttFile->cbProgress ) ( muttFile, & posEnd, & posCur ); } if( line == NULL ) flagEOF = TRUE; if( ! lastCont ) { /* Save data */ lineValue = mgu_list_coalesce( listValue ); if( lineValue ) { mutt_build_items( muttFile, cache, lineValue ); } g_free( lineValue ); lineValue = NULL; mgu_free_list( listValue ); listValue = NULL; } lastCont = flagCont; /* Add line to list */ listValue = g_slist_append( listValue, g_strdup( line ) ); g_free( line ); line = NULL; } /* Release data */ mgu_free_list( listValue ); listValue = NULL; }
/* * Read quoted-printable text, which may span several lines into one long string. * Param: cardFile - object. * Param: tagvalue - will be placed into the linked list. */ static gchar *vcard_read_qp( VCardFile *cardFile, char *tagvalue ) { GSList *listQP = NULL; gint len = 0; gchar *line = tagvalue; while( line ) { listQP = g_slist_append( listQP, line ); len = strlen( line ) - 1; if( line[ len ] != '=' ) break; line[ len ] = '\0'; line = vcard_get_line( cardFile ); } /* Coalesce linked list into one long buffer. */ line = mgu_list_coalesce( listQP ); /* Clean up */ mgu_free_list( listQP ); listQP = NULL; return line; }
/** * Read file data into address cache. * Note that one LDIF record identifies one entity uniquely with the * distinguished name (dn) tag. Each person can have multiple E-Mail * addresses. Also, each person can have many common name (cn) tags. * * \param ldifFile LDIF import control object. * \param cache Address cache to be populated with data. */ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) { gchar *tagName = NULL, *tagValue = NULL; gchar *lastTag = NULL, *fullValue = NULL; GSList *listValue = NULL; gboolean flagEOF = FALSE, flagEOR = FALSE; gboolean flag64 = FALSE, last64 = FALSE; Ldif_ParsedRec *rec; long posEnd = 0L; long posCur = 0L; GHashTable *hashField; gsize len; hashField = ldifFile->hashFields; rec = g_new0( Ldif_ParsedRec, 1 ); ldif_clear_rec( rec ); /* Find EOF for progress indicator */ fseek( ldifFile->file, 0L, SEEK_END ); posEnd = ftell( ldifFile->file ); fseek( ldifFile->file, 0L, SEEK_SET ); while( ! flagEOF ) { gchar *line = ldif_get_line( ldifFile ); posCur = ftell( ldifFile->file ); if( ldifFile->cbProgress ) { /* Call progress indicator */ ( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur ); } flag64 = FALSE; if( line == NULL ) { flagEOF = flagEOR = TRUE; } else if( *line == '\0' ) { flagEOR = TRUE; } if( flagEOR ) { /* EOR, Output address data */ if( lastTag ) { /* Save record */ fullValue = mgu_list_coalesce( listValue ); if (fullValue && last64) { gchar *tmp = g_base64_decode_zero(fullValue, &len); g_free(fullValue); fullValue = tmp; } ldif_add_value( rec, lastTag, fullValue, hashField ); /* ldif_print_record( rec, stdout ); */ ldif_build_items( ldifFile, rec, cache ); ldif_clear_rec( rec ); g_free( lastTag ); mgu_free_list( listValue ); g_free(fullValue); lastTag = NULL; listValue = NULL; last64 = FALSE; } } if( line ) { flagEOR = FALSE; if( *line == ' ' ) { /* Continuation line */ listValue = g_slist_append( listValue, g_strdup( line+1 ) ); } else if( *line == '=' ) { /* Base-64 encoded continuation field */ listValue = g_slist_append( listValue, g_strdup( line ) ); } else { /* Parse line */ tagName = ldif_get_tagname( line, &flag64 ); if( tagName ) { tagValue = ldif_get_tagvalue( line ); if( tagValue ) { if( lastTag ) { /* Save data */ fullValue = mgu_list_coalesce( listValue ); if (fullValue && last64) { gchar *tmp = g_base64_decode_zero(fullValue, &len); g_free(fullValue); fullValue = tmp; } /* Base-64 encoded data */ /* if( last64 ) { ldif_dump_b64( fullValue ); } */ ldif_add_value( rec, lastTag, fullValue, hashField ); g_free( lastTag ); mgu_free_list( listValue ); lastTag = NULL; listValue = NULL; } lastTag = g_strdup( tagName ); listValue = g_slist_append( listValue, g_strdup( tagValue ) ); g_free( tagValue ); last64 = flag64; } g_free( tagName ); } } } g_free( line ); } /* Release data */ ldif_clear_rec( rec ); g_free( rec ); g_free( lastTag ); mgu_free_list( listValue ); }