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

📄 init.c

📁 mutt-1.5.12 源代码。linux 下邮件接受的工具。
💻 C
📖 第 1 页 / 共 5 页
字号:
  LIST *p, *last = NULL;  if (mutt_strcmp ("*", str) == 0)    mutt_free_list (l);    /* ``unCMD *'' means delete all current entries */  else  {    p = *l;    last = NULL;    while (p)    {      if (ascii_strcasecmp (str, p->data) == 0)      {	FREE (&p->data);	if (last)	  last->next = p->next;	else	  (*l) = p->next;	FREE (&p);      }      else      {	last = p;	p = p->next;      }    }  }}static int remove_from_rx_list (RX_LIST **l, const char *str){  RX_LIST *p, *last = NULL;  int rv = -1;  if (mutt_strcmp ("*", str) == 0)  {    mutt_free_rx_list (l);    /* ``unCMD *'' means delete all current entries */    rv = 0;  }  else  {    p = *l;    last = NULL;    while (p)    {      if (ascii_strcasecmp (str, p->rx->pattern) == 0)      {	mutt_free_regexp (&p->rx);	if (last)	  last->next = p->next;	else	  (*l) = p->next;	FREE (&p);	rv = 0;      }      else      {	last = p;	p = p->next;      }    }  }  return (rv);}static int parse_unignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  do  {    mutt_extract_token (buf, s, 0);    /* don't add "*" to the unignore list */    if (strcmp (buf->data, "*"))       add_to_list (&UnIgnore, buf->data);    remove_from_list (&Ignore, buf->data);  }  while (MoreArgs (s));  return 0;}static int parse_ignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  do  {    mutt_extract_token (buf, s, 0);    remove_from_list (&UnIgnore, buf->data);    add_to_list (&Ignore, buf->data);  }  while (MoreArgs (s));  return 0;}static int parse_list (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  do  {    mutt_extract_token (buf, s, 0);    add_to_list ((LIST **) data, buf->data);  }  while (MoreArgs (s));  return 0;}static void _alternates_clean (void){  int i;  if (Context && Context->msgcount)   {    for (i = 0; i < Context->msgcount; i++)      Context->hdrs[i]->recip_valid = 0;  }}static int parse_alternates (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  group_context_t *gc = NULL;    _alternates_clean();  do  {    mutt_extract_token (buf, s, 0);    if (parse_group_context (&gc, buf, s, data, err) == -1)      goto bail;    remove_from_rx_list (&UnAlternates, buf->data);    if (mutt_add_to_rx_list (&Alternates, buf->data, REG_ICASE, err) != 0)      goto bail;    if (mutt_group_context_add_rx (gc, buf->data, REG_ICASE, err) != 0)      goto bail;  }  while (MoreArgs (s));    mutt_group_context_destroy (&gc);  return 0;   bail:  mutt_group_context_destroy (&gc);  return -1;}static int parse_unalternates (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  _alternates_clean();  do  {    mutt_extract_token (buf, s, 0);    remove_from_rx_list (&Alternates, buf->data);    if (mutt_strcmp (buf->data, "*") &&	mutt_add_to_rx_list (&UnAlternates, buf->data, REG_ICASE, err) != 0)      return -1;  }  while (MoreArgs (s));  return 0;}static int parse_spam_list (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  BUFFER templ;  memset(&templ, 0, sizeof(templ));  /* Insist on at least one parameter */  if (!MoreArgs(s))  {    if (data == M_SPAM)      strfcpy(err->data, _("spam: no matching pattern"), err->dsize);    else      strfcpy(err->data, _("nospam: no matching pattern"), err->dsize);    return -1;  }  /* Extract the first token, a regexp */  mutt_extract_token (buf, s, 0);  /* data should be either M_SPAM or M_NOSPAM. M_SPAM is for spam commands. */  if (data == M_SPAM)  {    /* If there's a second parameter, it's a template for the spam tag. */    if (MoreArgs(s))    {      mutt_extract_token (&templ, s, 0);      /* Add to the spam list. */      if (add_to_spam_list (&SpamList, buf->data, templ.data, err) != 0) {	  FREE(&templ.data);          return -1;      }      FREE(&templ.data);    }    /* If not, try to remove from the nospam list. */    else    {      remove_from_rx_list(&NoSpamList, buf->data);    }    return 0;  }  /* M_NOSPAM is for nospam commands. */  else if (data == M_NOSPAM)  {    /* nospam only ever has one parameter. */    /* "*" is a special case. */    if (!mutt_strcmp(buf->data, "*"))    {      mutt_free_spam_list (&SpamList);      mutt_free_rx_list (&NoSpamList);      return 0;    }    /* If it's on the spam list, just remove it. */    if (remove_from_spam_list(&SpamList, buf->data) != 0)      return 0;    /* Otherwise, add it to the nospam list. */    if (mutt_add_to_rx_list (&NoSpamList, buf->data, REG_ICASE, err) != 0)      return -1;    return 0;  }  /* This should not happen. */  strfcpy(err->data, "This is no good at all.", err->dsize);  return -1;}static int parse_unlist (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  do  {    mutt_extract_token (buf, s, 0);    /*     * Check for deletion of entire list     */    if (mutt_strcmp (buf->data, "*") == 0)    {      mutt_free_list ((LIST **) data);      break;    }    remove_from_list ((LIST **) data, buf->data);  }  while (MoreArgs (s));  return 0;}static int parse_lists (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  group_context_t *gc = NULL;  do  {    mutt_extract_token (buf, s, 0);        if (parse_group_context (&gc, buf, s, data, err) == -1)      goto bail;        remove_from_rx_list (&UnMailLists, buf->data);        if (mutt_add_to_rx_list (&MailLists, buf->data, REG_ICASE, err) != 0)      goto bail;        if (mutt_group_context_add_rx (gc, buf->data, REG_ICASE, err) != 0)      goto bail;  }  while (MoreArgs (s));  mutt_group_context_destroy (&gc);  return 0;   bail:  mutt_group_context_destroy (&gc);  return -1;}typedef enum group_state_t {  NONE, RX, ADDR} group_state_t;static int parse_group (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  group_context_t *gc = NULL;  group_state_t state = NONE;  ADDRESS *addr = NULL;  char *estr = NULL;    do   {    mutt_extract_token (buf, s, 0);    if (parse_group_context (&gc, buf, s, data, err) == -1)      goto bail;        if (!mutt_strcasecmp (buf->data, "-rx"))      state = RX;    else if (!mutt_strcasecmp (buf->data, "-addr"))      state = ADDR;    else     {      switch (state)       {	case NONE:	  strfcpy (err->data, _("Missing -rx or -addr."), err->dsize);	  goto bail;		case RX:	  if (mutt_group_context_add_rx (gc, buf->data, REG_ICASE, err) != 0)	    goto bail;	  break;		case ADDR:	  if ((addr = mutt_parse_adrlist (NULL, buf->data)) == NULL)	    goto bail;	  if (mutt_addrlist_to_idna (addr, &estr)) 	  {	    snprintf (err->data, err->dsize, _("Warning: Bad IDN '%s'.\n"),		      estr);	    goto bail;	  }	  mutt_group_context_add_adrlist (gc, addr);	  rfc822_free_address (&addr);	  break;      }    }  } while (MoreArgs (s));  mutt_group_context_destroy (&gc);  return 0;  bail:  mutt_group_context_destroy (&gc);  return -1;}static int parse_ungroup (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  strfcpy (err->data, "not implemented", err->dsize);  return -1;}/* always wise to do what someone else did before */static void _attachments_clean (void){  int i;  if (Context && Context->msgcount)   {    for (i = 0; i < Context->msgcount; i++)      Context->hdrs[i]->attach_valid = 0;  }}static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *err){  ATTACH_MATCH *a;  LIST *listp, *lastp;  char *p;  char *tmpminor;  int len;  /* Find the last item in the list that data points to. */  lastp = NULL;  dprint(5, (debugfile, "parse_attach_list: ldata = %08x, *ldata = %08x\n",	      (unsigned int)ldata, (unsigned int)*ldata));  for (listp = *ldata; listp; listp = listp->next)  {    a = (ATTACH_MATCH *)listp->data;    dprint(5, (debugfile, "parse_attach_list: skipping %s/%s\n",		a->major, a->minor));    lastp = listp;  }  do  {    mutt_extract_token (buf, s, 0);    if (!buf->data || *buf->data == '\0')      continue;       a = safe_malloc(sizeof(ATTACH_MATCH));    /* some cheap hacks that I expect to remove */    if (!ascii_strcasecmp(buf->data, "any"))      a->major = safe_strdup("*/.*");    else if (!ascii_strcasecmp(buf->data, "none"))      a->major = safe_strdup("cheap_hack/this_should_never_match");    else      a->major = safe_strdup(buf->data);    if ((p = strchr(a->major, '/')))    {      *p = '\0';      ++p;      a->minor = p;    }    else    {      a->minor = "unknown";    }    len = strlen(a->minor);    tmpminor = safe_malloc(len+3);    strcpy(&tmpminor[1], a->minor); /* __STRCPY_CHECKED__ */    tmpminor[0] = '^';    tmpminor[len+1] = '$';    tmpminor[len+2] = '\0';    a->major_int = mutt_check_mime_type(a->major);    regcomp(&a->minor_rx, tmpminor, REG_ICASE|REG_EXTENDED);    FREE(&tmpminor);    dprint(5, (debugfile, "parse_attach_list: added %s/%s [%d]\n",		a->major, a->minor, a->major_int));    listp = safe_malloc(sizeof(LIST));    listp->data = (char *)a;    listp->next = NULL;    if (lastp)    {      lastp->next = listp;    }    else    {      *ldata = listp;    }    lastp = listp;  }  while (MoreArgs (s));     _attachments_clean();  return 0;}static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *err){  ATTACH_MATCH *a;  LIST *lp, *lastp, *newlp;  char *tmp;  int major;  char *minor;  do  {    mutt_extract_token (buf, s, 0);    if (!ascii_strcasecmp(buf->data, "any"))      tmp = safe_strdup("*/.*");    else if (!ascii_strcasecmp(buf->data, "none"))      tmp = safe_strdup("cheap_hack/this_should_never_match");    else      tmp = safe_strdup(buf->data);    if ((minor = strchr(tmp, '/')))    {      *minor = '\0';      ++minor;    }    else    {      minor = "unknown";    }    major = mutt_check_mime_type(tmp);    /* We must do our own walk here because remove_from_list() will only     * remove the LIST->data, not anything pointed to by the LIST->data. */    lastp = NULL;    for(lp = *ldata; lp; )    {      a = (ATTACH_MATCH *)lp->data;      dprint(5, (debugfile, "parse_unattach_list: check %s/%s [%d] : %s/%s [%d]\n",		  a->major, a->minor, a->major_int, tmp, minor, major));      if (a->major_int == major && !mutt_strcasecmp(minor, a->minor))      {	dprint(5, (debugfile, "parse_unattach_list: removed %s/%s [%d]\n",		    a->major, a->minor, a->major_int));	regfree(&a->minor_rx);	FREE(&a->major);	/* Relink backward */	if (lastp)	  lastp->next = lp->next;	else	  *ldata = lp->next;        newlp = lp->next;        FREE(&lp->data);	/* same as a */        FREE(&lp);        lp = newlp;        continue;      }      lastp = lp;      lp = lp->next;    }  }  while (MoreArgs (s));     FREE(&tmp);  _attachments_clean();  return 0;}static int print_attach_list (LIST *lp, char op, char *name){  while (lp) {    printf("attachments %c%s %s/%s\n", op, name,           ((ATTACH_MATCH *)lp->data)->major,           ((ATTACH_MATCH *)lp->data)->minor);    lp = lp->next;  }  return 0;}static int parse_attachments (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err){  char op, *category;  LIST **listp;  mutt_extract_token(buf, s, 0);  if (!buf->data || *buf->data == '\0') {    strfcpy(err->data, _("attachments: no disposition"), err->dsize);    return -1;  }  category = buf->data;  op = *category++;  if (op == '?') {    mutt_endwin (NULL);    fflush (stdout);    printf("\nCurrent attachments settings:\n\n");    print_attach_list(AttachAllow,   '+', "A");    print_attach_list(AttachExclude, '-', "A");    print_attach_list(InlineAllow,   '+', "I");    print_attach_list(InlineExclude, '-', "I");    set_option (OPTFORCEREDRAWINDEX);    set_option (OPTFORCEREDRAWPAGER);    mutt_any_key_to_continue (NULL);    return 0;  }  if (op != '+' && op != '-') {    op = '+';    category--;  }  if (!ascii_strncasecmp(category, "attachment", strlen(category))) {    if (op == '+')

⌨️ 快捷键说明

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