nail.1: show possibility for more *verbose* output early
[s-mailx.git] / message.c
blob1b3fd86cdf6257b4dfd4d343b5911dce381ae485
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Message, message array, getmsglist(), and related operations.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2016 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 #undef n_FILE
36 #define n_FILE message
38 #ifndef HAVE_AMALGAMATION
39 # include "nail.h"
40 #endif
42 /* Token values returned by the scanner used for argument lists.
43 * Also, sizes of scanner-related things */
44 enum a_message_token{
45 a_MESSAGE_T_EOL, /* End of the command line */
46 a_MESSAGE_T_NUMBER, /* Message number */
47 a_MESSAGE_T_MINUS, /* - */
48 a_MESSAGE_T_STRING, /* A string (possibly containing -) */
49 a_MESSAGE_T_DOT, /* . */
50 a_MESSAGE_T_UP, /* ^ */
51 a_MESSAGE_T_DOLLAR, /* $ */
52 a_MESSAGE_T_ASTER, /* * */
53 a_MESSAGE_T_OPEN, /* ( */
54 a_MESSAGE_T_CLOSE, /* ) */
55 a_MESSAGE_T_PLUS, /* + */
56 a_MESSAGE_T_COMMA, /* , */
57 a_MESSAGE_T_SEMI, /* ; */
58 a_MESSAGE_T_BACK, /* ` */
59 a_MESSAGE_T_ERROR /* Lexical error */
62 enum a_message_idfield{
63 a_MESSAGE_ID_REFERENCES,
64 a_MESSAGE_ID_IN_REPLY_TO
67 enum a_message_state{
68 a_MESSAGE_S_NEW = 1<<0,
69 a_MESSAGE_S_OLD = 1<<1,
70 a_MESSAGE_S_UNREAD = 1<<2,
71 a_MESSAGE_S_DELETED = 1<<3,
72 a_MESSAGE_S_READ = 1<<4,
73 a_MESSAGE_S_FLAG = 1<<5,
74 a_MESSAGE_S_ANSWERED = 1<<6,
75 a_MESSAGE_S_DRAFT = 1<<7,
76 a_MESSAGE_S_SPAM = 1<<8,
77 a_MESSAGE_S_SPAMUNSURE = 1<<9
80 struct a_message_coltab{
81 char mco_char; /* What to find past : */
82 ui8_t mco__dummy[3];
83 int mco_bit; /* Associated modifier bit */
84 int mco_mask; /* m_status bits to mask */
85 int mco_equal; /* ... must equal this */
88 struct a_message_lex{
89 char ml_char;
90 ui8_t ml_token;
93 static struct a_message_coltab const a_message_coltabs[] = {
94 {'n', {0,}, a_MESSAGE_S_NEW, MNEW, MNEW},
95 {'o', {0,}, a_MESSAGE_S_OLD, MNEW, 0},
96 {'u', {0,}, a_MESSAGE_S_UNREAD, MREAD, 0},
97 {'d', {0,}, a_MESSAGE_S_DELETED, MDELETED, MDELETED},
98 {'r', {0,}, a_MESSAGE_S_READ, MREAD, MREAD},
99 {'f', {0,}, a_MESSAGE_S_FLAG, MFLAGGED, MFLAGGED},
100 {'a', {0,}, a_MESSAGE_S_ANSWERED, MANSWERED, MANSWERED},
101 {'t', {0,}, a_MESSAGE_S_DRAFT, MDRAFTED, MDRAFTED},
102 {'s', {0,}, a_MESSAGE_S_SPAM, MSPAM, MSPAM},
103 {'S', {0,}, a_MESSAGE_S_SPAMUNSURE, MSPAMUNSURE, MSPAMUNSURE}
106 static struct a_message_lex const a_message_singles[] = {
107 {'$', a_MESSAGE_T_DOLLAR},
108 {'.', a_MESSAGE_T_DOT},
109 {'^', a_MESSAGE_T_UP},
110 {'*', a_MESSAGE_T_ASTER},
111 {'-', a_MESSAGE_T_MINUS},
112 {'+', a_MESSAGE_T_PLUS},
113 {'(', a_MESSAGE_T_OPEN},
114 {')', a_MESSAGE_T_CLOSE},
115 {',', a_MESSAGE_T_COMMA},
116 {';', a_MESSAGE_T_SEMI},
117 {'`', a_MESSAGE_T_BACK}
120 /* Slots in ::message */
121 static size_t a_message_mem_space;
123 /* Mark entire threads */
124 static bool_t a_message_threadflag;
126 /* :d on its way HACK TODO */
127 static bool_t a_message_list_saw_d, a_message_list_last_saw_d;
129 /* String from a_MESSAGE_T_STRING, scan() */
130 static struct str a_message_lexstr;
131 /* Number of a_MESSAGE_T_NUMBER from scan() */
132 static int a_message_lexno;
134 /* Lazy load message header fields */
135 static enum okay a_message_get_header(struct message *mp);
137 /* Append, taking care of resizes TODO vector */
138 static char **a_message_add_to_namelist(char ***namelist, size_t *nmlsize,
139 char **np, char *string);
141 /* Mark all messages that the user wanted from the command line in the message
142 * structure. Return 0 on success, -1 on error */
143 static int a_message_markall(char *buf, int f);
145 /* Turn the character after a colon modifier into a bit value */
146 static int a_message_evalcol(int col);
148 /* Check the passed message number for legality and proper flags. Unless f is
149 * MDELETED the message has to be undeleted */
150 static bool_t a_message_check(int mno, int f);
152 /* Scan out a single lexical item and return its token number, updating the
153 * string pointer passed *sp. Also, store the value of the number or string
154 * scanned in a_message_lexno or a_message_lexstr as appropriate.
155 * In any event, store the scanned "thing" in a_message_lexstr.
156 * Returns the token as a negative number when we also saw & to mark a thread */
157 static int a_message_scan(char **sp);
159 /* See if the passed name sent the passed message */
160 static bool_t a_message_match_sender(struct message *mp, char const *str,
161 bool_t allnet);
163 /* Check whether the given message-id or references match */
164 static bool_t a_message_match_mid(struct message *mp, char const *id,
165 enum a_message_idfield idfield);
167 /* See if the given string matches.
168 * For the purpose of the scan, we ignore case differences.
169 * This is the engine behind the "/" search */
170 static bool_t a_message_match_dash(struct message *mp, char const *str);
172 /* See if the given search expression matches.
173 * For the purpose of the scan, we ignore case differences.
174 * This is the engine behind the "@[..@].." search */
175 static bool_t a_message_match_at(struct message *mp, struct search_expr *sep);
177 /* Unmark the named message */
178 static void a_message_unmark(int mesg);
180 /* Return the message number corresponding to the passed meta character */
181 static int a_message_metamess(int meta, int f);
183 /* Helper for mark(): self valid, threading enabled */
184 static void a_message__threadmark(struct message *self, int f);
186 static enum okay
187 a_message_get_header(struct message *mp){
188 enum okay rv;
189 NYD2_ENTER;
190 UNUSED(mp);
192 switch(mb.mb_type){
193 case MB_FILE:
194 case MB_MAILDIR:
195 rv = OKAY;
196 break;
197 #ifdef HAVE_POP3
198 case MB_POP3:
199 rv = pop3_header(mp);
200 break;
201 #endif
202 case MB_VOID:
203 default:
204 rv = STOP;
205 break;
207 NYD2_LEAVE;
208 return rv;
211 static char **
212 a_message_add_to_namelist(char ***namelist, size_t *nmlsize, char **np,
213 char *string){
214 size_t idx;
215 NYD2_ENTER;
217 if((idx = PTR2SIZE(np - *namelist)) >= *nmlsize){
218 *namelist = srealloc(*namelist, (*nmlsize += 8) * sizeof *np);
219 np = &(*namelist)[idx];
221 *np++ = string;
222 NYD2_LEAVE;
223 return np;
226 static int
227 a_message_markall(char *buf, int f){
228 struct message *mp, *mx;
229 enum a_message_idfield idfield;
230 size_t j, nmlsize;
231 char const *id;
232 char **np, **nq, **namelist, *bufp, *cp;
233 int i, valdot, beg, colmod, tok, colresult;
234 enum{
235 a_NONE = 0,
236 a_ALLNET = 1u<<0, /* Must be TRU1 */
237 a_ALLOC = 1u<<1, /* Have allocated something */
238 a_THREADED = 1u<<2,
239 a_ERROR = 1u<<3,
240 a_ANY = 1u<<4, /* Have marked just ANY */
241 a_RANGE = 1u<<5, /* Seen dash, await close */
242 a_ASTER = 1u<<8,
243 a_TOPEN = 1u<<9, /* ( used (and didn't match) */
244 a_TBACK = 1u<<10, /* ` used (and didn't match) */
245 a_TMP = 1u<<15
246 } flags;
247 NYD_ENTER;
248 n_LCTA((ui32_t)a_ALLNET == (ui32_t)TRU1,
249 "Constant is converted to bool_t via AND, thus");
251 /* Update message array: clear MMARK but remember its former state for `.
252 * An empty selector input is identical to * asterisk */
253 for(i = msgCount; i-- > 0;){
254 enum mflag mf;
256 mf = (mp = &message[i])->m_flag;
257 if(mf & MMARK)
258 mf |= MOLDMARK;
259 else
260 mf &= ~MOLDMARK;
261 mf &= ~MMARK;
262 mp->m_flag = mf;
265 /* Strip all leading WS from user buffer */
266 while(blankspacechar(*buf))
267 ++buf;
268 /* If there is no input buffer, we are done! */
269 if(buf[0] == '\0'){
270 flags = a_NONE;
271 goto jleave;
274 UNINIT(beg, 0);
275 UNINIT(idfield, a_MESSAGE_ID_REFERENCES);
276 a_message_threadflag = FAL0;
277 a_message_lexstr.s = ac_alloc(a_message_lexstr.l = 2 * strlen(buf) +1);
278 np = namelist = smalloc((nmlsize = 8) * sizeof *namelist); /* TODO vector */
279 bufp = buf;
280 valdot = (int)PTR2SIZE(dot - message + 1);
281 colmod = 0;
282 id = NULL;
283 flags = a_ALLOC | (mb.mb_threaded ? a_THREADED : 0);
285 while((tok = a_message_scan(&bufp)) != a_MESSAGE_T_EOL){
286 if((a_message_threadflag = (tok < 0)))
287 tok &= INT_MAX;
289 switch(tok){
290 case a_MESSAGE_T_NUMBER:
291 pstate |= PS_MSGLIST_GABBY;
292 jnumber:
293 if(flags & a_RANGE){
294 int i_base;
296 flags ^= a_RANGE;
298 if(!a_message_check(a_message_lexno, f))
299 goto jerr;
300 if(beg < a_message_lexno){
301 i = beg;
302 beg = 1; /* TODO does not work: (i < a_message_lexno)
303 * TODO we need to detect whether both ends of a range
304 * TODO belong to the same thread first, then iterate
305 * TODO over the subset in between those points */
306 }else{
307 i = a_message_lexno;
308 a_message_lexno = beg;
311 /* Problem: until the TODO above can be worked and we simply get an
312 * iterator object for the thread (-range), we need to walk
313 * a threaded list two times */
314 i_base = (flags & a_THREADED) ? i : -1;
315 jnumber__thr:
316 while((flags & a_THREADED) || i <= a_message_lexno){
317 mp = &message[i - 1];
318 if(i_base < 0 && !(mp->m_flag & MHIDDEN) &&
319 (f == MDELETED || !(mp->m_flag & MDELETED))){
320 mark(i, f);
321 flags |= a_ANY;
323 if(flags & a_THREADED){
324 if(i == a_message_lexno)
325 break;
326 mx = beg ? next_in_thread(mp) : prev_in_thread(mp);
327 if(mx == NULL){
328 id = N_("Range crosses multiple threads\n");
329 goto jerrmsg;
331 i = (int)PTR2SIZE(mx - message + 1);
332 }else
333 ++i;
335 if(i_base >= 0){
336 i = i_base;
337 i_base = -1;
338 goto jnumber__thr;
340 beg = 0;
341 break;
342 }else{
343 if(!a_message_check(a_message_lexno, f))
344 goto jerr;
345 /* Inclusive range? */
346 if(bufp[0] == '-'){
347 ++bufp;
348 beg = a_message_lexno;
349 flags |= a_RANGE;
350 }else{
351 mark(a_message_lexno, f);
352 flags |= a_ANY;
355 break;
356 case a_MESSAGE_T_PLUS:
357 pstate &= ~PS_MSGLIST_DIRECT;
358 pstate |= PS_MSGLIST_GABBY;
359 i = valdot;
361 if(flags & a_THREADED){
362 mx = next_in_thread(&message[i - 1]);
363 i = mx ? (int)PTR2SIZE(mx - message + 1) : msgCount + 1;
364 }else
365 ++i;
366 if(i > msgCount){
367 id = N_("Referencing beyond last message\n");
368 goto jerrmsg;
370 }while(message[i - 1].m_flag == MHIDDEN ||
371 (message[i - 1].m_flag & MDELETED) != (unsigned)f);
372 a_message_lexno = i;
373 goto jnumber;
374 case a_MESSAGE_T_MINUS:
375 pstate &= ~PS_MSGLIST_DIRECT;
376 pstate |= PS_MSGLIST_GABBY;
377 i = valdot;
379 if(flags & a_THREADED){
380 mx = prev_in_thread(&message[i - 1]);
381 i = mx ? (int)PTR2SIZE(mx - message + 1) : 0;
382 }else
383 --i;
384 if(i <= 0){
385 id = N_("Referencing before first message\n");
386 goto jerrmsg;
388 }while(message[i - 1].m_flag == MHIDDEN ||
389 (message[i - 1].m_flag & MDELETED) != (unsigned)f);
390 a_message_lexno = i;
391 goto jnumber;
392 case a_MESSAGE_T_STRING:
393 pstate &= ~PS_MSGLIST_DIRECT;
394 if(flags & a_RANGE)
395 goto jebadrange;
397 /* This may be a colon modifier */
398 if((cp = a_message_lexstr.s)[0] != ':')
399 np = a_message_add_to_namelist(&namelist, &nmlsize, np,
400 savestr(a_message_lexstr.s));
401 else{
402 while(*++cp != '\0'){
403 colresult = a_message_evalcol(*cp);
404 if(colresult == 0){
405 n_err(_("Unknown colon modifier: %s\n"), a_message_lexstr.s);
406 goto jerr;
408 if(colresult == a_MESSAGE_S_DELETED){
409 a_message_list_saw_d = TRU1;
410 f |= MDELETED;
412 colmod |= colresult;
415 break;
416 case a_MESSAGE_T_OPEN:
417 pstate &= ~PS_MSGLIST_DIRECT;
418 if(flags & a_RANGE)
419 goto jebadrange;
420 flags |= a_TOPEN;
422 #ifdef HAVE_IMAP_SEARCH
423 /* C99 */{
424 ssize_t ires;
426 if((ires = imap_search(a_message_lexstr.s, f)) >= 0){
427 if(ires > 0)
428 flags |= a_ANY;
429 break;
432 #else
433 n_err(_("Optional selector is not available: %s\n"),
434 a_message_lexstr.s);
435 #endif
436 goto jerr;
437 case a_MESSAGE_T_DOLLAR:
438 case a_MESSAGE_T_UP:
439 case a_MESSAGE_T_SEMI:
440 pstate |= PS_MSGLIST_GABBY;
441 /* FALLTHRU */
442 case a_MESSAGE_T_DOT: /* Don't set _GABBY for dot, to _allow_ history.. */
443 pstate &= ~PS_MSGLIST_DIRECT;
444 a_message_lexno = a_message_metamess(a_message_lexstr.s[0], f);
445 if(a_message_lexno == -1)
446 goto jerr;
447 goto jnumber;
448 case a_MESSAGE_T_BACK:
449 pstate &= ~PS_MSGLIST_DIRECT;
450 if(flags & a_RANGE)
451 goto jebadrange;
453 flags |= a_TBACK;
454 for(i = 0; i < msgCount; ++i){
455 if((mp = &message[i])->m_flag & MHIDDEN)
456 continue;
457 if((mp->m_flag & MDELETED) != (unsigned)f){
458 if(!a_message_list_last_saw_d)
459 continue;
460 a_message_list_saw_d = TRU1;
462 if(mp->m_flag & MOLDMARK){
463 mark(i + 1, f);
464 flags &= ~a_TBACK;
465 flags |= a_ANY;
468 break;
469 case a_MESSAGE_T_ASTER:
470 pstate &= ~PS_MSGLIST_DIRECT;
471 if(flags & a_RANGE)
472 goto jebadrange;
473 flags |= a_ASTER;
474 break;
475 case a_MESSAGE_T_COMMA:
476 pstate &= ~PS_MSGLIST_DIRECT;
477 pstate |= PS_MSGLIST_GABBY;
478 if(flags & a_RANGE)
479 goto jebadrange;
481 if(id == NULL){
482 if((cp = hfield1("in-reply-to", dot)) != NULL)
483 idfield = a_MESSAGE_ID_IN_REPLY_TO;
484 else if((cp = hfield1("references", dot)) != NULL){
485 struct name *enp;
487 if((enp = extract(cp, GREF)) != NULL){
488 while(enp->n_flink != NULL)
489 enp = enp->n_flink;
490 cp = enp->n_name;
491 idfield = a_MESSAGE_ID_REFERENCES;
492 }else
493 cp = NULL;
496 if(cp != NULL)
497 id = savestr(cp);
498 else{
499 id = N_("Message-ID of parent of \"dot\" is indeterminable\n");
500 goto jerrmsg;
502 }else if(!(pstate & PS_HOOK) && (options & OPT_D_V))
503 n_err(_("Ignoring redundant specification of , selector\n"));
504 break;
505 case a_MESSAGE_T_ERROR:
506 pstate &= ~PS_MSGLIST_DIRECT;
507 pstate |= PS_MSGLIST_GABBY;
508 goto jerr;
511 /* Explicitly disallow invalid ranges for future safety */
512 if(bufp[0] == '-' && !(flags & a_RANGE)){
513 if(!(pstate & PS_HOOK))
514 n_err(_("Ignoring invalid range before: %s\n"), bufp);
515 ++bufp;
518 if(flags & a_RANGE){
519 id = N_("Missing second range argument\n");
520 goto jerrmsg;
523 np = a_message_add_to_namelist(&namelist, &nmlsize, np, NULL);
524 --np;
526 /* * is special at this point, after we have parsed the entire line */
527 if(flags & a_ASTER){
528 for(i = 0; i < msgCount; ++i){
529 if((mp = &message[i])->m_flag & MHIDDEN)
530 continue;
531 if(!a_message_list_saw_d && (mp->m_flag & MDELETED) != (unsigned)f)
532 continue;
533 mark(i + 1, f);
534 flags |= a_ANY;
536 if(!(flags & a_ANY))
537 goto jenoapp;
538 goto jleave;
541 /* If any names were given, add any messages which match */
542 if(np > namelist || id != NULL){
543 struct search_expr *sep = NULL;
545 /* The @ search works with struct search_expr, so build an array.
546 * To simplify array, i.e., regex_t destruction, and optimize for the
547 * common case we walk the entire array even in case of errors */
548 if(np > namelist){
549 sep = scalloc(PTR2SIZE(np - namelist), sizeof(*sep));
550 for(j = 0, nq = namelist; *nq != NULL; ++j, ++nq){
551 char *x, *y;
553 sep[j].ss_sexpr = x = *nq;
554 if(*x != '@' || (flags & a_ERROR))
555 continue;
557 for(y = &x[1];; ++y){
558 if(*y == '\0' || !fieldnamechar(*y)){
559 x = NULL;
560 break;
562 if(*y == '@'){
563 x = y;
564 break;
567 sep[j].ss_where = (x == NULL || x - 1 == *nq)
568 ? "subject" : savestrbuf(&(*nq)[1], PTR2SIZE(x - *nq) - 1);
570 x = (x == NULL ? *nq : x) + 1;
571 if(*x == '\0'){ /* XXX Simply remove from list instead? */
572 n_err(_("Empty [@..]@ search expression\n"));
573 flags |= a_ERROR;
574 continue;
576 #ifdef HAVE_REGEX
577 if(is_maybe_regex(x)){
578 sep[j].ss_sexpr = NULL;
579 if(regcomp(&sep[j].ss_regex, x,
580 REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0){
581 if(!(pstate & PS_HOOK) && (options & OPT_D_V))
582 n_err(_("Invalid regular expression: >>> %s <<<\n"), x);
583 flags |= a_ERROR;
584 continue;
586 }else
587 #endif
588 sep[j].ss_sexpr = x;
590 if(flags & a_ERROR)
591 goto jnamesearch_sepfree;
594 /* Iterate the entire message array */
595 srelax_hold();
596 if(ok_blook(allnet))
597 flags |= a_ALLNET;
598 for(i = 0; i < msgCount; ++i){
599 if((mp = &message[i])->m_flag & (MMARK | MHIDDEN))
600 continue;
601 if(!a_message_list_saw_d && (mp->m_flag & MDELETED) != (unsigned)f)
602 continue;
604 flags &= ~a_TMP;
605 if(np > namelist){
606 for(nq = namelist; *nq != NULL; ++nq){
607 if(**nq == '@'){
608 if(a_message_match_at(mp, sep + PTR2SIZE(nq - namelist))){
609 flags |= a_TMP;
610 break;
612 }else if(**nq == '/'){
613 if(a_message_match_dash(mp, *nq)){
614 flags |= a_TMP;
615 break;
617 }else if(a_message_match_sender(mp, *nq, (flags & a_ALLNET))){
618 flags |= a_TMP;
619 break;
623 if(!(flags & a_TMP) &&
624 id != NULL && a_message_match_mid(mp, id, idfield))
625 flags |= a_TMP;
627 if(flags & a_TMP){
628 mark(i + 1, f);
629 flags |= a_ANY;
631 srelax();
633 srelax_rele();
635 jnamesearch_sepfree:
636 if(sep != NULL){
637 #ifdef HAVE_REGEX
638 for(j = PTR2SIZE(np - namelist); j-- != 0;)
639 if(sep[j].ss_sexpr == NULL)
640 regfree(&sep[j].ss_regex);
641 #endif
642 free(sep);
644 if(flags & a_ERROR)
645 goto jerr;
648 /* If any colon modifiers were given, go through and mark any messages which
649 * do satisfy the modifiers */
650 if(colmod != 0){
651 for(i = 0; i < msgCount; ++i){
652 struct a_message_coltab const *colp;
654 if((mp = &message[i])->m_flag & MMARK)
655 continue;
657 for(colp = a_message_coltabs;
658 PTRCMP(colp, <, &a_message_coltabs[NELEM(a_message_coltabs)]);
659 ++colp)
660 if((colp->mco_bit & colmod) &&
661 ((mp->m_flag & colp->mco_mask) == (unsigned)colp->mco_equal)){
662 mark(i + 1, f);
663 flags |= a_ANY;
664 break;
669 /* It shall be an error if ` didn't match anything, and nothing else did */
670 if((flags & (a_TBACK | a_ANY)) == a_TBACK){
671 id = N_("No previously marked messages\n");
672 goto jerrmsg;
673 }else if(!(flags & a_ANY))
674 goto jenoapp;
676 assert(!(flags & a_ERROR));
677 jleave:
678 if(flags & a_ALLOC){
679 free(namelist);
680 ac_free(a_message_lexstr.s);
682 NYD_LEAVE;
683 return (flags & a_ERROR) ? -1 : 0;
685 jebadrange:
686 id = N_("Invalid range endpoint\n");
687 goto jerrmsg;
688 jenoapp:
689 id = N_("No applicable messages\n");
690 jerrmsg:
691 if(!(pstate & PS_HOOK_MASK))
692 n_err(V_(id));
693 jerr:
694 flags |= a_ERROR;
695 goto jleave;
698 static int
699 a_message_evalcol(int col){
700 struct a_message_coltab const *colp;
701 int rv;
702 NYD2_ENTER;
704 rv = 0;
705 for(colp = a_message_coltabs;
706 PTRCMP(colp, <, &a_message_coltabs[NELEM(a_message_coltabs)]); ++colp)
707 if(colp->mco_char == col){
708 rv = colp->mco_bit;
709 break;
711 NYD2_LEAVE;
712 return rv;
715 static bool_t
716 a_message_check(int mno, int f){
717 struct message *mp;
718 NYD2_ENTER;
720 if(mno < 1 || mno > msgCount){
721 n_err(_("%d: Invalid message number\n"), mno);
722 mno = 1;
723 }else if(((mp = &message[mno - 1])->m_flag & MHIDDEN) ||
724 (f != MDELETED && (mp->m_flag & MDELETED) != 0))
725 n_err(_("%d: inappropriate message\n"), mno);
726 else
727 mno = 0;
728 NYD2_LEAVE;
729 return (mno == 0);
732 static int
733 a_message_scan(char **sp)
735 char *cp, *cp2;
736 struct a_message_lex const *lp;
737 int rv, c, inquote, quotec;
738 NYD_ENTER;
740 rv = a_MESSAGE_T_EOL;
742 cp = *sp;
743 cp2 = a_message_lexstr.s;
744 c = *cp++;
746 /* strip away leading white space */
747 while(blankchar(c))
748 c = *cp++;
750 /* If no characters remain, we are at end of line, so report that */
751 if(c == '\0'){
752 *sp = --cp;
753 goto jleave;
756 /* Select members of a message thread */
757 if(c == '&'){
758 if(*cp == '\0' || spacechar(*cp)){
759 a_message_lexstr.s[0] = '.';
760 a_message_lexstr.s[1] = '\0';
761 *sp = cp;
762 rv = a_MESSAGE_T_DOT | INT_MIN;
763 goto jleave;
765 rv = INT_MIN;
766 c = *cp++;
769 /* If the leading character is a digit, scan the number and convert it
770 * on the fly. Return a_MESSAGE_T_NUMBER when done */
771 if(digitchar(c)){
772 a_message_lexno = 0;
774 a_message_lexno = (a_message_lexno * 10) + c - '0';
775 *cp2++ = c;
776 }while((c = *cp++, digitchar(c)));
777 *cp2 = '\0';
778 *sp = --cp;
779 rv |= a_MESSAGE_T_NUMBER;
780 goto jleave;
783 /* An IMAP SEARCH list. Note that a_MESSAGE_T_OPEN has always been included
784 * in singles[] in Mail and mailx. Thus although there is no formal
785 * definition for (LIST) lists, they do not collide with historical
786 * practice because a subject string (LIST) could never been matched
787 * this way */
788 if (c == '(') {
789 ui32_t level = 1;
790 inquote = 0;
791 *cp2++ = c;
792 do {
793 if ((c = *cp++&0377) == '\0') {
794 jmtop:
795 n_err(_("Missing )\n"));
796 rv = a_MESSAGE_T_ERROR;
797 goto jleave;
799 if (inquote && c == '\\') {
800 *cp2++ = c;
801 c = *cp++&0377;
802 if (c == '\0')
803 goto jmtop;
804 } else if (c == '"')
805 inquote = !inquote;
806 else if (inquote)
807 /*EMPTY*/;
808 else if (c == '(')
809 ++level;
810 else if (c == ')')
811 --level;
812 else if (spacechar(c)) {
813 /* Replace unquoted whitespace by single space characters, to make
814 * the string IMAP SEARCH conformant */
815 c = ' ';
816 if (cp2[-1] == ' ')
817 --cp2;
819 *cp2++ = c;
820 } while (c != ')' || level > 0);
821 *cp2 = '\0';
822 *sp = cp;
823 rv |= a_MESSAGE_T_OPEN;
824 goto jleave;
827 /* Check for single character tokens; return such if found */
828 for(lp = a_message_singles;
829 PTRCMP(lp, <, &a_message_singles[NELEM(a_message_singles)]); ++lp)
830 if(c == lp->ml_char){
831 a_message_lexstr.s[0] = c;
832 a_message_lexstr.s[1] = '\0';
833 *sp = cp;
834 rv |= lp->ml_token;
835 goto jleave;
838 /* We've got a string! Copy all the characters of the string into
839 * a_message_lexstr, until we see a null, space, or tab. If the lead
840 * character is a " or ', save it and scan until you get another */
841 quotec = 0;
842 if (c == '\'' || c == '"') {
843 quotec = c;
844 c = *cp++;
846 while (c != '\0') {
847 if (quotec == 0 && c == '\\' && *cp != '\0')
848 c = *cp++;
849 if (c == quotec) {
850 ++cp;
851 break;
853 if (quotec == 0 && blankchar(c))
854 break;
855 if (PTRCMP(cp2 - a_message_lexstr.s, <, a_message_lexstr.l))
856 *cp2++ = c;
857 c = *cp++;
859 if (quotec && c == 0) {
860 n_err(_("Missing %c\n"), quotec);
861 rv = a_MESSAGE_T_ERROR;
862 goto jleave;
864 *sp = --cp;
865 *cp2 = '\0';
866 rv |= a_MESSAGE_T_STRING;
867 jleave:
868 NYD_LEAVE;
869 return rv;
872 static bool_t
873 a_message_match_sender(struct message *mp, char const *str, bool_t allnet){
874 char const *str_base, *np_base, *np;
875 char sc, nc;
876 bool_t rv;
877 NYD2_ENTER;
879 /* Empty string doesn't match */
880 if(*(str_base = str) == '\0'){
881 rv = FAL0;
882 goto jleave;
885 /* *allnet* is POSIX and, since it explicitly mentions login and user names,
886 * most likely case-sensitive. XXX Still allow substr matching, though
887 * XXX possibly the first letter should be case-insensitive, then? */
888 if(allnet){
889 for(np_base = np = nameof(mp, 0);;){
890 if((sc = *str++) == '@')
891 sc = '\0';
892 if((nc = *np++) == '@' || nc == '\0' || sc == '\0')
893 break;
894 if(sc != nc){
895 np = ++np_base;
896 str = str_base;
899 rv = (sc == '\0');
900 }else{
901 /* TODO POSIX says ~"match any address as shown in header overview",
902 * TODO but a normalized match would be more sane i guess.
903 * TODO struct name should gain a comparison method, normalize realname
904 * TODO content (in TODO) and thus match as likewise
905 * TODO "Buddy (Today) <here>" and "(Now) Buddy <here>" */
906 char const *real_base;
907 bool_t again;
909 real_base = name1(mp, 0);
910 again = ok_blook(showname);
911 jagain:
912 np_base = np = again ? realname(real_base) : skin(real_base);
913 str = str_base;
914 for(;;){
915 sc = *str++;
916 if((nc = *np++) == '\0' || sc == '\0')
917 break;
918 sc = upperconv(sc);
919 nc = upperconv(nc);
920 if(sc != nc){
921 np = ++np_base;
922 str = str_base;
926 /* And really if i want to match 'on@' then i want it to match even if
927 * *showname* is set! */
928 if(!(rv = (sc == '\0')) && again){
929 again = FAL0;
930 goto jagain;
933 jleave:
934 NYD2_LEAVE;
935 return rv;
938 static bool_t
939 a_message_match_mid(struct message *mp, char const *id,
940 enum a_message_idfield idfield){
941 char const *cp;
942 bool_t rv;
943 NYD2_ENTER;
945 rv = FAL0;
947 if((cp = hfield1("message-id", mp)) != NULL){
948 switch(idfield){
949 case a_MESSAGE_ID_REFERENCES:
950 if(!msgidcmp(id, cp))
951 rv = TRU1;
952 break;
953 case a_MESSAGE_ID_IN_REPLY_TO:{
954 struct name *np;
956 if((np = extract(id, GREF)) != NULL)
958 if(!msgidcmp(np->n_name, cp)){
959 rv = TRU1;
960 break;
962 }while((np = np->n_flink) != NULL);
963 break;
967 NYD2_LEAVE;
968 return rv;
971 static bool_t
972 a_message_match_dash(struct message *mp, char const *str){
973 static char lastscan[128];
975 struct str in, out;
976 char *hfield, *hbody;
977 bool_t rv;
978 NYD2_ENTER;
980 rv = FAL0;
982 if(*++str == '\0')
983 str = lastscan;
984 else
985 n_strscpy(lastscan, str, sizeof lastscan); /* XXX use new n_str object! */
987 /* Now look, ignoring case, for the word in the string */
988 if(ok_blook(searchheaders) && (hfield = strchr(str, ':'))){
989 size_t l;
991 l = PTR2SIZE(hfield - str);
992 hfield = ac_alloc(l +1);
993 memcpy(hfield, str, l);
994 hfield[l] = '\0';
995 hbody = hfieldX(hfield, mp);
996 ac_free(hfield);
997 hfield = UNCONST(str + l + 1);
998 }else{
999 hfield = UNCONST(str);
1000 hbody = hfield1("subject", mp);
1002 if(hbody == NULL)
1003 goto jleave;
1005 in.l = strlen(in.s = hbody);
1006 mime_fromhdr(&in, &out, TD_ICONV);
1007 rv = substr(out.s, hfield);
1008 free(out.s);
1009 jleave:
1010 NYD2_LEAVE;
1011 return rv;
1014 static bool_t
1015 a_message_match_at(struct message *mp, struct search_expr *sep){
1016 struct str in, out;
1017 char *nfield;
1018 char const *cfield;
1019 bool_t rv;
1020 NYD2_ENTER;
1022 rv = FAL0;
1023 nfield = savestr(sep->ss_where);
1025 while((cfield = n_strsep(&nfield, ',', TRU1)) != NULL){
1026 if(!asccasecmp(cfield, "body") ||
1027 (cfield[1] == '\0' && cfield[0] == '>')){
1028 rv = FAL0;
1029 jmsg:
1030 if((rv = message_match(mp, sep, rv)))
1031 break;
1032 continue;
1033 }else if(!asccasecmp(cfield, "text") ||
1034 (cfield[1] == '\0' && cfield[0] == '=')){
1035 rv = TRU1;
1036 goto jmsg;
1039 if(!asccasecmp(cfield, "header") ||
1040 (cfield[1] == '\0' && cfield[0] == '<')){
1041 if((rv = header_match(mp, sep)))
1042 break;
1043 continue;
1046 /* This is not a special name, so take care for the "skin" prefix !
1047 * and possible abbreviations */
1048 /* C99 */{
1049 struct name *np;
1050 bool_t doskin;
1052 if((doskin = (*cfield == '~')))
1053 ++cfield;
1054 if(cfield[0] != '\0' && cfield[1] == '\0'){
1055 char const x[][8] = {"from", "to", "cc", "bcc", "subject"};
1056 size_t i;
1057 char c1;
1059 c1 = lowerconv(cfield[0]);
1060 for(i = 0; i < NELEM(x); ++i){
1061 if(c1 == x[i][0]){
1062 cfield = x[i];
1063 break;
1067 if((in.s = hfieldX(cfield, mp)) == NULL)
1068 continue;
1070 /* Shall we split into address list and match the addresses only? */
1071 if(doskin){
1072 np = lextract(in.s, GSKIN);
1073 if(np == NULL)
1074 continue;
1075 out.s = np->n_name;
1076 }else{
1077 np = NULL;
1078 in.l = strlen(in.s);
1079 mime_fromhdr(&in, &out, TD_ICONV);
1082 jnext_name:
1083 #ifdef HAVE_REGEX
1084 if(sep->ss_sexpr == NULL)
1085 rv = (regexec(&sep->ss_regex, out.s, 0,NULL, 0) != REG_NOMATCH);
1086 else
1087 #endif
1088 rv = substr(out.s, sep->ss_sexpr);
1089 if(np == NULL)
1090 free(out.s);
1091 if(rv)
1092 break;
1093 if(np != NULL && (np = np->n_flink) != NULL){
1094 out.s = np->n_name;
1095 goto jnext_name;
1099 NYD2_LEAVE;
1100 return rv;
1103 static void
1104 a_message_unmark(int mesg){
1105 size_t i;
1106 NYD2_ENTER;
1108 i = (size_t)mesg;
1109 if(i < 1 || UICMP(z, i, >, msgCount))
1110 n_panic(_("Bad message number to unmark"));
1111 message[--i].m_flag &= ~MMARK;
1112 NYD2_LEAVE;
1115 static int
1116 a_message_metamess(int meta, int f)
1118 int c, m;
1119 struct message *mp;
1120 NYD2_ENTER;
1122 c = meta;
1123 switch (c) {
1124 case '^': /* First 'good' message left */
1125 mp = mb.mb_threaded ? threadroot : message;
1126 while (PTRCMP(mp, <, message + msgCount)) {
1127 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & MDELETED) == (ui32_t)f) {
1128 c = (int)PTR2SIZE(mp - message + 1);
1129 goto jleave;
1131 if (mb.mb_threaded) {
1132 mp = next_in_thread(mp);
1133 if (mp == NULL)
1134 break;
1135 } else
1136 ++mp;
1138 if (!(pstate & PS_HOOK_MASK))
1139 n_err(_("No applicable messages\n"));
1140 goto jem1;
1142 case '$': /* Last 'good message left */
1143 mp = mb.mb_threaded
1144 ? this_in_thread(threadroot, -1) : message + msgCount - 1;
1145 while (mp >= message) {
1146 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & MDELETED) == (ui32_t)f) {
1147 c = (int)PTR2SIZE(mp - message + 1);
1148 goto jleave;
1150 if (mb.mb_threaded) {
1151 mp = prev_in_thread(mp);
1152 if (mp == NULL)
1153 break;
1154 } else
1155 --mp;
1157 if (!(pstate & PS_HOOK_MASK))
1158 n_err(_("No applicable messages\n"));
1159 goto jem1;
1161 case '.':
1162 /* Current message */
1163 m = dot - message + 1;
1164 if ((dot->m_flag & MHIDDEN) || (dot->m_flag & MDELETED) != (ui32_t)f) {
1165 n_err(_("%d: inappropriate message\n"), m);
1166 goto jem1;
1168 c = m;
1169 break;
1171 case ';':
1172 /* Previously current message */
1173 if (prevdot == NULL) {
1174 n_err(_("No previously current message\n"));
1175 goto jem1;
1177 m = prevdot - message + 1;
1178 if ((prevdot->m_flag & MHIDDEN) ||
1179 (prevdot->m_flag & MDELETED) != (ui32_t)f) {
1180 n_err(_("%d: inappropriate message\n"), m);
1181 goto jem1;
1183 c = m;
1184 break;
1186 default:
1187 n_err(_("Unknown selector: %c\n"), c);
1188 goto jem1;
1190 jleave:
1191 NYD2_LEAVE;
1192 return c;
1193 jem1:
1194 c = -1;
1195 goto jleave;
1198 static void
1199 a_message__threadmark(struct message *self, int f){
1200 NYD2_ENTER;
1201 if(!(self->m_flag & MHIDDEN) &&
1202 (f == MDELETED || !(self->m_flag & MDELETED) || a_message_list_saw_d))
1203 self->m_flag |= MMARK;
1205 if((self = self->m_child) != NULL){
1206 goto jcall;
1207 while((self = self->m_younger) != NULL)
1208 if(self->m_child != NULL)
1209 jcall:
1210 a_message__threadmark(self, f);
1211 else
1212 self->m_flag |= MMARK;
1214 NYD2_LEAVE;
1217 FL FILE *
1218 setinput(struct mailbox *mp, struct message *m, enum needspec need){
1219 FILE *rv;
1220 enum okay ok;
1221 NYD_ENTER;
1223 rv = NULL;
1224 ok = STOP;
1226 switch(need){
1227 case NEED_HEADER:
1228 ok = (m->m_have & HAVE_HEADER) ? OKAY : a_message_get_header(m);
1229 break;
1230 case NEED_BODY:
1231 ok = (m->m_have & HAVE_BODY) ? OKAY : get_body(m);
1232 break;
1233 case NEED_UNSPEC:
1234 ok = OKAY;
1235 break;
1237 if(ok != OKAY)
1238 goto jleave;
1240 fflush(mp->mb_otf);
1241 if(fseek(mp->mb_itf, (long)mailx_positionof(m->m_block, m->m_offset),
1242 SEEK_SET) == -1){
1243 n_perr(_("fseek"), 0);
1244 n_panic(_("temporary file seek"));
1246 rv = mp->mb_itf;
1247 jleave:
1248 NYD_LEAVE;
1249 return rv;
1252 FL enum okay
1253 get_body(struct message *mp){
1254 enum okay rv;
1255 NYD_ENTER;
1256 UNUSED(mp);
1258 switch(mb.mb_type){
1259 case MB_FILE:
1260 case MB_MAILDIR:
1261 rv = OKAY;
1262 break;
1263 #ifdef HAVE_POP3
1264 case MB_POP3:
1265 rv = pop3_body(mp);
1266 break;
1267 #endif
1268 case MB_VOID:
1269 default:
1270 rv = STOP;
1271 break;
1273 NYD_LEAVE;
1274 return rv;
1277 FL void
1278 message_reset(void){
1279 NYD_ENTER;
1280 if(message != NULL){
1281 free(message);
1282 message = NULL;
1284 msgCount = 0;
1285 a_message_mem_space = 0;
1286 NYD_LEAVE;
1289 FL void
1290 message_append(struct message *mp){
1291 NYD_ENTER;
1292 if(UICMP(z, msgCount + 1, >=, a_message_mem_space)){
1293 /* XXX remove _mem_space magics (or use s_Vector) */
1294 a_message_mem_space = ((a_message_mem_space >= 128 &&
1295 a_message_mem_space <= 1000000)
1296 ? a_message_mem_space << 1 : a_message_mem_space + 64);
1297 message = srealloc(message, a_message_mem_space * sizeof(*message));
1299 if(msgCount > 0){
1300 if(mp != NULL)
1301 message[msgCount - 1] = *mp;
1302 else
1303 memset(&message[msgCount - 1], 0, sizeof *message);
1305 NYD_LEAVE;
1308 FL void
1309 message_append_null(void){
1310 NYD_ENTER;
1311 if(msgCount == 0)
1312 message_append(NULL);
1313 setdot(message);
1314 message[msgCount].m_size = 0;
1315 message[msgCount].m_lines = 0;
1316 NYD_LEAVE;
1319 FL bool_t
1320 message_match(struct message *mp, struct search_expr const *sep,
1321 bool_t with_headers){
1322 char **line;
1323 size_t *linesize, cnt;
1324 FILE *fp;
1325 bool_t rv;
1326 NYD_ENTER;
1328 rv = FAL0;
1330 if((fp = Ftmp(NULL, "mpmatch", OF_RDWR | OF_UNLINK | OF_REGISTER)) == NULL)
1331 goto j_leave;
1333 if(sendmp(mp, fp, NULL, NULL, SEND_TOSRCH, NULL) < 0)
1334 goto jleave;
1335 fflush_rewind(fp);
1337 cnt = fsize(fp);
1338 line = &termios_state.ts_linebuf; /* XXX line pool */
1339 linesize = &termios_state.ts_linesize; /* XXX line pool */
1341 if(!with_headers)
1342 while(fgetline(line, linesize, &cnt, NULL, fp, 0))
1343 if (**line == '\n')
1344 break;
1346 while(fgetline(line, linesize, &cnt, NULL, fp, 0)){
1347 #ifdef HAVE_REGEX
1348 if(sep->ss_sexpr == NULL){
1349 if(regexec(&sep->ss_regex, *line, 0,NULL, 0) == REG_NOMATCH)
1350 continue;
1351 }else
1352 #endif
1353 if(!substr(*line, sep->ss_sexpr))
1354 continue;
1355 rv = TRU1;
1356 break;
1359 jleave:
1360 Fclose(fp);
1361 j_leave:
1362 NYD_LEAVE;
1363 return rv;
1366 FL struct message *
1367 setdot(struct message *mp){
1368 NYD_ENTER;
1369 if(dot != mp){
1370 prevdot = dot;
1371 pstate &= ~PS_DID_PRINT_DOT;
1373 dot = mp;
1374 uncollapse1(dot, 0);
1375 NYD_LEAVE;
1376 return dot;
1379 FL void
1380 touch(struct message *mp){
1381 NYD_ENTER;
1382 mp->m_flag |= MTOUCH;
1383 if(!(mp->m_flag & MREAD))
1384 mp->m_flag |= MREAD | MSTATUS;
1385 NYD_LEAVE;
1388 FL int
1389 getmsglist(char *buf, int *vector, int flags)
1391 int *ip, mc;
1392 struct message *mp;
1393 NYD_ENTER;
1395 pstate &= ~PS_ARGLIST_MASK;
1396 a_message_list_last_saw_d = a_message_list_saw_d;
1397 a_message_list_saw_d = FAL0;
1399 if(msgCount == 0){
1400 *vector = 0;
1401 mc = 0;
1402 goto jleave;
1405 pstate |= PS_MSGLIST_DIRECT;
1407 if(a_message_markall(buf, flags) < 0){
1408 mc = -1;
1409 goto jleave;
1412 ip = vector;
1413 if(pstate & PS_HOOK_NEWMAIL){
1414 mc = 0;
1415 for(mp = message; mp < &message[msgCount]; ++mp)
1416 if(mp->m_flag & MMARK){
1417 if(!(mp->m_flag & MNEWEST))
1418 a_message_unmark((int)PTR2SIZE(mp - message + 1));
1419 else
1420 ++mc;
1422 if(mc == 0){
1423 mc = -1;
1424 goto jleave;
1428 if(mb.mb_threaded == 0){
1429 for(mp = message; mp < &message[msgCount]; ++mp)
1430 if(mp->m_flag & MMARK)
1431 *ip++ = (int)PTR2SIZE(mp - message + 1);
1432 }else{
1433 for(mp = threadroot; mp != NULL; mp = next_in_thread(mp))
1434 if(mp->m_flag & MMARK)
1435 *ip++ = (int)PTR2SIZE(mp - message + 1);
1437 *ip = 0;
1438 mc = (int)PTR2SIZE(ip - vector);
1439 if(mc != 1)
1440 pstate &= ~PS_MSGLIST_DIRECT;
1441 jleave:
1442 NYD_LEAVE;
1443 return mc;
1446 FL int
1447 first(int f, int m)
1449 struct message *mp;
1450 int rv;
1451 NYD_ENTER;
1453 if (msgCount == 0) {
1454 rv = 0;
1455 goto jleave;
1458 f &= MDELETED;
1459 m &= MDELETED;
1460 for (mp = dot;
1461 mb.mb_threaded ? (mp != NULL) : PTRCMP(mp, <, message + msgCount);
1462 mb.mb_threaded ? (mp = next_in_thread(mp)) : ++mp) {
1463 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & m) == (ui32_t)f) {
1464 rv = (int)PTR2SIZE(mp - message + 1);
1465 goto jleave;
1469 if (dot > message) {
1470 for (mp = dot - 1; (mb.mb_threaded ? (mp != NULL) : (mp >= message));
1471 mb.mb_threaded ? (mp = prev_in_thread(mp)) : --mp) {
1472 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & m) == (ui32_t)f) {
1473 rv = (int)PTR2SIZE(mp - message + 1);
1474 goto jleave;
1478 rv = 0;
1479 jleave:
1480 NYD_LEAVE;
1481 return rv;
1484 FL void
1485 mark(int mno, int f){
1486 struct message *mp;
1487 int i;
1488 NYD_ENTER;
1490 i = mno;
1491 if(i < 1 || i > msgCount)
1492 n_panic(_("Bad message number to mark"));
1493 mp = &message[--i];
1495 if(mb.mb_threaded == 1 && a_message_threadflag)
1496 a_message__threadmark(mp, f);
1497 else{
1498 assert(!(mp->m_flag & MHIDDEN));
1499 mp->m_flag |= MMARK;
1501 NYD_LEAVE;
1504 /* s-it-mode */