]> code.citadel.org Git - citadel.git/blobdiff - citadel/utils/ctdlload.c
Fix ansi auto-detect
[citadel.git] / citadel / utils / ctdlload.c
index 0bb24e25dc1865930aa7749d67b99fb7bb2aa325..aed19b472cc1ec0e9d2d73d4ef7551afa4e343e1 100644 (file)
@@ -1,6 +1,6 @@
 // Load (restore) the Citadel database from a flat file created by ctdldump
 //
-// Copyright (c) 2023-2024 by Art Cancro citadel.org
+// Copyright (c) 2023-2024 by citadel.org (Art Cancro et al.)
 //
 // This program is open source software.  Use, duplication, or disclosure
 // is subject to the terms of the GNU General Public License, version 3.
@@ -118,6 +118,7 @@ int import_user(char *line, struct cdbkeyval *kv) {
        char userkey[USERNAME_SIZE];
        char *token;
        struct ctdluser *u;
+       int dlen = 0;
 
        u = malloc(sizeof(struct ctdluser));
        if (!u) {
@@ -163,8 +164,12 @@ int import_user(char *line, struct cdbkeyval *kv) {
                                u->msgnum_pic = atol(token);
                                break;
                        case 12:
-                               CtdlDecodeBase64(token, token, strlen(token));                  // Decode in place
-                               safestrncpy(u->emailaddrs, token, sizeof(u->emailaddrs));
+                               dlen = CtdlDecodeBase64(token, token, strlen(token));                   // Decode in place
+                               if (dlen >= sizeof(u->emailaddrs)) {
+                                       dlen = sizeof(u->emailaddrs) - 1;
+                               }
+                               memcpy(u->emailaddrs, token, dlen);
+                               u->emailaddrs[dlen] = 0;
                                break;
                        case 13:
                                u->msgnum_inboxrules = atol(token);
@@ -691,6 +696,7 @@ void ingest_one(char *line, struct cdbkeyval *kv) {
                ++good_rows;
        }
        else {
+               fprintf(stderr, "bad row: <%s>\n", line);
                ++bad_rows;
        }
 
@@ -731,6 +737,10 @@ void ingest(void) {
                }
 
                if (line_len > 0) {
+                       if (!strncasecmp(line, HKEY("end|"))) {
+                               fprintf(stderr, "\n");
+                               end_found = 1;
+                       }
                        if ( (begin_found) && (!end_found) ) {
                                ingest_one(line, &kv);
                        }
@@ -738,10 +748,6 @@ void ingest(void) {
                                begin_found = 1;
                                fprintf(stderr, "   good rows / bad rows:\n");
                        }
-                       if (!strncasecmp(line, HKEY("end|"))) {
-                               fprintf(stderr, "\n");
-                               end_found = 1;
-                       }
                }
 
        } while (ch >= 0);
@@ -763,11 +769,12 @@ int main(int argc, char **argv) {
        // display the greeting
        fprintf(stderr,
                "\033[44m\033[1m╔════════════════════════════════════════════════════════════════════════╗\033[0m\n"
-               "\033[44m\033[1m║ DB Load utility for Citadel                                            ║\033[0m\n"
+               "\033[44m\033[1m║ DB Load utility for Citadel                               version %-4d ║\033[0m\n"
                "\033[44m\033[1m║ Copyright (c) 2023-2024 by citadel.org et al.                          ║\033[0m\n"
                "\033[44m\033[1m║ This program is open source software.  Use, duplication, or disclosure ║\033[0m\n"
                "\033[44m\033[1m║ is subject to the terms of the GNU General Public license v3.          ║\033[0m\n"
-               "\033[44m\033[1m╚════════════════════════════════════════════════════════════════════════╝\033[0m\n"
+               "\033[44m\033[1m╚════════════════════════════════════════════════════════════════════════╝\033[0m\n",
+               REV_LEVEL
        );
 
        // Parse command line