Ejemplo n.º 1
0
static int
dbox_get_cached_metadata(struct dbox_mail *mail, enum dbox_metadata_key key,
			 enum index_cache_field cache_field,
			 const char **value_r)
{
	struct index_mail *imail = &mail->imail;
	struct index_mailbox_context *ibox =
		INDEX_STORAGE_CONTEXT(imail->mail.mail.box);
	const char *value;
	string_t *str;
	uint32_t order;

	str = str_new(imail->mail.data_pool, 64);
	if (mail_cache_lookup_field(imail->mail.mail.transaction->cache_view,
				    str, imail->mail.mail.seq,
				    ibox->cache_fields[cache_field].idx) > 0) {
		if (cache_field == MAIL_CACHE_POP3_ORDER) {
			i_assert(str_len(str) == sizeof(order));
			memcpy(&order, str_data(str), sizeof(order));
			str_truncate(str, 0);
			if (order != 0)
				str_printfa(str, "%u", order);
			else {
				/* order=0 means it doesn't exist. we don't
				   want to return "0" though, because then the
				   mails get ordered to beginning, while
				   nonexistent are supposed to be ordered at
				   the end. */
			}
		}
		*value_r = str_c(str);
		return 0;
	}

	if (dbox_mail_metadata_get(mail, key, &value) < 0)
		return -1;

	if (value == NULL)
		value = "";
	if (cache_field != MAIL_CACHE_POP3_ORDER) {
		index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
					 value, strlen(value)+1);
	} else {
		if (str_to_uint(value, &order) < 0)
			order = 0;
		index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
					 &order, sizeof(order));
	}

	/* don't return pointer to dbox metadata directly, since it may
	   change unexpectedly */
	str_truncate(str, 0);
	str_append(str, value);
	*value_r = str_c(str);
	return 0;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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;
}