static int dbox_file_parse_header(struct dbox_file *file, const char *line) { const char *const *tmp, *value; unsigned int pos; enum dbox_header_key key; file->file_version = *line - '0'; if (!i_isdigit(line[0]) || line[1] != ' ' || (file->file_version != 1 && file->file_version != DBOX_VERSION)) { dbox_file_set_corrupted(file, "Invalid dbox version"); return -1; } line += 2; pos = 2; file->msg_header_size = 0; for (tmp = t_strsplit(line, " "); *tmp != NULL; tmp++) { uintmax_t time; key = **tmp; value = *tmp + 1; switch (key) { case DBOX_HEADER_OLDV1_APPEND_OFFSET: break; case DBOX_HEADER_MSG_HEADER_SIZE: if (str_to_uint_hex(value, &file->msg_header_size) < 0) { dbox_file_set_corrupted(file, "Invalid message header size"); return -1; } break; case DBOX_HEADER_CREATE_STAMP: if (str_to_uintmax_hex(value, &time) < 0) { dbox_file_set_corrupted(file, "Invalid create time stamp"); return -1; } file->create_time = (time_t)time; break; } pos += strlen(value) + 2; } if (file->msg_header_size == 0) { dbox_file_set_corrupted(file, "Missing message header size"); return -1; } return 0; }
int dbox_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r) { struct dbox_mail *mail = (struct dbox_mail *)_mail; struct index_mail_data *data = &mail->imail.data; const char *value; uintmax_t size; if (index_mail_get_cached_virtual_size(&mail->imail, size_r)) return 0; if (dbox_mail_metadata_get(mail, DBOX_METADATA_VIRTUAL_SIZE, &value) < 0) return -1; if (value == NULL) return index_mail_get_virtual_size(_mail, size_r); if (str_to_uintmax_hex(value, &size) < 0 || size > (uoff_t)-1) return -1; data->virtual_size = (uoff_t)size; *size_r = data->virtual_size; return 0; }
int dbox_mail_get_received_date(struct mail *_mail, time_t *date_r) { struct dbox_mail *mail = (struct dbox_mail *)_mail; struct index_mail_data *data = &mail->imail.data; const char *value; uintmax_t time; if (index_mail_get_received_date(_mail, date_r) == 0) return 0; if (dbox_mail_metadata_get(mail, DBOX_METADATA_RECEIVED_TIME, &value) < 0) return -1; time = 0; if (value != NULL && str_to_uintmax_hex(value, &time) < 0) return -1; data->received_date = (time_t)time; *date_r = data->received_date; return 0; }