+/*
+ * Helper function for move_inet_addrs_from_vcards_to_user_records()
+ *
+ * Call this function as a ForEachUser backend in order to queue up
+ * user names, or call it with a null user to make it do the processing.
+ * This allows us to maintain the list as a static instead of passing
+ * pointers around.
+ */
+void miafvtur_backend(char *username, void *data) {
+ struct ctdluser usbuf;
+ char primary_inet_email[512] = { 0 };
+ char other_inet_emails[512] = { 0 };
+ char combined_inet_emails[512] = { 0 };
+
+ if (CtdlGetUser(&usbuf, username) != 0) {
+ return;
+ }
+
+ struct vCard *v = vcard_get_user(&usbuf);
+ if (!v) return;
+ extract_inet_email_addrs(primary_inet_email, sizeof primary_inet_email, other_inet_emails, sizeof other_inet_emails, v, 1);
+ vcard_free(v);
+
+ if ( (IsEmptyStr(primary_inet_email)) && (IsEmptyStr(other_inet_emails)) ) {
+ return;
+ }
+
+ snprintf(combined_inet_emails, 512, "%s%s%s",
+ (!IsEmptyStr(primary_inet_email) ? primary_inet_email : ""),
+ ((!IsEmptyStr(primary_inet_email)&&(!IsEmptyStr(other_inet_emails))) ? "|" : ""),
+ (!IsEmptyStr(other_inet_emails) ? other_inet_emails : "")
+ );
+
+ CtdlSetEmailAddressesForUser(usbuf.fullname, combined_inet_emails);
+}
+
+
+/*
+ * If our system still has a "refcount_adjustments.dat" sitting around from an old version, ingest it now.
+ */
+int ProcessOldStyleAdjRefCountQueue(void)
+{
+ int r;
+ FILE *fp;
+ struct arcq arcq_rec;
+ int num_records_processed = 0;
+
+ fp = fopen(file_arcq, "rb");
+ if (fp == NULL) {
+ return(num_records_processed);
+ }
+
+ syslog(LOG_INFO, "msgbase: ingesting %s", file_arcq);
+
+ while (fread(&arcq_rec, sizeof(struct arcq), 1, fp) == 1) {
+ AdjRefCount(arcq_rec.arcq_msgnum, arcq_rec.arcq_delta);
+ ++num_records_processed;
+ }
+
+ fclose(fp);
+ r = unlink(file_arcq);
+ if (r != 0) {
+ syslog(LOG_ERR, "%s: %m", file_arcq);
+ }
+
+ return(num_records_processed);
+}
+
+
+/*
+ * Prior to version 912 we kept a user's various Internet email addresses in their vCards.
+ * This function moves them over to the user record, which is where we keep them now.
+ */
+void move_inet_addrs_from_vcards_to_user_records(void)
+{
+ ForEachUser(miafvtur_backend, NULL);
+ CtdlRebuildDirectoryIndex();
+}
+
+
+
+
+/*
+ * We found the legacy sieve config in the user's config room. Store the message number in the user record.
+ */
+void mifm_found_config(long msgnum, void *userdata) {
+ struct ctdluser *us = (struct ctdluser *)userdata;
+
+ us->msgnum_inboxrules = msgnum;
+ syslog(LOG_DEBUG, "user: <%s> inbox filter msgnum: <%ld>", us->fullname, us->msgnum_inboxrules);
+}
+
+
+/*
+ * Helper function for migrate_inbox_filter_msgnums()
+ */
+void mifm_backend(char *username, void *data) {
+ struct ctdluser us;
+ char roomname[ROOMNAMELEN];
+
+ if (CtdlGetUserLock(&us, username) == 0) {
+ /* Take a spin through the user's personal config room */
+ syslog(LOG_DEBUG, "Processing <%s> (%ld)", us.fullname, us.usernum);
+ snprintf(roomname, sizeof roomname, "%010ld.%s", us.usernum, USERCONFIGROOM);
+ if (CtdlGetRoom(&CC->room, roomname) == 0) {
+ CtdlForEachMessage(MSGS_LAST, 1, NULL, SIEVECONFIG, NULL, mifm_found_config, (void *)&us );
+ }
+ CtdlPutUserLock(&us);
+ }
+}
+
+
+/*
+ * Prior to version 930 we used a MIME type search to locate the user's inbox filter rules.
+ * This function locates those ruleset messages and simply stores the message number in the user record.
+ */
+void migrate_inbox_filter_msgnums(void)
+{
+ ForEachUser(mifm_backend, NULL);
+}
+
+
+/*
+ * Create a default administrator account so we can log in to a new installation
+ */
+void create_default_admin_account(void) {
+ struct ctdluser usbuf;
+
+ create_user(DEFAULT_ADMIN_USERNAME, CREATE_USER_DO_NOT_BECOME_USER, (-1));
+ CtdlGetUser(&usbuf, DEFAULT_ADMIN_USERNAME);
+ safestrncpy(usbuf.password, DEFAULT_ADMIN_PASSWORD, sizeof(usbuf.password));
+ usbuf.axlevel = AxAideU;
+ CtdlPutUser(&usbuf);
+ CtdlSetConfigStr("c_sysadm", DEFAULT_ADMIN_USERNAME);
+}
+