"Fossies" - the Fresh Open Source Software Archive

Member "dovecot-2.3.8/src/lib-storage/index/raw/raw-mail.c" (8 Oct 2019, 3774 Bytes) of package /linux/misc/dovecot-2.3.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "raw-mail.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.3.7.2_vs_2.3.8.

    1 /* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
    2 
    3 #include "lib.h"
    4 #include "istream.h"
    5 #include "index-mail.h"
    6 #include "raw-storage.h"
    7 
    8 #include <fcntl.h>
    9 #include <unistd.h>
   10 #include <sys/stat.h>
   11 
   12 static int raw_mail_stat(struct mail *mail)
   13 {
   14     struct raw_mailbox *mbox = RAW_MAILBOX(mail->box);
   15     const struct stat *st;
   16 
   17     if (mail->lookup_abort >= MAIL_LOOKUP_ABORT_NOT_IN_CACHE) {
   18         mail_set_aborted(mail);
   19         return -1;
   20     }
   21     mail->mail_metadata_accessed = TRUE;
   22 
   23     mail->transaction->stats.fstat_lookup_count++;
   24     if (i_stream_stat(mail->box->input, TRUE, &st) < 0) {
   25         mail_set_critical(mail, "stat(%s) failed: %m",
   26                   i_stream_get_name(mail->box->input));
   27         return -1;
   28     }
   29 
   30     if (mbox->mtime != (time_t)-1)
   31         mbox->mtime = st->st_mtime;
   32     if (mbox->ctime != (time_t)-1)
   33         mbox->ctime = st->st_ctime;
   34     mbox->size = st->st_size;
   35     return 0;
   36 }
   37 
   38 static int raw_mail_get_received_date(struct mail *_mail, time_t *date_r)
   39 {
   40     struct index_mail *mail = INDEX_MAIL(_mail);
   41     struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
   42 
   43     if (mbox->mtime == (time_t)-1) {
   44         if (raw_mail_stat(_mail) < 0)
   45             return -1;
   46     }
   47 
   48     *date_r = mail->data.received_date = mbox->mtime;
   49     return 0;
   50 }
   51 
   52 static int raw_mail_get_save_date(struct mail *_mail, time_t *date_r)
   53 {
   54     struct index_mail *mail = INDEX_MAIL(_mail);
   55     struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
   56 
   57     if (mbox->ctime == (time_t)-1) {
   58         if (raw_mail_stat(_mail) < 0)
   59             return -1;
   60     }
   61 
   62     *date_r = mail->data.save_date = mbox->ctime;
   63     return 0;
   64 }
   65 
   66 static int raw_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
   67 {
   68     struct index_mail *mail = INDEX_MAIL(_mail);
   69     struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
   70 
   71     if (mbox->size == (uoff_t)-1) {
   72         if (raw_mail_stat(_mail) < 0)
   73             return -1;
   74     }
   75 
   76     *size_r = mail->data.physical_size = mbox->size;
   77     return 0;
   78 }
   79 
   80 static int
   81 raw_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
   82             struct message_size *hdr_size,
   83             struct message_size *body_size, struct istream **stream_r)
   84 {
   85     struct index_mail *mail = INDEX_MAIL(_mail);
   86 
   87     if (mail->data.stream == NULL) {
   88         /* we can't just reference mbox->input, because
   89            index_mail_close() expects to be able to free the stream */
   90         mail->data.stream =
   91             i_stream_create_limit(_mail->box->input, (uoff_t)-1);
   92     }
   93 
   94     return index_mail_init_stream(mail, hdr_size, body_size, stream_r);
   95 }
   96 
   97 static int
   98 raw_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
   99              const char **value_r)
  100 {
  101     struct raw_mailbox *mbox = RAW_MAILBOX(_mail->box);
  102 
  103     switch (field) {
  104     case MAIL_FETCH_FROM_ENVELOPE:
  105         *value_r = mbox->envelope_sender != NULL ?
  106             mbox->envelope_sender : "";
  107         return 0;
  108     case MAIL_FETCH_STORAGE_ID:
  109         *value_r = mbox->have_filename ?
  110             mailbox_get_path(_mail->box) : "";
  111         return 0;
  112     default:
  113         return index_mail_get_special(_mail, field, value_r);
  114     }
  115 }
  116 
  117 struct mail_vfuncs raw_mail_vfuncs = {
  118     index_mail_close,
  119     index_mail_free,
  120     index_mail_set_seq,
  121     index_mail_set_uid,
  122     index_mail_set_uid_cache_updates,
  123     index_mail_prefetch,
  124     index_mail_precache,
  125     index_mail_add_temp_wanted_fields,
  126 
  127     index_mail_get_flags,
  128     index_mail_get_keywords,
  129     index_mail_get_keyword_indexes,
  130     index_mail_get_modseq,
  131     index_mail_get_pvt_modseq,
  132     index_mail_get_parts,
  133     index_mail_get_date,
  134     raw_mail_get_received_date,
  135     raw_mail_get_save_date,
  136     index_mail_get_virtual_size,
  137     raw_mail_get_physical_size,
  138     index_mail_get_first_header,
  139     index_mail_get_headers,
  140     index_mail_get_header_stream,
  141     raw_mail_get_stream,
  142     index_mail_get_binary_stream,
  143     raw_mail_get_special,
  144     index_mail_get_backend_mail,
  145     index_mail_update_flags,
  146     index_mail_update_keywords,
  147     index_mail_update_modseq,
  148     index_mail_update_pvt_modseq,
  149     NULL,
  150     index_mail_expunge,
  151     index_mail_set_cache_corrupted,
  152     index_mail_opened,
  153 };