X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..84b9ea1689a8189d41ea4a821a1fd6cc446b9332:/main.c diff --git a/main.c b/main.c index 0a566da..0952c93 100644 --- a/main.c +++ b/main.c @@ -65,7 +65,7 @@ To contact the developers, please mail to .\n\ To report a bug, please visit http://bugs.mutt.org/.\n"); static const char *Notice = N_("\ -Copyright (C) 1996-2008 Michael R. Elkins and others.\n\ +Copyright (C) 1996-2009 Michael R. Elkins and others.\n\ Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv'.\n\ Mutt is free software, and you are welcome to redistribute it\n\ under certain conditions; type `mutt -vv' for details.\n"); @@ -73,11 +73,12 @@ under certain conditions; type `mutt -vv' for details.\n"); static const char *Copyright = N_("\ Copyright (C) 1996-2007 Michael R. Elkins \n\ Copyright (C) 1996-2002 Brandon Long \n\ -Copyright (C) 1997-2007 Thomas Roessler \n\ +Copyright (C) 1997-2008 Thomas Roessler \n\ Copyright (C) 1998-2005 Werner Koch \n\ -Copyright (C) 1999-2008 Brendan Cully \n\ +Copyright (C) 1999-2009 Brendan Cully \n\ Copyright (C) 1999-2002 Tommi Komulainen \n\ Copyright (C) 2000-2002 Edmund Grimley Evans \n\ +Copyright (C) 2006-2009 Rocco Rutte \n\ \n\ Many others not mentioned here contributed code, fixes,\n\ and suggestions.\n"); @@ -110,7 +111,8 @@ static void mutt_usage (void) puts _( "usage: mutt [] [-z] [-f | -yZ]\n\ - mutt [] [-x] [-Hi ] [-s ] [-bc ] [-a [...]] [--] [...]\n\ + mutt [] [-x] [-Hi ] [-s ] [-bc ] [-a [...] --] [...]\n\ + mutt [] [-x] [-s ] [-bc ] [-a [...] --] [...] < message\n\ mutt [] -p\n\ mutt [] -A [...]\n\ mutt [] -Q [...]\n\ @@ -120,7 +122,8 @@ static void mutt_usage (void) puts _("\ options:\n\ -A \texpand the given alias\n\ - -a \tattach a file to the message\n\ + -a [...] --\tattach file(s) to the message\n\ +\t\tthe list of files must be terminated with the \"--\" sequence\n\ -b
\tspecify a blind carbon-copy (BCC) address\n\ -c
\tspecify a carbon-copy (CC) address\n\ -D\t\tprint the value of all variables to stdout"); @@ -147,8 +150,6 @@ options:\n\ -z\t\texit immediately if there are no messages in the mailbox\n\ -Z\t\topen the first folder with new message, exit immediately if none\n\ -h\t\tthis help message"); - puts _(" --\t\ttreat remaining arguments as addr even if starting with a dash\n\ -\t\twhen using -a with multiple filenames using -- is mandatory"); exit (0); } @@ -234,8 +235,6 @@ static void show_version (void) "-DL_STANDALONE " #endif - "\n" - #ifdef USE_FCNTL "+USE_FCNTL " #else @@ -247,7 +246,7 @@ static void show_version (void) #else "-USE_FLOCK " #endif - ); + ); puts ( #ifdef USE_POP "+USE_POP " @@ -266,13 +265,7 @@ static void show_version (void) #else "-USE_SMTP " #endif - -#ifdef USE_GSS - "+USE_GSS " -#else - "-USE_GSS " -#endif - + "\n" #ifdef USE_SSL_OPENSSL "+USE_SSL_OPENSSL " @@ -291,6 +284,11 @@ static void show_version (void) #else "-USE_SASL " #endif +#ifdef USE_GSS + "+USE_GSS " +#else + "-USE_GSS " +#endif #if HAVE_GETADDRINFO "+HAVE_GETADDRINFO " @@ -516,6 +514,7 @@ static void start_curses (void) #if HAVE_META meta (stdscr, TRUE); #endif +init_extended_keys(); } #define M_IGNORE (1<<0) /* -z */ @@ -544,7 +543,7 @@ int main (int argc, char **argv) int dump_variables = 0; extern char *optarg; extern int optind; - int attach_sep = 0; + int double_dash = argc, nargc = 1; /* sanity check against stupid administrators */ @@ -572,16 +571,32 @@ int main (int argc, char **argv) memset (Options, 0, sizeof (Options)); memset (QuadOptions, 0, sizeof (QuadOptions)); - for (i = 1; i < argc; i++) - if (!strcmp(argv[i], "--")) + for (optind = 1; optind < double_dash; ) + { + /* We're getopt'ing POSIXLY, so we'll be here every time getopt() + * encounters a non-option. That could be a file to attach + * (all non-options between -a and --) or it could be an address + * (which gets collapsed to the front of argv). + */ + for (; optind < argc; optind++) { - attach_sep = i; - break; + if (argv[optind][0] == '-' && argv[optind][1] != '\0') + { + if (argv[optind][1] == '-' && argv[optind][2] == '\0') + double_dash = optind; /* quit outer loop after getopt */ + break; /* drop through to getopt */ + } + + /* non-option, either an attachment or address */ + if (attach) + attach = mutt_add_list (attach, argv[optind]); + else + argv[nargc++] = argv[optind]; } - while ((i = getopt (argc, argv, "A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF) - switch (i) - { + if ((i = getopt (argc, argv, "+A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF) + switch (i) + { case 'A': alias_queries = mutt_add_list (alias_queries, optarg); break; @@ -616,7 +631,11 @@ int main (int argc, char **argv) case 'd': #ifdef DEBUG - debuglevel = atoi (optarg); + if (mutt_atoi (optarg, &debuglevel) < 0 || debuglevel <= 0) + { + fprintf (stderr, _("Error: value '%s' is invalid for -d.\n"), optarg); + return 1; + } printf (_("Debugging at level %d.\n"), debuglevel); #else printf _("DEBUG was not defined during compilation. Ignored.\n"); @@ -682,7 +701,14 @@ int main (int argc, char **argv) default: mutt_usage (); - } + } + } + + /* collapse remaining argv */ + while (optind < argc) + argv[nargc++] = argv[optind++]; + optind = 1; + argc = nargc; switch (version) { @@ -719,6 +745,9 @@ int main (int argc, char **argv) /* Initialize crypto backends. */ crypt_init (); + if (newMagic) + mx_set_magic (newMagic); + if (queries) { for (; optind < argc; optind++) @@ -751,14 +780,6 @@ int main (int argc, char **argv) return rv; } - /* if an -a option is present, all non-option arguments before -- are considered attachments */ - if (attach) - for (; optind <= attach_sep; optind++) - attach = mutt_add_list (attach, argv[optind]); - - if (newMagic) - mx_set_magic (newMagic); - if (!option (OPTNOCURSES)) { SETCOLOR (MT_COLOR_NORMAL); @@ -875,7 +896,7 @@ int main (int argc, char **argv) else fin = NULL; - mutt_mktemp (buf); + mutt_mktemp (buf, sizeof (buf)); tempfile = safe_strdup (buf); if (draftFile) @@ -892,7 +913,7 @@ int main (int argc, char **argv) if (!option (OPTNOCURSES)) mutt_endwin (NULL); perror (tempfile); - fclose (fin); + safe_fclose (&fin); FREE (&tempfile); exit (1); } @@ -900,9 +921,9 @@ int main (int argc, char **argv) mutt_copy_stream (fin, fout); else if (bodytext) fputs (bodytext, fout); - fclose (fout); + safe_fclose (&fout); if (fin && fin != stdin) - fclose (fin); + safe_fclose (&fin); } }