2005-11-07 [colin] 1.9.99cvs17
[claws.git] / src / ldif.c
index 61a95fc71de8074b91e99f572cf97eaf61495515..60c277cabe94b53bf13162ed992e80e457ec6c59 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 /*
@@ -306,26 +306,28 @@ static void ldif_close_file( LdifFile *ldifFile ) {
 static gchar *ldif_get_line( LdifFile *ldifFile ) {
        gchar buf[ LDIFBUFSIZE ];
        gint ch;
-       gchar *ptr;
+       int i = 0;
 
-       if( feof( ldifFile->file ) ) return NULL;
+       if( feof( ldifFile->file ) ) 
+               return NULL;
 
-       ptr = buf;
-       while( TRUE ) {
-               *ptr = '\0';
+       while( i < LDIFBUFSIZE-1 ) {
                ch = fgetc( ldifFile->file );
                if( ch == '\0' || ch == EOF ) {
-                       if( *buf == '\0' ) return NULL;
+                       if( i == 0 ) return NULL;
                        break;
                }
 #if HAVE_DOSISH_SYSTEM
 #else
-               if( ch == '\r' ) continue;
+               if( ch == '\r' ) 
+                       continue;
 #endif
-               if( ch == '\n' ) break;
-               *ptr = ch;
-               ptr++;
+               if( ch == '\n' ) 
+                       break;
+               buf[i] = ch;
+               i++;
        }
+       buf[i] = '\0';
 
        /* Return a copy of buffer */
        return g_strdup( buf );
@@ -483,6 +485,14 @@ static void ldif_build_items(
                        fullName = g_strdup_printf( "%s", lastName );
                }
        }
+       
+       if (!fullName || strlen(fullName) == 0) {
+               g_free(fullName);
+               fullName = NULL;
+               if (rec->listCName)
+                       fullName = g_strdup(rec->listCName->data);
+       }
+       
        if( fullName ) {
                g_strchug( fullName ); g_strchomp( fullName );
        }
@@ -723,7 +733,17 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
                        if( lastTag ) {
                                /* Save record */
                                fullValue = mgu_list_coalesce( listValue );
-
+                               if (fullValue && last64) {
+                                       gchar *out = g_malloc(strlen(fullValue));
+                                       int len = 0;
+                                       if ((len = base64_decode(out, fullValue,
+                                                       strlen(fullValue))) >= 0) {
+                                               g_free(fullValue);
+                                               fullValue = out;
+                                               fullValue[len] = '\0';
+                                       } else
+                                               g_free(out);
+                               }
                                /* Base-64 encoded data */
                                /*
                                if( last64 ) {
@@ -764,6 +784,17 @@ static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
                                                        /* Save data */
                                                        fullValue =
                                                                mgu_list_coalesce( listValue );
+                                                       if (fullValue && last64) {
+                                                               gchar *out = g_malloc(strlen(fullValue));
+                                                               int len = 0;
+                                                               if ((len = base64_decode(out, fullValue,
+                                                                               strlen(fullValue))) >= 0) {
+                                                                       g_free(fullValue);
+                                                                       fullValue = out;
+                                                                       fullValue[len] = '\0';
+                                                               } else
+                                                                       g_free(out);
+                                                       }
                                                        /* Base-64 encoded data */
                                                        /*
                                                        if( last64 ) {
@@ -908,7 +939,6 @@ static void ldif_read_tag_list( LdifFile *ldifFile ) {
        /* Process file */
        while( ! flagEOF ) {
                gchar *line = ldif_get_line( ldifFile );
-
                posCur = ftell( ldifFile->file );
                if( ldifFile->cbProgress ) {
                        /* Call progress indicator */
@@ -948,6 +978,7 @@ static void ldif_read_tag_list( LdifFile *ldifFile ) {
                                if( tagName ) {
                                        /* Add tag to list */
                                        listTags = g_slist_append( listTags, tagName );
+
                                        if( g_utf8_collate(
                                                tagName, LDIF_TAG_EMAIL ) == 0 )
                                        {