INSTALL: more on v14.5
[s-mailx.git] / acmava.c
blobb2d7c281c7253ebd0c2beafeba09bb8ac31babdd
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Account, macro and variable handling.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2013 Steffen "Daode" Nurpmeso <sdaoden@users.sf.net>.
6 */
7 /*
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
40 #ifndef HAVE_AMALGAMATION
41 # include "nail.h"
42 #endif
45 * TODO in general it would be nice if it would be possible to define "macros"
46 * TODO etc. inside of other "macros"
49 #define MA_PRIME HSHSIZE
50 #define MA_HASH(S) (strhash(S) % MA_PRIME)
52 enum ma_flags {
53 MA_NONE = 0,
54 MA_ACC = 1<<0,
55 MA_TYPE_MASK = MA_ACC,
56 MA_UNDEF = 1<<1 /* Unlink after lookup */
59 struct macro {
60 struct macro *ma_next;
61 char *ma_name;
62 struct mline *ma_contents;
63 size_t ma_maxlen; /* Maximum line length */
64 enum ma_flags ma_flags;
65 struct var *ma_localopts; /* `account' unroll list, for `localopts' */
68 struct mline {
69 struct mline *l_next;
70 size_t l_length;
71 char l_line[VFIELD_SIZE(sizeof(size_t))];
74 struct var {
75 struct var *v_link;
76 char *v_name;
77 char *v_value;
80 struct lostack {
81 struct lostack *s_up; /* Outer context */
82 struct macro *s_mac; /* Context (`account' or `define') */
83 struct var *s_localopts;
84 bool_t s_unroll; /* Unroll? */
87 static struct macro *_acc_curr; /* Currently active account */
88 static struct lostack *_localopts; /* Currently executing macro unroll list */
90 /* TODO once we have a dynamically sized hashtable we could unite _macros and
91 * TODO _variables into a single hashtable, stripping down fun interface;
92 * TODO also, setting and clearing a variable can be easily joined */
93 static struct macro *_macros[MA_PRIME]; /* TODO dynamically spaced */
94 static struct var *_vars[MA_PRIME]; /* TODO dynamically spaced */
96 /* Special cased value string allocation */
97 static char * _vcopy(char const *str);
98 static void _vfree(char *cp);
100 /* Check for special housekeeping. */
101 static bool_t _check_special_vars(char const *name, bool_t enable,
102 char **val);
104 /* If a variable name begins with a lowercase-character and contains at
105 * least one '@', it is converted to all-lowercase. This is necessary
106 * for lookups of names based on email addresses.
108 * Following the standard, only the part following the last '@' should
109 * be lower-cased, but practice has established otherwise here */
110 static char const * _canonify(char const *vn);
112 /* Locate a variable and return its variable node */
113 static struct var * _lookup(char const *name, ui_it h, bool_t hisset);
115 /* Line *cp* consists solely of WS and a } */
116 static bool_t _is_closing_angle(char const *cp);
118 /* Lookup for macros/accounts */
119 static struct macro *_malook(char const *name, struct macro *data,
120 enum ma_flags mafl);
122 /* Walk all lines of a macro and execute() them */
123 static int _maexec(struct macro const *mp, struct var **unroll_store);
125 /* User display helpers */
126 static int _list_macros(enum ma_flags mafl);
128 /* */
129 static bool_t _define1(char const *name, enum ma_flags mafl);
130 static void _undef1(char const *name, enum ma_flags mafl);
131 static void _freelines(struct mline *lp);
133 /* qsort(3) helper */
134 static int __var_list_all_cmp(void const *s1, void const *s2);
136 /* Update replay-log */
137 static void _localopts_add(struct lostack *losp, char const *name,
138 struct var *ovap);
139 static void _localopts_unroll(struct var **vapp);
141 static char *
142 _vcopy(char const *str)
144 char *news;
145 size_t len;
147 if (*str == '\0')
148 news = UNCONST("");
149 else {
150 len = strlen(str) + 1;
151 news = smalloc(len);
152 memcpy(news, str, len);
154 return news;
157 static void
158 _vfree(char *cp)
160 if (*cp != '\0')
161 free(cp);
164 static bool_t
165 _check_special_vars(char const *name, bool_t enable, char **val)
167 /* TODO _check_special_vars --> value cache */
168 char *cp = NULL;
169 bool_t rv = TRU1;
170 int flag = 0;
172 if (strcmp(name, "debug") == 0)
173 flag = OPT_DEBUG;
174 else if (strcmp(name, "header") == 0)
175 flag = OPT_N_FLAG, enable = ! enable;
176 else if (strcmp(name, "skipemptybody") == 0)
177 flag = OPT_E_FLAG;
178 else if (strcmp(name, "verbose") == 0)
179 flag = OPT_VERBOSE;
180 else if (strcmp(name, "prompt") == 0)
181 flag = OPT_NOPROMPT, enable = ! enable;
182 else if (strcmp(name, "folder") == 0) {
183 rv = var_folder_updated(*val, &cp);
184 if (rv && cp != NULL) {
185 _vfree(*val);
186 /* It's smalloc()ed, but ensure we don't leak */
187 if (*cp == '\0') {
188 *val = UNCONST("");
189 free(cp);
190 } else
191 *val = cp;
194 #ifdef HAVE_NCL
195 else if (strcmp(name, "line-editor-cursor-right") == 0) {
196 char const *x = cp = *val;
197 int c;
198 while (*x != '\0') {
199 c = expand_shell_escape(&x, FAL0);
200 if (c < 0)
201 break;
202 *cp++ = (char)c;
204 *cp++ = '\0';
206 #endif
208 if (flag) {
209 if (enable)
210 options |= flag;
211 else
212 options &= ~flag;
214 return rv;
217 static char const *
218 _canonify(char const *vn)
220 if (! upperchar(*vn)) {
221 char const *vp;
223 for (vp = vn; *vp != '\0' && *vp != '@'; ++vp)
225 vn = (*vp == '@') ? i_strdup(vn) : vn;
227 return vn;
230 static struct var *
231 _lookup(char const *name, ui_it h, bool_t hisset)
233 struct var **vap, *lvp, *vp;
235 if (! hisset)
236 h = MA_HASH(name);
237 vap = _vars + h;
239 for (lvp = NULL, vp = *vap; vp != NULL; lvp = vp, vp = vp->v_link)
240 if (*vp->v_name == *name && strcmp(vp->v_name, name) == 0) {
241 /* Relink as head, hope it "sorts on usage" over time */
242 if (lvp != NULL) {
243 lvp->v_link = vp->v_link;
244 vp->v_link = *vap;
245 *vap = vp;
247 goto jleave;
249 vp = NULL;
250 jleave:
251 return vp;
254 static bool_t
255 _is_closing_angle(char const *cp)
257 bool_t rv = FAL0;
258 while (spacechar(*cp))
259 ++cp;
260 if (*cp++ != '}')
261 goto jleave;
262 while (spacechar(*cp))
263 ++cp;
264 rv = (*cp == '\0');
265 jleave:
266 return rv;
269 static struct macro *
270 _malook(char const *name, struct macro *data, enum ma_flags mafl)
272 enum ma_flags save_mafl;
273 ui_it h;
274 struct macro *lmp, *mp;
276 save_mafl = mafl;
277 mafl &= MA_TYPE_MASK;
278 h = MA_HASH(name);
280 for (lmp = NULL, mp = _macros[h]; mp != NULL; lmp = mp, mp = mp->ma_next) {
281 if ((mp->ma_flags & MA_TYPE_MASK) == mafl &&
282 strcmp(mp->ma_name, name) == 0) {
283 if (save_mafl & MA_UNDEF) {
284 if (lmp == NULL)
285 _macros[h] = mp->ma_next;
286 else
287 lmp->ma_next = mp->ma_next;
289 goto jleave;
293 if (data != NULL) {
294 data->ma_next = _macros[h];
295 _macros[h] = data;
296 mp = NULL;
298 jleave:
299 return mp;
302 static int
303 _maexec(struct macro const *mp, struct var **unroll_store)
305 struct lostack los;
306 int rv = 0;
307 struct mline const *lp;
308 char *buf = ac_alloc(mp->ma_maxlen + 1);
310 los.s_up = _localopts;
311 los.s_mac = UNCONST(mp);
312 los.s_localopts = NULL;
313 los.s_unroll = FAL0;
314 _localopts = &los;
316 for (lp = mp->ma_contents; lp; lp = lp->l_next) {
317 unset_allow_undefined = TRU1;
318 memcpy(buf, lp->l_line, lp->l_length + 1);
319 rv |= execute(buf, 0, lp->l_length); /* XXX break if != 0 ? */
320 unset_allow_undefined = FAL0;
323 _localopts = los.s_up;
324 if (unroll_store == NULL)
325 _localopts_unroll(&los.s_localopts);
326 else
327 *unroll_store = los.s_localopts;
329 ac_free(buf);
330 return rv;
333 static int
334 _list_macros(enum ma_flags mafl)
336 FILE *fp;
337 char *cp;
338 char const *typestr;
339 struct macro *mq;
340 ui_it ti, mc;
341 struct mline *lp;
343 if ((fp = Ftemp(&cp, "Ra", "w+", 0600, 1)) == NULL) {
344 perror("tmpfile");
345 return 1;
347 rm(cp);
348 Ftfree(&cp);
350 mafl &= MA_TYPE_MASK;
351 typestr = (mafl & MA_ACC) ? "account" : "define";
353 for (ti = mc = 0; ti < MA_PRIME; ++ti)
354 for (mq = _macros[ti]; mq; mq = mq->ma_next)
355 if ((mq->ma_flags & MA_TYPE_MASK) == mafl) {
356 if (++mc > 1)
357 fputc('\n', fp);
358 fprintf(fp, "%s %s {\n", typestr, mq->ma_name);
359 for (lp = mq->ma_contents; lp; lp = lp->l_next)
360 fprintf(fp, " %s\n", lp->l_line);
361 fputs("}\n", fp);
363 if (mc)
364 page_or_print(fp, 0);
366 mc = (ui_it)ferror(fp);
367 Fclose(fp);
368 return (int)mc;
371 static bool_t
372 _define1(char const *name, enum ma_flags mafl)
374 bool_t rv = FAL0;
375 struct macro *mp;
376 struct mline *lp, *lst = NULL, *lnd = NULL;
377 char *linebuf = NULL, *cp;
378 size_t linesize = 0, maxlen = 0;
379 int n, i;
381 mp = scalloc(1, sizeof *mp);
382 mp->ma_name = sstrdup(name);
383 mp->ma_flags = mafl;
385 for (;;) {
386 n = readline_input(LNED_LF_ESC, "", &linebuf, &linesize);
387 if (n <= 0) {
388 fprintf(stderr, tr(75, "Unterminated %s definition: \"%s\".\n"),
389 (mafl & MA_ACC ? "account" : "macro"), mp->ma_name);
390 if (sourcing)
391 unstack();
392 goto jerr;
394 if (_is_closing_angle(linebuf))
395 break;
397 /* Trim WS */
398 for (cp = linebuf, i = 0; i < n; ++cp, ++i)
399 if (! whitechar(*cp))
400 break;
401 if (i == n)
402 continue;
403 n -= i;
404 while (whitechar(cp[n - 1]))
405 if (--n == 0)
406 break;
407 if (n == 0)
408 continue;
410 maxlen = MAX(maxlen, (size_t)n);
411 cp[n++] = '\0';
413 lp = scalloc(1, sizeof(*lp) - VFIELD_SIZEOF(struct mline, l_line) + n);
414 memcpy(lp->l_line, cp, n);
415 lp->l_length = (size_t)--n;
416 if (lst != NULL) {
417 lnd->l_next = lp;
418 lnd = lp;
419 } else
420 lst = lnd = lp;
422 mp->ma_contents = lst;
423 mp->ma_maxlen = maxlen;
425 if (_malook(mp->ma_name, mp, mafl) != NULL) {
426 if (! (mafl & MA_ACC)) {
427 fprintf(stderr, tr(76, "A macro named \"%s\" already exists.\n"),
428 mp->ma_name);
429 lst = mp->ma_contents;
430 goto jerr;
432 _undef1(mp->ma_name, MA_ACC);
433 _malook(mp->ma_name, mp, MA_ACC);
436 rv = TRU1;
437 jleave:
438 if (linebuf != NULL)
439 free(linebuf);
440 return rv;
441 jerr:
442 if (lst != NULL)
443 _freelines(lst);
444 free(mp->ma_name);
445 free(mp);
446 goto jleave;
449 static void
450 _undef1(char const *name, enum ma_flags mafl)
452 struct macro *mp;
454 if ((mp = _malook(name, NULL, mafl | MA_UNDEF)) != NULL) {
455 _freelines(mp->ma_contents);
456 free(mp->ma_name);
457 free(mp);
461 static void
462 _freelines(struct mline *lp)
464 struct mline *lq;
466 for (lq = NULL; lp != NULL; ) {
467 if (lq != NULL)
468 free(lq);
469 lq = lp;
470 lp = lp->l_next;
472 if (lq)
473 free(lq);
476 static int
477 __var_list_all_cmp(void const *s1, void const *s2)
479 return strcmp(*(char**)UNCONST(s1), *(char**)UNCONST(s2));
482 static void
483 _localopts_add(struct lostack *losp, char const *name, struct var *ovap)
485 struct var *vap;
486 size_t nl, vl;
488 /* Propagate unrolling up the stack, as necessary */
489 while (! losp->s_unroll && (losp = losp->s_up) != NULL)
491 if (losp == NULL)
492 goto jleave;
494 /* We have found a level that wants to unroll; check wether it does it yet */
495 for (vap = losp->s_localopts; vap != NULL; vap = vap->v_link)
496 if (strcmp(vap->v_name, name) == 0)
497 goto jleave;
499 nl = strlen(name) + 1;
500 vl = (ovap != NULL) ? strlen(ovap->v_value) + 1 : 0;
501 vap = smalloc(sizeof(*vap) + nl + vl);
502 vap->v_link = losp->s_localopts;
503 losp->s_localopts = vap;
504 vap->v_name = (char*)(vap + 1);
505 memcpy(vap->v_name, name, nl);
506 if (vl == 0)
507 vap->v_value = NULL;
508 else {
509 vap->v_value = (char*)(vap + 1) + nl;
510 memcpy(vap->v_value, ovap->v_value, vl);
512 jleave:
516 static void
517 _localopts_unroll(struct var **vapp)
519 struct lostack *save_los;
520 struct var *x, *vap;
522 vap = *vapp;
523 *vapp = NULL;
525 save_los = _localopts;
526 _localopts = NULL;
527 while (vap != NULL) {
528 x = vap;
529 vap = vap->v_link;
530 var_assign(x->v_name, x->v_value);
531 free(x);
533 _localopts = save_los;
536 FL void
537 var_assign(char const *name, char const *val)
539 struct var *vp;
540 ui_it h;
541 char *oval;
543 if (val == NULL) {
544 bool_t tmp = unset_allow_undefined;
545 unset_allow_undefined = TRU1;
546 var_unset(name);
547 unset_allow_undefined = tmp;
548 goto jleave;
551 name = _canonify(name);
552 h = MA_HASH(name);
553 vp = _lookup(name, h, TRU1);
555 /* Don't care what happens later on, store this in the unroll list */
556 if (_localopts != NULL)
557 _localopts_add(_localopts, name, vp);
559 if (vp == NULL) {
560 vp = (struct var*)scalloc(1, sizeof *vp);
561 vp->v_name = _vcopy(name);
562 vp->v_link = _vars[h];
563 _vars[h] = vp;
564 oval = UNCONST("");
565 } else
566 oval = vp->v_value;
567 vp->v_value = _vcopy(val);
569 /* Check if update allowed XXX wasteful on error! */
570 if (! _check_special_vars(name, TRU1, &vp->v_value)) {
571 char *cp = vp->v_value;
572 vp->v_value = oval;
573 oval = cp;
575 if (*oval != '\0')
576 _vfree(oval);
577 jleave:
581 FL int
582 var_unset(char const *name)
584 int ret = 1;
585 ui_it h;
586 struct var *vp;
588 name = _canonify(name);
589 h = MA_HASH(name);
590 vp = _lookup(name, h, TRU1);
592 if (vp == NULL) {
593 if (! sourcing && ! unset_allow_undefined) {
594 fprintf(stderr, tr(203, "\"%s\": undefined variable\n"), name);
595 goto jleave;
597 } else {
598 if (_localopts != NULL)
599 _localopts_add(_localopts, name, vp);
601 /* Always listhead after _lookup() */
602 _vars[h] = _vars[h]->v_link;
603 _vfree(vp->v_name);
604 _vfree(vp->v_value);
605 free(vp);
607 _check_special_vars(name, FAL0, NULL);
609 ret = 0;
610 jleave:
611 return ret;
614 FL char *
615 var_lookup(char const *name, bool_t look_environ)
617 struct var *vp;
618 char *rv;
620 name = _canonify(name);
621 if ((vp = _lookup(name, 0, FAL0)) != NULL)
622 rv = vp->v_value;
623 else if (! look_environ)
624 rv = NULL;
625 else if ((rv = getenv(name)) != NULL && *rv != '\0')
626 rv = savestr(rv);
627 return rv;
630 FL void
631 var_list_all(void)
633 FILE *fp;
634 char *cp, **vacp, **cap;
635 struct var *vp;
636 size_t no, i;
637 char const *fmt;
639 if ((fp = Ftemp(&cp, "Ra", "w+", 0600, 1)) == NULL) {
640 perror("tmpfile");
641 goto jleave;
643 rm(cp);
644 Ftfree(&cp);
646 for (no = i = 0; i < MA_PRIME; ++i)
647 for (vp = _vars[i]; vp != NULL; vp = vp->v_link)
648 ++no;
649 vacp = salloc(no * sizeof(*vacp));
650 for (cap = vacp, i = 0; i < MA_PRIME; ++i)
651 for (vp = _vars[i]; vp != NULL; vp = vp->v_link)
652 *cap++ = vp->v_name;
654 if (no > 1)
655 qsort(vacp, no, sizeof *vacp, &__var_list_all_cmp);
657 i = (boption("bsdcompat") || boption("bsdset"));
658 fmt = (i != 0) ? "%s\t%s\n" : "%s=\"%s\"\n";
660 for (cap = vacp; no != 0; ++cap, --no) {
661 cp = value(*cap); /* TODO internal lookup; binary? value? */
662 if (cp == NULL)
663 cp = UNCONST("");
664 if (i || *cp != '\0')
665 fprintf(fp, fmt, *cap, cp);
666 else
667 fprintf(fp, "%s\n", *cap);
670 page_or_print(fp, (size_t)(cap - vacp));
671 Fclose(fp);
672 jleave:
676 FL int
677 cdefine(void *v)
679 int rv = 1;
680 char **args = v;
681 char const *errs;
683 if (args[0] == NULL) {
684 errs = tr(504, "Missing macro name to `define'");
685 goto jerr;
687 if (args[1] == NULL || strcmp(args[1], "{") || args[2] != NULL) {
688 errs = tr(505, "Syntax is: define <name> {");
689 goto jerr;
691 rv = ! _define1(args[0], MA_NONE);
692 jleave:
693 return rv;
694 jerr:
695 fprintf(stderr, "%s\n", errs);
696 goto jleave;
699 FL int
700 cundef(void *v)
702 int rv = 1;
703 char **args = v;
705 if (*args == NULL) {
706 fprintf(stderr, tr(506, "Missing macro name to `undef'\n"));
707 goto jleave;
710 _undef1(*args, MA_NONE);
711 while (*++args);
712 rv = 0;
713 jleave:
714 return rv;
717 FL int
718 ccall(void *v)
720 int rv = 1;
721 char **args = v;
722 char const *errs, *name;
723 struct macro *mp;
725 if (args[0] == NULL || (args[1] != NULL && args[2] != NULL)) {
726 errs = tr(507, "Syntax is: call <%s>\n");
727 name = "name";
728 goto jerr;
731 if ((mp = _malook(*args, NULL, MA_NONE)) == NULL) {
732 errs = tr(508, "Undefined macro called: \"%s\"\n");
733 name = *args;
734 goto jerr;
737 rv = _maexec(mp, NULL);
738 jleave:
739 return rv;
740 jerr:
741 fprintf(stderr, errs, name);
742 goto jleave;
745 FL int
746 callhook(char const *name, int nmail)
748 int len, rv;
749 struct macro *mp;
750 char *var, *cp;
752 var = ac_alloc(len = strlen(name) + 13);
753 snprintf(var, len, "folder-hook-%s", name);
754 if ((cp = value(var)) == NULL && (cp = value("folder-hook")) == NULL) {
755 rv = 0;
756 goto jleave;
758 if ((mp = _malook(cp, NULL, MA_NONE)) == NULL) {
759 fprintf(stderr, tr(49, "Cannot call hook for folder \"%s\": "
760 "Macro \"%s\" does not exist.\n"), name, cp);
761 rv = 1;
762 goto jleave;
765 inhook = nmail ? 3 : 1;
766 rv = _maexec(mp, NULL);
767 inhook = 0;
768 jleave:
769 ac_free(var);
770 return rv;
773 FL int
774 cdefines(void *v)
776 (void)v;
777 return _list_macros(MA_NONE);
780 FL int
781 c_account(void *v)
783 char **args = v;
784 struct macro *mp;
785 int rv = 1, i, oqf, nqf;
787 if (args[0] == NULL) {
788 rv = _list_macros(MA_ACC);
789 goto jleave;
792 if (args[1] && args[1][0] == '{' && args[1][1] == '\0') {
793 if (args[2] != NULL) {
794 fprintf(stderr, tr(517, "Syntax is: account <name> {\n"));
795 goto jleave;
797 if (asccasecmp(args[0], ACCOUNT_NULL) == 0) {
798 fprintf(stderr, tr(521, "Error: `%s' is a reserved name.\n"),
799 ACCOUNT_NULL);
800 goto jleave;
802 rv = ! _define1(args[0], MA_ACC);
803 goto jleave;
806 if (inhook) {
807 fprintf(stderr, tr(518, "Cannot change account from within a hook.\n"));
808 goto jleave;
811 save_mbox_for_possible_quitstuff();
813 mp = NULL;
814 if (asccasecmp(args[0], ACCOUNT_NULL) != 0 &&
815 (mp = _malook(args[0], NULL, MA_ACC)) == NULL) {
816 fprintf(stderr, tr(519, "Account `%s' does not exist.\n"), args[0]);
817 goto jleave;
820 oqf = savequitflags();
821 if (_acc_curr != NULL)
822 _localopts_unroll(&_acc_curr->ma_localopts);
823 account_name = (mp != NULL) ? mp->ma_name : NULL;
824 _acc_curr = mp;
826 if (mp != NULL && _maexec(mp, &mp->ma_localopts) == CBAD) {
827 /* XXX account switch incomplete, unroll? */
828 fprintf(stderr, tr(520, "Switching to account `%s' failed.\n"), args[0]);
829 goto jleave;
832 if (! starting && ! inhook) {
833 nqf = savequitflags(); /* TODO obsolete (leave -> void -> new box!) */
834 restorequitflags(oqf);
835 if ((i = setfile("%", 0)) < 0)
836 goto jleave;
837 callhook(mailname, 0);
838 if (i > 0 && ! boption("emptystart"))
839 goto jleave;
840 announce(boption("bsdcompat") || boption("bsdannounce"));
841 restorequitflags(nqf);
843 rv = 0;
844 jleave:
845 return rv;
848 FL int
849 c_localopts(void *v)
851 int rv = 1;
852 char **c = v;
854 if (_localopts == NULL) {
855 fprintf(stderr, tr(522,
856 "Cannot use `localopts' but from within a `define' or `account'\n"));
857 goto jleave;
860 _localopts->s_unroll = (**c == '0') ? FAL0 : TRU1;
861 rv = 0;
862 jleave:
863 return rv;
866 /* vim:set fenc=utf-8:s-it-mode */