~ubuntu-branches/ubuntu/precise/mutt/precise

« back to all changes in this revision

Viewing changes to init.c

  • Committer: Package Import Robot
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2010-12-17 14:28:28 UTC
  • mfrom: (16.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20101217142828-ve8yy0xf1zomtnx9
Tags: 1.5.21-1ubuntu1
* Merge with Debian experimental (LP: #691512), remaining changes:
  + debian/control, debian/patches/debian-specific/build_doc_adjustments.diff:
    Use w3m (main) instead of elinks (universe) for generating documentation.
  + Drop libtokyocabinet-dev (universe) from Build-Depends, use always
    libgdbm-dev and also use gdbm for the header cache backend. (lp: #607448)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "charset.h"
32
32
#include "mutt_crypt.h"
33
33
#include "mutt_idna.h"
 
34
#include "group.h"
34
35
 
35
36
#if defined(USE_SSL)
36
37
#include "mutt_ssl.h"
49
50
#include <sys/utsname.h>
50
51
#include <errno.h>
51
52
#include <sys/wait.h>
 
53
#include <sys/time.h>
52
54
 
53
55
#define CHECK_PAGER \
54
56
  if ((CurrentMenu == MENU_PAGER) && (idx >= 0) &&      \
599
601
  }
600
602
}
601
603
 
602
 
static int remove_from_rx_list (RX_LIST **l, const char *str)
603
 
{
604
 
  RX_LIST *p, *last = NULL;
605
 
  int rv = -1;
606
 
 
607
 
  if (mutt_strcmp ("*", str) == 0)
608
 
  {
609
 
    mutt_free_rx_list (l);    /* ``unCMD *'' means delete all current entries */
610
 
    rv = 0;
611
 
  }
612
 
  else
613
 
  {
614
 
    p = *l;
615
 
    last = NULL;
616
 
    while (p)
617
 
    {
618
 
      if (ascii_strcasecmp (str, p->rx->pattern) == 0)
619
 
      {
620
 
        mutt_free_regexp (&p->rx);
621
 
        if (last)
622
 
          last->next = p->next;
623
 
        else
624
 
          (*l) = p->next;
625
 
        FREE (&p);
626
 
        rv = 0;
627
 
      }
628
 
      else
629
 
      {
630
 
        last = p;
631
 
        p = p->next;
632
 
      }
633
 
    }
634
 
  }
635
 
  return (rv);
636
 
}
637
 
 
638
604
static int parse_unignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
639
605
{
640
606
  do
700
666
    if (parse_group_context (&gc, buf, s, data, err) == -1)
701
667
      goto bail;
702
668
 
703
 
    remove_from_rx_list (&UnAlternates, buf->data);
 
669
    mutt_remove_from_rx_list (&UnAlternates, buf->data);
704
670
 
705
671
    if (mutt_add_to_rx_list (&Alternates, buf->data, REG_ICASE, err) != 0)
706
672
      goto bail;
724
690
  do
725
691
  {
726
692
    mutt_extract_token (buf, s, 0);
727
 
    remove_from_rx_list (&Alternates, buf->data);
 
693
    mutt_remove_from_rx_list (&Alternates, buf->data);
728
694
 
729
695
    if (mutt_strcmp (buf->data, "*") &&
730
696
        mutt_add_to_rx_list (&UnAlternates, buf->data, REG_ICASE, err) != 0)
774
740
    /* If not, try to remove from the nospam list. */
775
741
    else
776
742
    {
777
 
      remove_from_rx_list(&NoSpamList, buf->data);
 
743
      mutt_remove_from_rx_list(&NoSpamList, buf->data);
778
744
    }
779
745
 
780
746
    return 0;
841
807
    if (parse_group_context (&gc, buf, s, data, err) == -1)
842
808
      goto bail;
843
809
    
844
 
    remove_from_rx_list (&UnMailLists, buf->data);
 
810
    mutt_remove_from_rx_list (&UnMailLists, buf->data);
845
811
    
846
812
    if (mutt_add_to_rx_list (&MailLists, buf->data, REG_ICASE, err) != 0)
847
813
      goto bail;
869
835
  group_state_t state = NONE;
870
836
  ADDRESS *addr = NULL;
871
837
  char *estr = NULL;
872
 
  
873
 
  do 
 
838
 
 
839
  do
874
840
  {
875
841
    mutt_extract_token (buf, s, 0);
876
842
    if (parse_group_context (&gc, buf, s, data, err) == -1)
877
843
      goto bail;
878
 
    
 
844
 
 
845
    if (data == M_UNGROUP && !mutt_strcasecmp (buf->data, "*"))
 
846
    {
 
847
      if (mutt_group_context_clear (&gc) < 0)
 
848
        goto bail;
 
849
      goto out;
 
850
    }
 
851
 
879
852
    if (!mutt_strcasecmp (buf->data, "-rx"))
880
853
      state = RX;
881
854
    else if (!mutt_strcasecmp (buf->data, "-addr"))
882
855
      state = ADDR;
883
 
    else 
 
856
    else
884
857
    {
885
 
      switch (state) 
 
858
      switch (state)
886
859
      {
887
860
        case NONE:
888
 
          strfcpy (err->data, _("Missing -rx or -addr."), err->dsize);
 
861
          snprintf (err->data, err->dsize, _("%sgroup: missing -rx or -addr."),
 
862
                   data == M_UNGROUP ? "un" : "");
889
863
          goto bail;
890
 
        
 
864
 
891
865
        case RX:
892
 
          if (mutt_group_context_add_rx (gc, buf->data, REG_ICASE, err) != 0)
 
866
          if (data == M_GROUP &&
 
867
              mutt_group_context_add_rx (gc, buf->data, REG_ICASE, err) != 0)
 
868
            goto bail;
 
869
          else if (data == M_UNGROUP &&
 
870
                   mutt_group_context_remove_rx (gc, buf->data) < 0)
893
871
            goto bail;
894
872
          break;
895
 
        
 
873
 
896
874
        case ADDR:
897
875
          if ((addr = mutt_parse_adrlist (NULL, buf->data)) == NULL)
898
876
            goto bail;
899
 
          if (mutt_addrlist_to_idna (addr, &estr)) 
900
 
          {
901
 
            snprintf (err->data, err->dsize, _("Warning: Bad IDN '%s'.\n"),
902
 
                      estr);
 
877
          if (mutt_addrlist_to_idna (addr, &estr))
 
878
          { 
 
879
            snprintf (err->data, err->dsize, _("%sgroup: warning: bad IDN '%s'.\n"),
 
880
                      data == 1 ? "un" : "", estr);
903
881
            goto bail;
904
882
          }
905
 
          mutt_group_context_add_adrlist (gc, addr);
 
883
          if (data == M_GROUP)
 
884
            mutt_group_context_add_adrlist (gc, addr);
 
885
          else if (data == M_UNGROUP)
 
886
            mutt_group_context_remove_adrlist (gc, addr);
906
887
          rfc822_free_address (&addr);
907
888
          break;
908
889
      }
909
890
    }
910
891
  } while (MoreArgs (s));
911
892
 
 
893
out:
912
894
  mutt_group_context_destroy (&gc);
913
895
  return 0;
914
896
 
915
 
  bail:
 
897
bail:
916
898
  mutt_group_context_destroy (&gc);
917
899
  return -1;
918
900
}
919
901
 
920
 
static int parse_ungroup (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
921
 
{
922
 
  strfcpy (err->data, "not implemented", err->dsize);
923
 
  return -1;
924
 
}
925
 
 
926
902
/* always wise to do what someone else did before */
927
903
static void _attachments_clean (void)
928
904
{
941
917
  char *p;
942
918
  char *tmpminor;
943
919
  int len;
 
920
  int ret;
944
921
 
945
922
  /* Find the last item in the list that data points to. */
946
923
  lastp = NULL;
990
967
    tmpminor[len+2] = '\0';
991
968
 
992
969
    a->major_int = mutt_check_mime_type(a->major);
993
 
    regcomp(&a->minor_rx, tmpminor, REG_ICASE|REG_EXTENDED);
 
970
    ret = REGCOMP(&a->minor_rx, tmpminor, REG_ICASE);
994
971
 
995
972
    FREE(&tmpminor);
996
973
 
 
974
    if (ret)
 
975
    {
 
976
      regerror(ret, &a->minor_rx, err->data, err->dsize);
 
977
      FREE(&a->major);
 
978
      FREE(&a);
 
979
      return -1;
 
980
    }
 
981
 
997
982
    dprint(5, (debugfile, "parse_attach_list: added %s/%s [%d]\n",
998
983
                a->major, a->minor, a->major_int));
999
984
 
1193
1178
  do
1194
1179
  {
1195
1180
    mutt_extract_token (buf, s, 0);
1196
 
    remove_from_rx_list (&SubscribedLists, buf->data);
1197
 
    remove_from_rx_list (&MailLists, buf->data);
 
1181
    mutt_remove_from_rx_list (&SubscribedLists, buf->data);
 
1182
    mutt_remove_from_rx_list (&MailLists, buf->data);
1198
1183
    
1199
1184
    if (mutt_strcmp (buf->data, "*") && 
1200
1185
        mutt_add_to_rx_list (&UnMailLists, buf->data, REG_ICASE, err) != 0)
1216
1201
    if (parse_group_context (&gc, buf, s, data, err) == -1)
1217
1202
      goto bail;
1218
1203
    
1219
 
    remove_from_rx_list (&UnMailLists, buf->data);
1220
 
    remove_from_rx_list (&UnSubscribedLists, buf->data);
 
1204
    mutt_remove_from_rx_list (&UnMailLists, buf->data);
 
1205
    mutt_remove_from_rx_list (&UnSubscribedLists, buf->data);
1221
1206
 
1222
1207
    if (mutt_add_to_rx_list (&MailLists, buf->data, REG_ICASE, err) != 0)
1223
1208
      goto bail;
1241
1226
  do
1242
1227
  {
1243
1228
    mutt_extract_token (buf, s, 0);
1244
 
    remove_from_rx_list (&SubscribedLists, buf->data);
 
1229
    mutt_remove_from_rx_list (&SubscribedLists, buf->data);
1245
1230
    
1246
1231
    if (mutt_strcmp (buf->data, "*") &&
1247
1232
        mutt_add_to_rx_list (&UnSubscribedLists, buf->data, REG_ICASE, err) != 0)
1546
1531
  switch (p->type & DT_MASK)
1547
1532
  {
1548
1533
    case DT_STR:
1549
 
      if (p->init)
1550
 
        mutt_str_replace ((char **) p->data, (char *) p->init); 
 
1534
      mutt_str_replace ((char **) p->data, (char *) p->init); 
1551
1535
      break;
1552
1536
    case DT_PATH:
 
1537
      FREE((char **) p->data);          /* __FREE_CHECKED__ */
1553
1538
      if (p->init)
1554
1539
      {
1555
1540
        char path[_POSIX_PATH_MAX];
1556
 
 
1557
1541
        strfcpy (path, (char *) p->init, sizeof (path));
1558
1542
        mutt_expand_path (path, sizeof (path));
1559
 
        mutt_str_replace ((char **) p->data, path);
 
1543
        *((char **) p->data) = safe_strdup (path);
1560
1544
      }
1561
1545
      break;
1562
1546
    case DT_ADDR:
 
1547
      rfc822_free_address ((ADDRESS **) p->data);
1563
1548
      if (p->init)
1564
 
      {
1565
 
        rfc822_free_address ((ADDRESS **) p->data);
1566
1549
        *((ADDRESS **) p->data) = rfc822_parse_adrlist (NULL, (char *) p->init);
1567
 
      }
1568
1550
      break;
1569
1551
    case DT_BOOL:
1570
1552
      if (p->init)
1610
1592
            fprintf (stderr, _("mutt_restore_default(%s): error in regexp: %s\n"),
1611
1593
                     p->option, pp->pattern);
1612
1594
            FREE (&pp->pattern);
1613
 
            regfree (pp->rx);
1614
1595
            FREE (&pp->rx);
1615
1596
          }
1616
1597
        }
1920
1901
        }
1921
1902
        else if (DTYPE (MuttVars[idx].type) == DT_STR)
1922
1903
        {
1923
 
          if (strstr (MuttVars[idx].option, "charset") &&
1924
 
              check_charset (&MuttVars[idx], tmp->data) < 0)
 
1904
          if ((strstr (MuttVars[idx].option, "charset") &&
 
1905
               check_charset (&MuttVars[idx], tmp->data) < 0) |
 
1906
              /* $charset can't be empty, others can */
 
1907
              (strcmp(MuttVars[idx].option, "charset") == 0 && ! *tmp->data))
1925
1908
          {
1926
1909
            snprintf (err->data, err->dsize, _("Invalid value for option %s: \"%s\""),
1927
1910
                      MuttVars[idx].option, tmp->data);
1988
1971
        if ((e = REGCOMP (rx, p, flags)) != 0)
1989
1972
        {
1990
1973
          regerror (e, rx, err->data, err->dsize);
1991
 
          regfree (rx);
1992
1974
          FREE (&rx);
1993
1975
          break;
1994
1976
        }
2846
2828
  {
2847
2829
    t = time (0);
2848
2830
    setbuf (debugfile, NULL); /* don't buffer the debugging output! */
2849
 
    fprintf (debugfile, "Mutt %s started at %s.\nDebugging at level %d.\n\n",
2850
 
             MUTT_VERSION, asctime (localtime (&t)), debuglevel);
 
2831
    dprint(1,(debugfile,"Mutt/%s (%s) debugging at level %d\n",
 
2832
              MUTT_VERSION, ReleaseDate, debuglevel));
2851
2833
  }
2852
2834
}
2853
2835
#endif
2874
2856
  return 0;
2875
2857
}
2876
2858
 
 
2859
static void mutt_srandom (void)
 
2860
{
 
2861
  struct timeval tv;
 
2862
  unsigned seed;
 
2863
 
 
2864
  gettimeofday(&tv, NULL);
 
2865
  /* POSIX.1-2008 states that seed is 'unsigned' without specifying its width.
 
2866
   * Use as many of the lower order bits from the current time of day as the seed.
 
2867
   * If the upper bound is truncated, that is fine.
 
2868
   *
 
2869
   * tv_sec is integral of type integer or float.  Cast to 'long long' before
 
2870
   * bitshift in case it is a float.
 
2871
   */
 
2872
  seed = ((LONGLONG) tv.tv_sec << 20) | tv.tv_usec;
 
2873
  srandom(seed);
 
2874
}
 
2875
 
2877
2876
void mutt_init (int skip_sys_rc, LIST *commands)
2878
2877
{
2879
2878
  struct passwd *pw;
2890
2889
  ReverseAlias = hash_create (1031, 1);
2891
2890
  
2892
2891
  mutt_menu_init ();
 
2892
  mutt_srandom ();
2893
2893
 
2894
2894
  /* 
2895
2895
   * XXX - use something even more difficult to predict?