~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/lib-storage/index/dbox-common/dbox-mail.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2007-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "istream.h"
165
165
                INDEX_STORAGE_CONTEXT(imail->mail.mail.box);
166
166
        const char *value;
167
167
        string_t *str;
 
168
        uint32_t order;
168
169
 
169
 
        str = str_new(imail->data_pool, 64);
 
170
        str = str_new(imail->mail.data_pool, 64);
170
171
        if (mail_cache_lookup_field(imail->mail.mail.transaction->cache_view,
171
172
                                    str, imail->mail.mail.seq,
172
173
                                    ibox->cache_fields[cache_field].idx) > 0) {
173
 
                *value_r = str_c(str);
 
174
                if (cache_field != MAIL_CACHE_POP3_ORDER)
 
175
                        *value_r = str_c(str);
 
176
                else {
 
177
                        i_assert(str_len(str) == sizeof(order));
 
178
                        memcpy(&order, str_data(str), sizeof(order));
 
179
                        *value_r = order == 0 ? "" : dec2str(order);
 
180
                }
174
181
                return 0;
175
182
        }
176
183
 
179
186
 
180
187
        if (value == NULL)
181
188
                value = "";
182
 
        index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
183
 
                                 value, strlen(value)+1);
 
189
        if (cache_field != MAIL_CACHE_POP3_ORDER) {
 
190
                index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
 
191
                                         value, strlen(value)+1);
 
192
        } else {
 
193
                if (str_to_uint(value, &order) < 0)
 
194
                        order = 0;
 
195
                index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
 
196
                                         &order, sizeof(order));
 
197
        }
184
198
 
185
199
        /* don't return pointer to dbox metadata directly, since it may
186
200
           change unexpectedly */
202
216
        case MAIL_FETCH_UIDL_BACKEND:
203
217
                return dbox_get_cached_metadata(mail, DBOX_METADATA_POP3_UIDL,
204
218
                                                MAIL_CACHE_POP3_UIDL, value_r);
 
219
        case MAIL_FETCH_POP3_ORDER:
 
220
                return dbox_get_cached_metadata(mail, DBOX_METADATA_POP3_ORDER,
 
221
                                                MAIL_CACHE_POP3_ORDER, value_r);
205
222
        case MAIL_FETCH_GUID:
206
223
                return dbox_get_cached_metadata(mail, DBOX_METADATA_GUID,
207
224
                                                MAIL_CACHE_GUID, value_r);
220
237
        struct dbox_file *file = mail->open_file;
221
238
        int ret;
222
239
 
223
 
        if ((ret = dbox_file_seek(file, offset)) <= 0)
 
240
        if ((ret = dbox_file_seek(file, offset)) <= 0) {
 
241
                *stream_r = NULL;
224
242
                return ret;
 
243
        }
225
244
 
226
245
        *stream_r = i_stream_create_limit(file->input, file->cur_physical_size);
227
246
        if (pmail->v.istream_opened != NULL) {
258
277
                        dbox_file_set_corrupted(mail->open_file,
259
278
                                "uid=%u points to broken data at offset="
260
279
                                "%"PRIuUOFF_T, _mail->uid, offset);
 
280
                        if (input != NULL)
 
281
                                i_stream_unref(&input);
261
282
                        return -1;
262
283
                }
263
284
                data->stream = input;