+static int
+memoserv_history_read(const char *key, struct record_data *hir)
+{
+ char *str;
+ struct handle_info *sender, *recipient;
+ struct history *history;
+ unsigned long id;
+ time_t sent;
+
+ if (hir->type != RECDB_OBJECT) {
+ log_module(MS_LOG, LOG_WARNING, "Unexpected rectype %d for %s.", hir->type, key);
+ return 0;
+ }
+
+ if (!(str = database_get_data(hir->d.object, KEY_SENT, RECDB_QSTRING))) {
+ log_module(MS_LOG, LOG_ERROR, "Date sent not present in history %s; skipping", key);
+ return 0;
+ }
+
+ sent = atoi(str);
+
+ if (!(str = database_get_data(hir->d.object, KEY_ID, RECDB_QSTRING))) {
+ log_module(MS_LOG, LOG_ERROR, "ID sent not present in history %s; skipping", key);
+ return 0;
+ }
+ id = strtoul(str, NULL, 0);
+
+ if (!(str = database_get_data(hir->d.object, KEY_RECIPIENT, RECDB_QSTRING))) {
+ log_module(MS_LOG, LOG_ERROR, "Recipient not present in history %s; skipping", key);
+ return 0;
+ } else if (!(recipient = get_handle_info(str))) {
+ log_module(MS_LOG, LOG_ERROR, "Invalid recipient %s in history %s; skipping", str, key);
+ return 0;
+ }
+
+ if (!(str = database_get_data(hir->d.object, KEY_FROM, RECDB_QSTRING))) {
+ log_module(MS_LOG, LOG_ERROR, "Sender not present in history %s; skipping", key);
+ return 0;
+ } else if (!(sender = get_handle_info(str))) {
+ log_module(MS_LOG, LOG_ERROR, "Invalid sender %s in history %s; skipping", str, key);
+ return 0;
+ }
+
+ history = add_history(sent, memoserv_get_account(recipient), memoserv_get_account(sender), id);
+
+ return 0;
+}
+