1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Startup -- interface with user.
3 *@ This file is also used to materialize externals.
5 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
6 * Copyright (c) 2012 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #ifndef HAVE_AMALGAMATION
46 #include <sys/ioctl.h>
51 #ifdef HAVE_NL_LANGINFO
52 # include <langinfo.h>
60 /* Verify that our size_t ZFMT format string has the correct type size */
64 struct a_arg
*aa_next
;
68 /* (extern, but not with amalgamation, so define here) */
69 VL
char const weekday_names
[7 + 1][4] = {
70 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", ""
72 VL
char const month_names
[12 + 1][4] = {
73 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
74 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""
76 VL
char const uagent
[] = UAGENT
;
77 VL
char const version
[] = VERSION
;
78 /*VL char const features[]; The "feature string" comes from config.h */
79 VL uc_it
const class_char
[] = {
80 /* 000 nul 001 soh 002 stx 003 etx 004 eot 005 enq 006 ack 007 bel */
81 C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
,
82 /* 010 bs 011 ht 012 nl 013 vt 014 np 015 cr 016 so 017 si */
83 C_CNTRL
, C_BLANK
, C_WHITE
, C_SPACE
, C_SPACE
, C_SPACE
, C_CNTRL
, C_CNTRL
,
84 /* 020 dle 021 dc1 022 dc2 023 dc3 024 dc4 025 nak 026 syn 027 etb */
85 C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
,
86 /* 030 can 031 em 032 sub 033 esc 034 fs 035 gs 036 rs 037 us */
87 C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
, C_CNTRL
,
88 /* 040 sp 041 ! 042 " 043 # 044 $ 045 % 046 & 047 ' */
89 C_BLANK
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
,
90 /* 050 ( 051 ) 052 * 053 + 054 , 055 - 056 . 057 / */
91 C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
,
92 /* 060 0 061 1 062 2 063 3 064 4 065 5 066 6 067 7 */
93 C_OCTAL
, C_OCTAL
, C_OCTAL
, C_OCTAL
, C_OCTAL
, C_OCTAL
, C_OCTAL
, C_OCTAL
,
94 /* 070 8 071 9 072 : 073 ; 074 < 075 = 076 > 077 ? */
95 C_DIGIT
, C_DIGIT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
,
96 /* 100 @ 101 A 102 B 103 C 104 D 105 E 106 F 107 G */
97 C_PUNCT
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
,
98 /* 110 H 111 I 112 J 113 K 114 L 115 M 116 N 117 O */
99 C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
,
100 /* 120 P 121 Q 122 R 123 S 124 T 125 U 126 V 127 W */
101 C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
, C_UPPER
,
102 /* 130 X 131 Y 132 Z 133 [ 134 \ 135 ] 136 ^ 137 _ */
103 C_UPPER
, C_UPPER
, C_UPPER
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
,
104 /* 140 ` 141 a 142 b 143 c 144 d 145 e 146 f 147 g */
105 C_PUNCT
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
,
106 /* 150 h 151 i 152 j 153 k 154 l 155 m 156 n 157 o */
107 C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
,
108 /* 160 p 161 q 162 r 163 s 164 t 165 u 166 v 167 w */
109 C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
, C_LOWER
,
110 /* 170 x 171 y 172 z 173 { 174 | 175 } 176 ~ 177 del */
111 C_LOWER
, C_LOWER
, C_LOWER
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_PUNCT
, C_CNTRL
114 /* getopt(3) fallback implementation */
116 # define _oarg optarg
117 # define _oind optind
118 /*# define _oerr opterr*/
119 # define _oopt optopt
122 static int _oind
, /*_oerr,*/ _oopt
;
125 /* getopt(3) fallback implementation */
127 # define _getopt getopt
129 static int _getopt(int argc
, char * const argv
[], char const *optstring
);
132 /* Perform basic startup initialization */
133 static void _startup(void);
136 static size_t _grow_cpp(char const ***cpp
, size_t newsize
, size_t oldcnt
);
138 /* Initialize *tempdir*, *myname*, *homedir* */
139 static void _setup_vars(void);
141 /* We're in an interactive session - compute what the screen size for printing
142 * headers etc. should be; notify tty upon resize if *is_sighdl* is not 0.
143 * We use the following algorithm for the height:
144 * If baud rate < 1200, use 9
145 * If baud rate = 1200, use 14
146 * If baud rate > 1200, use 24 or ws_row
147 * Width is either 80 or ws_col */
148 static void _setscreensize(int is_sighdl
);
150 /* Ok, we are reading mail. Decide whether we are editing a mailbox or reading
151 * the system mailbox, and open up the right stuff */
152 static int _rcv_mode(char const *folder
, char const *Larg
);
154 /* Interrupt printing of the headers */
155 static void _hdrstop(int signo
);
159 _getopt(int argc
, char * const argv
[], char const *optstring
)
161 static char const *lastp
;
167 if ((colon
= (optstring
[0] == ':')))
173 if (_oind
>= argc
|| argv
[_oind
] == 0 || argv
[_oind
][0] != '-' ||
174 argv
[_oind
][1] == '\0')
176 if (argv
[_oind
][1] == '-' && argv
[_oind
][2] == '\0') {
180 curp
= &argv
[_oind
][1];
184 while (optstring
[0] != '\0') {
185 if (optstring
[0] == ':' || optstring
[0] != _oopt
) {
189 if (optstring
[1] == ':') {
190 if (curp
[1] != '\0') {
191 _oarg
= UNCONST(curp
+ 1);
194 if ((_oind
+= 2) > argc
) {
195 if (!colon
/*&& _oerr*/) {
197 tr(79, "%s: option requires an argument -- %c\n"),
198 argv
[0], (char)_oopt
);
200 rv
= (colon
? ':' : '?');
203 _oarg
= argv
[_oind
- 1];
216 if (!colon
/*&& opterr*/)
217 fprintf(stderr
, tr(78, "%s: invalid option -- %c\n"), argv
[0], _oopt
);
228 #endif /* !HAVE_GETOPT */
236 /* Absolutely the first thing we do is save our egid and set it to the rgid,
237 * so that we can safely run setgid. We use the sgid (saved set-gid) to
238 * allow ourselves to revert to the egid if we want (temporarily) to become
239 * privileged XXX (s-nail-)*dotlock(-program)* [maybe forked<->Unix IPC?] */
240 effectivegid
= getegid();
242 if (setgid(realgid
) == -1) {
250 _oind
= /*_oerr =*/ 1;
253 if ((cp
= strrchr(progname
, '/')) != NULL
)
256 /* Set up a reasonable environment */
259 safe_signal(SIGABRT
, &_nyd_oncrash
);
261 safe_signal(SIGBUS
, &_nyd_oncrash
);
263 safe_signal(SIGFPE
, &_nyd_oncrash
);
264 safe_signal(SIGILL
, &_nyd_oncrash
);
265 safe_signal(SIGSEGV
, &_nyd_oncrash
);
267 command_manager_start();
269 if (isatty(STDIN_FILENO
)) /* TODO should be isatty(0) && isatty(2)?? */
270 options
|= OPT_TTYIN
| OPT_INTERACTIVE
;
271 if (isatty(STDOUT_FILENO
))
272 options
|= OPT_TTYOUT
;
273 if (IS_TTY_SESSION())
274 safe_signal(SIGPIPE
, dflpipe
= SIG_IGN
);
276 /* Define defaults for internal variables, based on POSIX 2008/Cor 1-2013.
277 * Note: on change please update ./nail.rc accordingly */
280 ok_bset(asksub
, TRU1
);
289 /* ok_vset(escape, ESCAPE *"~"*); TODO non-compliant */
292 ok_bset(header
, TRU1
);
299 /* noonehop -- Note: we ignore this one */
302 ok_vset(prompt
, "\\& "); /* POSIX "? " unless *bsdcompat*, then "& " */
310 /* ok_vset(toplines, "5"); XXX somewhat hmm */
312 #ifdef HAVE_SETLOCALE
313 setlocale(LC_ALL
, "");
314 mb_cur_max
= MB_CUR_MAX
;
315 # ifdef HAVE_NL_LANGINFO
316 if (ok_vlook(ttycharset
) == NULL
&& (cp
= nl_langinfo(CODESET
)) != NULL
)
317 ok_vset(ttycharset
, cp
);
320 # ifdef HAVE_C90AMEND1
321 if (mb_cur_max
> 1) {
323 if (mbtowc(&wc
, "\303\266", 2) == 2 && wc
== 0xF6 &&
324 mbtowc(&wc
, "\342\202\254", 3) == 3 && wc
== 0x20AC)
325 options
|= OPT_UNICODE
;
326 /* Reset possibly messed up state; luckily this also gives us an
327 * indication wether the encoding has locking shift state sequences */
328 /* TODO temporary - use option bits! */
329 enc_has_state
= mbtowc(&wc
, NULL
, mb_cur_max
);
337 # ifdef NL_CAT_LOCALE
338 catd
= catopen(CATNAME
, NL_CAT_LOCALE
);
340 catd
= catopen(CATNAME
, 0);
345 iconvd
= (iconv_t
)-1;
351 _grow_cpp(char const ***cpp
, size_t newsize
, size_t oldcnt
)
353 /* Before spreserve(): use our string pool instead of LibC heap */
357 newcpp
= salloc(sizeof(char*) * newsize
);
360 memcpy(newcpp
, *cpp
, oldcnt
* sizeof(char*));
369 /* Before spreserve(): use our string pool instead of LibC heap */
370 /* XXX further check paths? */
373 struct passwd
*pwuid
, *pw
;
376 tempdir
= ((cp
= getenv("TMPDIR")) != NULL
) ? savestr(cp
) : TMPDIR_FALLBACK
;
378 cp
= (myname
== NULL
) ? getenv("USER") : myname
;
380 if ((pwuid
= getpwuid(uid
)) == NULL
)
381 panic(tr(201, "Cannot associate a name with uid %lu"), (ul_it
)uid
);
383 myname
= pwuid
->pw_name
;
384 else if ((pw
= getpwnam(cp
)) == NULL
)
385 panic(tr(236, "`%s' is not a user of this system"), cp
);
387 myname
= pw
->pw_name
;
388 if (pw
->pw_uid
!= uid
)
389 options
|= OPT_u_FLAG
;
391 myname
= savestr(myname
);
392 /* XXX myfullname = pw->pw_gecos[OPTIONAL!] -> GUT THAT; TODO pw_shell */
394 if ((cp
= getenv("HOME")) == NULL
)
395 cp
= "."; /* XXX User and Login objects; Login: pw->pw_dir */
396 homedir
= savestr(cp
);
401 _setscreensize(int is_sighdl
)
406 #elif defined TIOCGSIZE
411 scrnheight
= realscreenheight
= scrnwidth
= 0;
413 /* (Also) POSIX: LINES and COLUMNS always override. Adjust this
414 * a little bit to be able to honour resizes during our lifetime and
415 * only honour it upon first run; abuse *is_sighdl* as an indicator */
420 if ((cp
= getenv("LINES")) != NULL
&& (i
= strtol(cp
, NULL
, 10)) > 0)
421 scrnheight
= realscreenheight
= (int)i
;
422 if ((cp
= getenv("COLUMNS")) != NULL
&& (i
= strtol(cp
, NULL
, 10)) > 0)
425 if (scrnwidth
!= 0 && scrnheight
!= 0)
430 if (ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
) == -1)
431 ws
.ws_col
= ws
.ws_row
= 0;
432 #elif defined TIOCGSIZE
433 if (ioctl(STDOUT_FILENO
, TIOCGSIZE
, &ws
) == -1)
434 ts
.ts_lines
= ts
.ts_cols
= 0;
437 if (scrnheight
== 0) {
438 speed_t ospeed
= ((tcgetattr(STDOUT_FILENO
, &tbuf
) == -1)
439 ? B9600
: cfgetospeed(&tbuf
));
443 else if (ospeed
== B1200
)
446 else if (ws
.ws_row
!= 0)
447 scrnheight
= ws
.ws_row
;
448 #elif defined TIOCGSIZE
449 else if (ts
.ts_lines
!= 0)
450 scrnheight
= ts
.ts_lines
;
455 #if defined TIOCGWINSZ || defined TIOCGSIZE
458 (realscreenheight
= ws
.ws_row
)
460 (realscreenheight
= ts
.ts_lines
)
463 realscreenheight
= 24;
467 if (scrnwidth
== 0 && 0 ==
469 (scrnwidth
= ws
.ws_col
)
470 #elif defined TIOCGSIZE
471 (scrnwidth
= ts
.ts_cols
)
478 if (is_sighdl
&& IS_TTY_SESSION())
479 tty_signal(SIGWINCH
);
484 static sigjmp_buf __hdrjmp
; /* XXX */
487 _rcv_mode(char const *folder
, char const *Larg
)
491 sighandler_type prevint
;
496 else if (*folder
== '@') {
497 /* This must be treated specially to make possible invocation like
498 * -A imap -f @mailbox */
499 if ((cp
= ok_vlook(folder
)) != NULL
&& which_protocol(cp
) == PROTO_IMAP
)
500 n_strlcpy(mailname
, cp
, PATH_MAX
);
503 i
= setfile(folder
, 0);
505 exit_status
= EXIT_ERR
; /* error already reported */
508 if (options
& OPT_EXISTONLY
) {
512 if (options
& (OPT_HEADERSONLY
| OPT_HEADERLIST
)) {
513 if ((exit_status
= i
) == EXIT_OK
)
514 print_header_summary(Larg
);
518 callhook(mailname
, 0);
519 if (i
> 0 && !ok_blook(emptystart
)) {
520 exit_status
= EXIT_ERR
;
524 if (sigsetjmp(__hdrjmp
, 1) == 0) {
525 if ((prevint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
526 safe_signal(SIGINT
, _hdrstop
);
527 if (!(options
& OPT_N_FLAG
)) {
528 if (!ok_blook(quiet
))
529 printf(tr(140, "%s version %s. Type ? for help.\n"),
530 (ok_blook(bsdcompat
) ? "Mail" : uagent
), version
);
534 safe_signal(SIGINT
, prevint
);
537 /* Enter the command loop */
538 if (options
& OPT_INTERACTIVE
)
541 if (options
& OPT_INTERACTIVE
)
544 if (mb
.mb_type
== MB_FILE
|| mb
.mb_type
== MB_MAILDIR
) {
545 safe_signal(SIGHUP
, SIG_IGN
);
546 safe_signal(SIGINT
, SIG_IGN
);
547 safe_signal(SIGQUIT
, SIG_IGN
);
549 save_mbox_for_possible_quitstuff();
559 NYD_X
; /* Signal handler */
563 fprintf(stderr
, tr(141, "\nInterrupt\n"));
564 siglongjmp(__hdrjmp
, 1);
568 main(int argc
, char *argv
[])
570 static char const optstr
[] = "A:a:Bb:c:DdEeFfHiL:NnO:q:Rr:S:s:tu:Vv~#",
573 " %s [-BDdEFintv~] [-A acc] [-a attachment] "
574 "[-b bcc-addr] [-c cc-addr]\n"
575 "\t [-O mtaopt [-O mtaopt-arg]] [-q file] [-r from-addr] "
577 "\t [-s subject] to-addr...\n"
578 " %s [-BDdEeHiNnRv~#] [-A acc] [-L spec-list] [-S var[=value]] "
580 " %s [-BDdEeHiNnRv~#] [-A acc] [-L spec-list] [-S var[=value]] "
583 struct a_arg
*a_head
= NULL
, *a_curr
= /* silence CC */ NULL
;
584 struct name
*to
= NULL
, *cc
= NULL
, *bcc
= NULL
;
585 struct attachment
*attach
= NULL
;
586 char *cp
= NULL
, *subject
= NULL
, *qf
= NULL
, *Aarg
= NULL
, *Larg
= NULL
;
587 char const *okey
, **oargs
= NULL
, *folder
= NULL
;
588 size_t oargs_size
= 0, oargs_count
= 0, smopts_size
= 0;
593 * Start our lengthy setup
597 var_clear_allow_undefined
= TRU1
;
602 /* Command line parsing
603 * Variable settings need to be done twice, since the user surely wants the
604 * setting to take effect immediately, but also doesn't want it to be
605 * overwritten from within resource files */
606 while ((i
= _getopt(argc
, argv
, optstr
)) >= 0) {
609 /* Execute an account command later on */
613 options
|= OPT_SENDMODE
;
614 { struct a_arg
*nap
= ac_alloc(sizeof(struct a_arg
));
618 a_curr
->aa_next
= nap
;
620 nap
->aa_file
= _oarg
;
625 /* Make 0/1 line buffered */
626 setvbuf(stdin
, NULL
, _IOLBF
, 0);
627 setvbuf(stdout
, NULL
, _IOLBF
, 0);
630 /* Get Blind Carbon Copy Recipient list */
631 options
|= OPT_SENDMODE
;
632 bcc
= cat(bcc
, checkaddrs(lextract(_oarg
, GBCC
| GFULL
)));
635 /* Get Carbon Copy Recipient list */
636 options
|= OPT_SENDMODE
;
637 cc
= cat(cc
, checkaddrs(lextract(_oarg
, GCC
| GFULL
)));
641 ok_bset(disconnected
, TRU1
);
642 okey
= "disconnected";
648 ok_bset(debug
, TRU1
);
652 ok_bset(skipemptybody
, TRU1
);
653 okey
= "skipemptybody";
656 options
|= OPT_EXISTONLY
;
659 options
|= OPT_F_FLAG
| OPT_SENDMODE
;
662 /* User is specifying file to "edit" with Mail, as opposed to reading
663 * system mailbox. If no argument is given, we read his mbox file.
664 * Check for remaining arguments later */
668 options
|= OPT_HEADERSONLY
;
671 /* Ignore interrupts */
672 ok_bset(ignore
, TRU1
);
677 options
|= OPT_HEADERLIST
;
678 if (*Larg
== '"' || *Larg
== '\'') { /* TODO list.c:listspec_check() */
679 size_t j
= strlen(++Larg
);
685 /* Avoid initial header printing */
686 ok_bset(header
, FAL0
);
690 /* Don't source "unspecified system start-up file" */
691 options
|= OPT_NOSRC
;
694 /* Additional options to pass-through to MTA */
695 if (smopts_count
== (size_t)smopts_size
)
696 smopts_size
= _grow_cpp(&smopts
, smopts_size
+ 8, smopts_count
);
697 smopts
[smopts_count
++] = skin(_oarg
);
700 /* Quote file TODO drop? -Q with real quote?? what ? */
701 options
|= OPT_SENDMODE
;
706 /* Open folders read-only */
707 options
|= OPT_R_FLAG
;
710 /* Set From address. */
711 options
|= OPT_r_FLAG
;
712 if ((option_r_arg
= _oarg
)[0] != '\0') {
713 struct name
*fa
= nalloc(_oarg
, GFULL
);
715 if (is_addr_invalid(fa
, 1) || is_fileorpipe_addr(fa
)) {
716 fprintf(stderr
, tr(271, "Invalid address argument with -r\n"));
719 option_r_arg
= fa
->n_name
;
720 /* TODO -r options is set in smopts, but may
721 * TODO be overwritten by setting from= in
722 * TODO an interactive session!
723 * TODO Maybe disable setting of from?
724 * TODO Warn user? Update manual!! */
725 okey
= savecat("from=", fa
->n_fullname
);
727 /* ..and fa goes even though it is ready :/ */
731 /* Set variable (twice) */
738 if (oargs_count
== oargs_size
)
739 oargs_size
= _grow_cpp(&oargs
, oargs_size
+ 8, oargs_count
);
740 oargs
[oargs_count
++] = okey
;
745 options
|= OPT_SENDMODE
;
748 /* Read defined set of headers from mail to be send */
749 options
|= OPT_SENDMODE
| OPT_t_FLAG
;
752 /* Set user name to pretend to be; don't set OPT_u_FLAG yet, this is
753 * done as necessary in _setup_vars() above */
762 ok_bset(verbose
, TRU1
);
766 /* Enable tilde escapes even in non-interactive mode */
767 options
|= OPT_TILDE_FLAG
;
770 /* Work in batch mode, even if non-interactive */
771 if (oargs_count
+ 6 >= oargs_size
)
772 oargs_size
= _grow_cpp(&oargs
, oargs_size
+ 8, oargs_count
);
773 /* xxx Setting most of the -# options immediately is useless, so be
774 * selective in what is set immediately */
775 options
|= OPT_TILDE_FLAG
| OPT_BATCH_FLAG
;
776 folder
= "/dev/null";
778 ok_bset(emptystart
, TRU1
);
779 ok_bset(header
, FAL0
);
780 ok_bset(quiet
, TRU1
);
781 ok_bset(sendwait
, TRU1
);
782 ok_vset(MBOX
, folder
);
783 oargs
[oargs_count
+ 0] = "dot";
784 oargs
[oargs_count
+ 1] = "emptystart";
785 oargs
[oargs_count
+ 2] = "noheader";
786 oargs
[oargs_count
+ 3] = "quiet";
787 oargs
[oargs_count
+ 4] = "sendwait";
788 oargs
[oargs_count
+ 5] = "MBOX=/dev/null";
793 fprintf(stderr
, tr(135, usagestr
), progname
, progname
, progname
);
794 exit_status
= EXIT_USE
;
799 /* OPT_BATCH_FLAG sets to /dev/null, but -f can still be used and sets & */
800 if (folder
!= NULL
&& folder
[1] == '\0') {
802 if (_oind
+ 1 < argc
) {
803 fprintf(stderr
, tr(205, "More than one file given with -f\n"));
806 folder
= argv
[_oind
];
809 for (i
= _oind
; argv
[i
]; ++i
)
810 to
= cat(to
, checkaddrs(lextract(argv
[i
], GTO
| GFULL
)));
812 options
|= OPT_SENDMODE
;
815 /* Check for inconsistent arguments */
816 if (options
& OPT_SENDMODE
) {
817 if (folder
!= NULL
&& !(options
& OPT_BATCH_FLAG
)) {
818 fprintf(stderr
, tr(137, "Cannot give -f and people to send to.\n"));
821 if (myname
!= NULL
) {
822 fprintf(stderr
, tr(568,
823 "The -u option cannot be used in send mode\n"));
826 if (!(options
& OPT_t_FLAG
) && to
== NULL
) {
827 fprintf(stderr
, tr(138,
828 "Send options without primary recipient specified.\n"));
831 if (options
& (OPT_HEADERSONLY
| OPT_HEADERLIST
)) {
832 fprintf(stderr
, tr(45,
833 "The -H and -L options cannot be used in send mode.\n"));
836 if (options
& OPT_R_FLAG
) {
838 tr(235, "The -R option is meaningless in send mode.\n"));
842 if (folder
!= NULL
&& myname
!= NULL
) {
843 fprintf(stderr
, tr(569,
844 "The options -f and -u are mutually exclusive\n"));
850 * Likely to go, perform more setup
855 if (options
& OPT_INTERACTIVE
) {
858 # ifndef TTY_WANTS_SIGWINCH
859 if (safe_signal(SIGWINCH
, SIG_IGN
) != SIG_IGN
)
861 safe_signal(SIGWINCH
, _setscreensize
);
864 scrnheight
= realscreenheight
= 24, scrnwidth
= 80;
866 /* Snapshot our string pools. Memory is auto-reclaimed from now on */
869 if (!(options
& OPT_NOSRC
) && getenv("NAIL_NO_SYSTEM_RC") == NULL
)
871 /* *expand() returns a savestr(), but load only uses the file name for
872 * fopen(), so it's safe to do this */
873 if ((cp
= getenv("MAILRC")) == NULL
&& (cp
= getenv("NAILRC")) == NULL
)
874 cp
= UNCONST(MAILRC
);
875 load(file_expand(cp
));
876 if (getenv("NAIL_EXTRA_RC") == NULL
&&
877 (cp
= ok_vlook(NAIL_EXTRA_RC
)) != NULL
)
878 load(file_expand(cp
));
880 /* Now we can set the account */
888 /* Ensure the -S and other command line options take precedence over
889 * anything that may have been placed in resource files.
890 * Our "ternary binary" option *verbose* needs special treament */
891 if ((options
& (OPT_VERB
| OPT_VERBVERB
)) == OPT_VERB
)
892 options
&= ~OPT_VERB
;
893 for (i
= 0; UICMP(z
, i
, <, oargs_count
); ++i
) {
901 * We're finally completely setup and ready to go
905 var_clear_allow_undefined
= FAL0
;
907 if (options
& OPT_DEBUG
)
908 fprintf(stderr
, tr(199, "user = %s, homedir = %s\n"), myname
, homedir
);
910 if (!(options
& OPT_SENDMODE
)) {
911 exit_status
= _rcv_mode(folder
, Larg
);
915 /* Now that full mailx(1)-style file expansion is possible handle the
916 * attachments which we had delayed due to this.
917 * This may use savestr(), but since we won't enter the command loop we
918 * don't need to care about that */
919 while (a_head
!= NULL
) {
920 attach
= add_attachment(attach
, a_head
->aa_file
, NULL
);
921 if (attach
!= NULL
) {
923 a_head
= a_head
->aa_next
;
926 perror(a_head
->aa_file
);
927 exit_status
= EXIT_ERR
;
932 /* xxx exit_status = EXIT_OK; */
933 if (options
& OPT_INTERACTIVE
)
935 mail(to
, cc
, bcc
, subject
, attach
, qf
, ((options
& OPT_F_FLAG
) != 0));
936 if (options
& OPT_INTERACTIVE
)
943 /* vim:set fenc=utf-8:s-it-mode */