⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hcache.c

📁 mutt-1.5.12 源代码。linux 下邮件接受的工具。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004 Thomas Glanzmann <sithglan@stud.uni-erlangen.de> * Copyright (C) 2004 Tobias Werth <sitowert@stud.uni-erlangen.de> * Copyright (C) 2004 Brian Fundakowski Feldman <green@FreeBSD.org> * *     This program is free software; you can redistribute it and/or modify *     it under the terms of the GNU General Public License as published by *     the Free Software Foundation; either version 2 of the License, or *     (at your option) any later version. * *     This program is distributed in the hope that it will be useful, *     but WITHOUT ANY WARRANTY; without even the implied warranty of *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *     GNU General Public License for more details. * *     You should have received a copy of the GNU General Public License *     along with this program; if not, write to the Free Software *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *//* this comment bumps Id because of the attachment counting patch. */#if HAVE_CONFIG_H#include "config.h"#endif				/* HAVE_CONFIG_H */#if HAVE_QDBM#include <depot.h>#include <cabin.h>#include <villa.h>#elif HAVE_GDBM#include <gdbm.h>#elif HAVE_DB4#include <db.h>#endif#include <errno.h>#include <fcntl.h>#if HAVE_SYS_TIME_H#include <sys/time.h>#endif#include "mutt.h"#include "hcache.h"#ifdef USE_IMAP#include "message.h"#endif#include "mime.h"#include "mx.h"#include "lib.h"#include "md5.h"#if HAVE_QDBMstatic struct header_cache{  VILLA *db;  char *folder;  unsigned int crc;} HEADER_CACHE;#elif HAVE_GDBMstatic struct header_cache{  GDBM_FILE db;  char *folder;  unsigned int crc;} HEADER_CACHE;#elif HAVE_DB4static struct header_cache{  DB_ENV *env;  DB *db;  unsigned int crc;  int fd;  char lockfile[_POSIX_PATH_MAX];} HEADER_CACHE;static void mutt_hcache_dbt_init(DBT * dbt, void *data, size_t len);static void mutt_hcache_dbt_empty_init(DBT * dbt);#endiftypedef union{  struct timeval timeval;  unsigned long uid_validity;} validate;static void *lazy_malloc(size_t siz){  if (0 < siz && siz < 4096)    siz = 4096;  return safe_malloc(siz);}static voidlazy_realloc(void *ptr, size_t siz){  void **p = (void **) ptr;  if (p != NULL && 0 < siz && siz < 4096)    return;  safe_realloc(ptr, siz);}static unsigned char *dump_int(unsigned int i, unsigned char *d, int *off){  lazy_realloc(&d, *off + sizeof (int));  memcpy(d + *off, &i, sizeof (int));  (*off) += sizeof (int);  return d;}static voidrestore_int(unsigned int *i, const unsigned char *d, int *off){  memcpy(i, d + *off, sizeof (int));  (*off) += sizeof (int);}static unsigned char *dump_char(char *c, unsigned char *d, int *off){  unsigned int size;  if (c == NULL)  {    size = 0;    d = dump_int(size, d, off);    return d;  }  size = mutt_strlen(c) + 1;  d = dump_int(size, d, off);  lazy_realloc(&d, *off + size);  memcpy(d + *off, c, size);  *off += size;  return d;}static unsigned char *dump_char_size(char *c, unsigned char *d, int *off, ssize_t size){  if (c == NULL)  {    size = 0;    d = dump_int(size, d, off);    return d;  }  d = dump_int(size, d, off);  lazy_realloc(&d, *off + size);  memcpy(d + *off, c, size);  *off += size;  return d;}static voidrestore_char(char **c, const unsigned char *d, int *off){  unsigned int size;  restore_int(&size, d, off);  if (size == 0)  {    *c = NULL;    return;  }  *c = safe_malloc(size);  memcpy(*c, d + *off, size);  *off += size;}static unsigned char *dump_address(ADDRESS * a, unsigned char *d, int *off){  unsigned int counter = 0;  unsigned int start_off = *off;  d = dump_int(0xdeadbeef, d, off);  while (a)  {#ifdef EXACT_ADDRESS    d = dump_char(a->val, d, off);#endif    d = dump_char(a->personal, d, off);    d = dump_char(a->mailbox, d, off);    d = dump_int(a->group, d, off);    a = a->next;    counter++;  }  memcpy(d + start_off, &counter, sizeof (int));  return d;}static voidrestore_address(ADDRESS ** a, const unsigned char *d, int *off){  unsigned int counter;  restore_int(&counter, d, off);  while (counter)  {    *a = safe_malloc(sizeof (ADDRESS));#ifdef EXACT_ADDRESS    restore_char(&(*a)->val, d, off);#endif    restore_char(&(*a)->personal, d, off);    restore_char(&(*a)->mailbox, d, off);    restore_int((unsigned int *) &(*a)->group, d, off);    a = &(*a)->next;    counter--;  }  *a = NULL;}static unsigned char *dump_list(LIST * l, unsigned char *d, int *off){  unsigned int counter = 0;  unsigned int start_off = *off;  d = dump_int(0xdeadbeef, d, off);  while (l)  {    d = dump_char(l->data, d, off);    l = l->next;    counter++;  }  memcpy(d + start_off, &counter, sizeof (int));  return d;}static voidrestore_list(LIST ** l, const unsigned char *d, int *off){  unsigned int counter;  restore_int(&counter, d, off);  while (counter)  {    *l = safe_malloc(sizeof (LIST));    restore_char(&(*l)->data, d, off);    l = &(*l)->next;    counter--;  }  *l = NULL;}static unsigned char *dump_buffer(BUFFER * b, unsigned char *d, int *off){  if (!b)  {    d = dump_int(0, d, off);    return d;  }  else    d = dump_int(1, d, off);  d = dump_char_size(b->data, d, off, b->dsize + 1);  d = dump_int(b->dptr - b->data, d, off);  d = dump_int(b->dsize, d, off);  d = dump_int(b->destroy, d, off);  return d;}static voidrestore_buffer(BUFFER ** b, const unsigned char *d, int *off){  unsigned int used;  unsigned int offset;  restore_int(&used, d, off);  if (!used)  {    return;  }  *b = safe_malloc(sizeof (BUFFER));  restore_char(&(*b)->data, d, off);  restore_int(&offset, d, off);  (*b)->dptr = (*b)->data + offset;  restore_int((unsigned int *) &(*b)->dsize, d, off);  restore_int((unsigned int *) &(*b)->destroy, d, off);}static unsigned char *dump_parameter(PARAMETER * p, unsigned char *d, int *off){  unsigned int counter = 0;  unsigned int start_off = *off;  d = dump_int(0xdeadbeef, d, off);  while (p)  {    d = dump_char(p->attribute, d, off);    d = dump_char(p->value, d, off);    p = p->next;    counter++;  }  memcpy(d + start_off, &counter, sizeof (int));  return d;}static voidrestore_parameter(PARAMETER ** p, const unsigned char *d, int *off){  unsigned int counter;  restore_int(&counter, d, off);  while (counter)  {    *p = safe_malloc(sizeof (PARAMETER));    restore_char(&(*p)->attribute, d, off);    restore_char(&(*p)->value, d, off);    p = &(*p)->next;    counter--;  }  *p = NULL;}static unsigned char *dump_body(BODY * c, unsigned char *d, int *off){  lazy_realloc(&d, *off + sizeof (BODY));  memcpy(d + *off, c, sizeof (BODY));  *off += sizeof (BODY);  d = dump_char(c->xtype, d, off);  d = dump_char(c->subtype, d, off);  d = dump_parameter(c->parameter, d, off);  d = dump_char(c->description, d, off);  d = dump_char(c->form_name, d, off);  d = dump_char(c->filename, d, off);  d = dump_char(c->d_filename, d, off);  return d;}static voidrestore_body(BODY * c, const unsigned char *d, int *off){  memcpy(c, d + *off, sizeof (BODY));  *off += sizeof (BODY);  restore_char(&c->xtype, d, off);  restore_char(&c->subtype, d, off);  restore_parameter(&c->parameter, d, off);  restore_char(&c->description, d, off);  restore_char(&c->form_name, d, off);  restore_char(&c->filename, d, off);  restore_char(&c->d_filename, d, off);}static unsigned char *dump_envelope(ENVELOPE * e, unsigned char *d, int *off){  d = dump_address(e->return_path, d, off);  d = dump_address(e->from, d, off);  d = dump_address(e->to, d, off);  d = dump_address(e->cc, d, off);  d = dump_address(e->bcc, d, off);  d = dump_address(e->sender, d, off);  d = dump_address(e->reply_to, d, off);  d = dump_address(e->mail_followup_to, d, off);  d = dump_char(e->list_post, d, off);  d = dump_char(e->subject, d, off);  if (e->real_subj)    d = dump_int(e->real_subj - e->subject, d, off);  else    d = dump_int(-1, d, off);  d = dump_char(e->message_id, d, off);  d = dump_char(e->supersedes, d, off);  d = dump_char(e->date, d, off);  d = dump_char(e->x_label, d, off);  d = dump_buffer(e->spam, d, off);  d = dump_list(e->references, d, off);  d = dump_list(e->in_reply_to, d, off);  d = dump_list(e->userhdrs, d, off);  return d;}static voidrestore_envelope(ENVELOPE * e, const unsigned char *d, int *off){  int real_subj_off;  restore_address(&e->return_path, d, off);  restore_address(&e->from, d, off);  restore_address(&e->to, d, off);  restore_address(&e->cc, d, off);  restore_address(&e->bcc, d, off);  restore_address(&e->sender, d, off);  restore_address(&e->reply_to, d, off);  restore_address(&e->mail_followup_to, d, off);  restore_char(&e->list_post, d, off);  restore_char(&e->subject, d, off);  restore_int((unsigned int *) (&real_subj_off), d, off);  if (0 <= real_subj_off)    e->real_subj = e->subject + real_subj_off;  else    e->real_subj = NULL;  restore_char(&e->message_id, d, off);  restore_char(&e->supersedes, d, off);  restore_char(&e->date, d, off);  restore_char(&e->x_label, d, off);  restore_buffer(&e->spam, d, off);  restore_list(&e->references, d, off);  restore_list(&e->in_reply_to, d, off);  restore_list(&e->userhdrs, d, off);}static unsigned intcrc32(unsigned int crc, unsigned char const *p, size_t len){  int i;  while (len--)  {    crc ^= *p++;    for (i = 0; i < 8; i++)      crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);  }  return crc;}static intgenerate_crc32(){  int crc = 0;  SPAM_LIST *sp = SpamList;  RX_LIST *rx = NoSpamList;  crc = crc32(crc, (unsigned char const *) "$Id: hcache.c,v 3.17 2006/05/18 18:35:10 brendan Exp $", mutt_strlen("$Id: hcache.c,v 3.17 2006/05/18 18:35:10 brendan Exp $"));#if HAVE_LANGINFO_CODESET  crc = crc32(crc, (unsigned char const *) Charset, mutt_strlen(Charset));  crc = crc32(crc, (unsigned char const *) "HAVE_LANGINFO_CODESET",	mutt_strlen("HAVE_LANGINFO_CODESET"));#endif#if EXACT_ADDRESS  crc = crc32(crc, (unsigned char const *) "EXACT_ADDRESS",	mutt_strlen("EXACT_ADDRESS"));#endif#ifdef USE_POP  crc = crc32(crc, (unsigned char const *) "USE_POP", mutt_strlen("USE_POP"));#endif#ifdef MIXMASTER  crc = crc32(crc, (unsigned char const *) "MIXMASTER",        mutt_strlen("MIXMASTER"));#endif#ifdef USE_IMAP  crc = crc32(crc, (unsigned char const *) "USE_IMAP", mutt_strlen("USE_IMAP"));  crc = crc32(crc, (unsigned char const *) ImapHeaders,        mutt_strlen(ImapHeaders));#endif  while (sp)  {    crc = crc32(crc, (unsigned char const *) sp->rx->pattern,	  mutt_strlen(sp->rx->pattern));    sp = sp->next;  }  crc = crc32(crc, (unsigned char const *) "SPAM_SEPERATOR",	mutt_strlen("SPAM_SEPERATOR"));  while (rx)  {    crc = crc32(crc, (unsigned char const *) rx->rx->pattern,	  mutt_strlen(rx->rx->pattern));    rx = rx->next;  }  return crc;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -