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