pop3c-mail.c revision e130bb802c8bfb6c6cc44e5c8bc098b4fa5af789
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen/* Copyright (c) 2011-2013 Dovecot authors, see the included COPYING file */
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainenstatic int pop3c_mail_get_received_date(struct mail *_mail, time_t *date_r)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* FIXME: we could also parse the first Received: header and get
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen the date from there, but since this code is unlikely to be called
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen except during migration, I don't think it really matters. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen return index_mail_get_date(_mail, date_r, &tz);
1d4f710106fb498750456724628da6063e012e6dTimo Sirainenstatic int pop3c_mail_get_save_date(struct mail *_mail, time_t *date_r)
9439bed2f07d6475febd8a247cd2f0990fb32a13Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* FIXME: we could use a value stored in cache */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen return pop3c_mail_get_received_date(_mail, date_r);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic int pop3c_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
baebb412a9a5a44b1756e01cfa3b99f5d8a846b6Timo Sirainen /* virtual size is already known. it's the same as our
baebb412a9a5a44b1756e01cfa3b99f5d8a846b6Timo Sirainen (correct) physical size */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (index_mail_get_physical_size(_mail, size_r) == 0) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (_mail->lookup_abort == MAIL_LOOKUP_ABORT_READ_MAIL &&
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen (_mail->box->flags & MAILBOX_FLAG_POP3_SESSION) != 0) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* kludge: we want output for POP3 LIST with
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen pop3_fast_size_lookups=yes. use the remote's LIST values
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen regardless of their correctness */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* slow way: get the whole message body */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (mail_get_stream(_mail, &hdr_size, &body_size, &input) < 0)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_assert(mail->data.physical_size != (uoff_t)-1);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic void pop3c_mail_cache_size(struct index_mail *mail)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (i_stream_get_size(mail->data.stream, TRUE, &size) <= 0)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen cache_idx = mail->ibox->cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (mail_cache_field_exists(_mail->transaction->cache_view,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen index_mail_cache_add_idx(mail, cache_idx, &size, sizeof(size));
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* make sure it's not cached twice */
ad004e44be109684521494b5af2ad1da39b8bb27Timo Sirainenpop3c_mail_get_stream(struct mail *_mail, bool get_body,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct message_size *body_size, struct istream **stream_r)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* we've fetched the body */
54533aa265f5c87730022cc7576090bc51370f97Timo Sirainen /* we've fetched the header, but we need the body
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_panic("Unexpected POP3 stream name: %s", name);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen capa = pop3c_client_get_capabilities(mbox->client);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (get_body || (capa & POP3C_CAPABILITY_TOP) == 0) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen cmd = t_strdup_printf("RETR %u\r\n", _mail->seq);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen cmd = t_strdup_printf("TOP %u 0\r\n", _mail->seq);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (pop3c_client_cmd_stream(mbox->client, cmd,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen MAIL_ERROR_TEMP : MAIL_ERROR_EXPUNGED, error);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_stream_set_name(mail->data.stream, t_strcut(cmd, '\r'));
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen return index_mail_init_stream(mail, hdr_size, body_size, stream_r);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenpop3c_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char **value_r)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;