dbox-mail.c revision b8d314c6355009ad0b9e332b6acecdfac5cc8891
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (c) 2007-2010 Dovecot authors, see the included COPYING file */
5363a534097c170ef9cccbdde5ca802f581f5eb7Timo Sirainendbox_mail_alloc(struct mailbox_transaction_context *t,
5363a534097c170ef9cccbdde5ca802f581f5eb7Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen index_mail_init(&mail->imail, t, wanted_fields, wanted_headers);
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenint dbox_mail_metadata_read(struct dbox_mail *mail, struct dbox_file **file_r)
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen (struct dbox_storage *)mail->imail.mail.mail.box->storage;
a205d315b0978985ba77d871f44e4a98273612e6Timo Sirainen if (storage->v.mail_open(mail, &offset, file_r) < 0)
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen if (dbox_file_get_mail_stream(*file_r, offset, NULL) <= 0)
a6a2b38d806f3ab3198160e39240a8200775e525Timo Sirainen /* we just messed up mail's input stream by reading metadata */
12d34ab79772e0748a1daef30fa749dfe3036608Timo Sirainendbox_mail_metadata_get(struct dbox_mail *mail, enum dbox_metadata_key key,
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen const char **value_r)
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenint dbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct index_mail_data *data = &mail->imail.data;
821984ecb6c90696f35c32a8dc4c8a60f9e98f99Timo Sirainen if (index_mail_get_physical_size(_mail, size_r) == 0)
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen /* see if we have it in metadata */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen value = dbox_file_metadata_get(file, DBOX_METADATA_PHYSICAL_SIZE);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen data->physical_size = strtoul(value, NULL, 16);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen /* no. that means we can use the size in the header */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen data->physical_size = file->cur_physical_size;
4efba37e4f27b93832f6147c3a353d6d22c855c7Timo Sirainenint dbox_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct index_mail_data *data = &mail->imail.data;
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen if (index_mail_get_cached_virtual_size(&mail->imail, size_r))
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen if (dbox_mail_metadata_get(mail, DBOX_METADATA_VIRTUAL_SIZE,
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen return index_mail_get_virtual_size(_mail, size_r);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen data->virtual_size = strtoul(value, NULL, 16);
821984ecb6c90696f35c32a8dc4c8a60f9e98f99Timo Sirainenint dbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct index_mail_data *data = &mail->imail.data;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen if (index_mail_get_received_date(_mail, date_r) == 0)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen if (dbox_mail_metadata_get(mail, DBOX_METADATA_RECEIVED_TIME,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen data->received_date = value == NULL ? 0 : strtoul(value, NULL, 16);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenint dbox_mail_get_save_date(struct mail *_mail, time_t *date_r)
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct index_mail_data *data = &mail->imail.data;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen if (index_mail_get_save_date(_mail, date_r) == 0)
d22301419109ed4a38351715e6760011421dadecTimo Sirainendbox_get_cached_metadata(struct dbox_mail *mail, enum dbox_metadata_key key,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const char **value_r)
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen if (mail_cache_lookup_field(imail->trans->cache_view, str,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen if (dbox_mail_metadata_get(mail, key, &value) < 0)
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenint dbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char **value_r)
8bb360f9e5de1c25e4f875205bb06e8bf15dae14Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen /* keep the UIDL in cache file, otherwise POP3 would open all
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen mail files and read the metadata. same for GUIDs if they're
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen return dbox_get_cached_metadata(mail, DBOX_METADATA_POP3_UIDL,
33ae95df45c9b5ec51332a6b39eb5322038686b9Timo Sirainen return dbox_get_cached_metadata(mail, DBOX_METADATA_GUID,
2054222e84cb972842cc4de88e16516bef41b542Timo Sirainen return index_mail_get_special(_mail, field, value_r);
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainenint dbox_mail_get_stream(struct mail *_mail, struct message_size *hdr_size,
bf301a34ffbfd049be583094019b2644884b6d0bTimo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen struct index_mail_data *data = &mail->imail.data;
d371507847d62ba311b4bcc23d18f45c3d0f1a38Timo Sirainen if (storage->v.mail_open(mail, &offset, &mail->open_file) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ret = dbox_file_get_mail_stream(mail->open_file, offset,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "uid=%u points to broken data at offset="