pop3c-mail.c revision 0d6ae58916bee3452c91d9d81be72227761ec33d
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2011-2012 Dovecot authors, see the included COPYING file */
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainenstatic int pop3c_mail_get_received_date(struct mail *_mail, time_t *date_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_storage_set_error(_mail->box->storage, MAIL_ERROR_NOTPOSSIBLE,
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen "POP3 has no received date");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic int pop3c_mail_get_save_date(struct mail *_mail, time_t *date_r)
40ef82c46f6652412b068ebcdac7c3e74840a284Timo Sirainen mail_storage_set_error(_mail->box->storage, MAIL_ERROR_NOTPOSSIBLE,
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen "POP3 has no save date");
b44faf865da16ac4d18eecd85a55b3fab6b9e63aTimo Sirainenstatic int pop3c_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen /* virtual size is already known. it's the same as our
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen (correct) physical size */
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen if (index_mail_get_physical_size(_mail, size_r) == 0) {
651fc0f1e43fef3e02e0e7b5f498973b05f641d7Timo Sirainen if (_mail->lookup_abort == MAIL_LOOKUP_ABORT_READ_MAIL &&
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen (_mail->box->flags & MAILBOX_FLAG_POP3_SESSION) != 0) {
e188bab0b830136d04a1dd8b55e9afefae20d930Timo Sirainen /* kludge: we want output for POP3 LIST with
fee561b9d9162b130e662914fcebc9dd99b5c320Timo Sirainen pop3_fast_size_lookups=yes. use the remote's LIST values
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen regardless of their correctness */
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen /* slow way: get the whole message body */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (mail_get_stream(_mail, &hdr_size, &body_size, &input) < 0)
e169102fb38ce788b76c2a344bee7d77079dea05Timo Sirainen i_assert(mail->data.physical_size != (uoff_t)-1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void pop3c_mail_cache_size(struct index_mail *mail)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (i_stream_get_size(mail->data.stream, TRUE, &size) <= 0)
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen cache_idx = mail->ibox->cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen if (mail_cache_field_exists(_mail->transaction->cache_view,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen index_mail_cache_add_idx(mail, cache_idx, &size, sizeof(size));
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen /* make sure it's not cached twice */
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainenpop3c_mail_get_stream(struct mail *_mail, bool get_body,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct message_size *body_size, struct istream **stream_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen /* we've fetched the body */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen /* we've fetched the header, but we need the body
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen i_panic("Unexpected POP3 stream name: %s", name);
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen capa = pop3c_client_get_capabilities(mbox->client);
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen if (get_body || (capa & POP3C_CAPABILITY_TOP) == 0) {
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen cmd = t_strdup_printf("RETR %u\r\n", _mail->seq);
838f56174b963779a88083a0d0e85b30d2d846e7Timo Sirainen cmd = t_strdup_printf("TOP %u 0\r\n", _mail->seq);
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen if (pop3c_client_cmd_stream(mbox->client, cmd,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen MAIL_ERROR_TEMP : MAIL_ERROR_EXPUNGED, error);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_stream_set_name(mail->data.stream, t_strcut(cmd, '\r'));
6e07b4251bf6a3cf34019c351a32a65c08392e58Timo Sirainen return index_mail_init_stream(mail, hdr_size, body_size, stream_r);
d143077bd518de129b8d446fb58e003903e50867Timo Sirainenpop3c_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen const char **value_r)
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;