getmsglist(): improve [0879986] a bit
[s-mailx.git] / message.c
blobdae665db31578374809c3500c32d5a388c82b1c5
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 mp = &message[i];
600 if(mp->m_flag & MMARK)
601 continue;
603 flags &= ~a_TMP;
604 if(np > namelist){
605 for(nq = namelist; *nq != NULL; ++nq){
606 if(**nq == '@'){
607 if(a_message_match_at(mp, sep + PTR2SIZE(nq - namelist))){
608 flags |= a_TMP;
609 break;
611 }else if(**nq == '/'){
612 if(a_message_match_dash(mp, *nq)){
613 flags |= a_TMP;
614 break;
616 }else if(a_message_match_sender(mp, *nq, (flags & a_ALLNET))){
617 flags |= a_TMP;
618 break;
622 if(!(flags & a_TMP) &&
623 id != NULL && a_message_match_mid(mp, id, idfield))
624 flags |= a_TMP;
626 if(flags & a_TMP){
627 mark(i + 1, f);
628 flags |= a_ANY;
630 srelax();
632 srelax_rele();
634 jnamesearch_sepfree:
635 if(sep != NULL){
636 #ifdef HAVE_REGEX
637 for(j = PTR2SIZE(np - namelist); j-- != 0;)
638 if(sep[j].ss_sexpr == NULL)
639 regfree(&sep[j].ss_regex);
640 #endif
641 free(sep);
643 if(flags & a_ERROR)
644 goto jerr;
647 /* If any colon modifiers were given, go through and mark any messages which
648 * do satisfy the modifiers */
649 if(colmod != 0){
650 for(i = 0; i < msgCount; ++i){
651 struct a_message_coltab const *colp;
653 if((mp = &message[i])->m_flag & MMARK)
654 continue;
656 for(colp = a_message_coltabs;
657 PTRCMP(colp, <, &a_message_coltabs[NELEM(a_message_coltabs)]);
658 ++colp)
659 if((colp->mco_bit & colmod) &&
660 ((mp->m_flag & colp->mco_mask) == (unsigned)colp->mco_equal)){
661 mark(i + 1, f);
662 flags |= a_ANY;
663 break;
668 /* It shall be an error if ` didn't match anything, and nothing else did */
669 if((flags & (a_TBACK | a_ANY)) == a_TBACK){
670 id = N_("No previously marked messages\n");
671 goto jerrmsg;
672 }else if(!(flags & a_ANY))
673 goto jenoapp;
675 assert(!(flags & a_ERROR));
676 jleave:
677 if(flags & a_ALLOC){
678 free(namelist);
679 ac_free(a_message_lexstr.s);
681 NYD_LEAVE;
682 return (flags & a_ERROR) ? -1 : 0;
684 jebadrange:
685 id = N_("Invalid range endpoint\n");
686 goto jerrmsg;
687 jenoapp:
688 id = N_("No applicable messages\n");
689 jerrmsg:
690 if(!(pstate & PS_HOOK_MASK))
691 n_err(V_(id));
692 jerr:
693 flags |= a_ERROR;
694 goto jleave;
697 static int
698 a_message_evalcol(int col){
699 struct a_message_coltab const *colp;
700 int rv;
701 NYD2_ENTER;
703 rv = 0;
704 for(colp = a_message_coltabs;
705 PTRCMP(colp, <, &a_message_coltabs[NELEM(a_message_coltabs)]); ++colp)
706 if(colp->mco_char == col){
707 rv = colp->mco_bit;
708 break;
710 NYD2_LEAVE;
711 return rv;
714 static bool_t
715 a_message_check(int mno, int f){
716 struct message *mp;
717 NYD2_ENTER;
719 if(mno < 1 || mno > msgCount){
720 n_err(_("%d: Invalid message number\n"), mno);
721 mno = 1;
722 }else if(((mp = &message[mno - 1])->m_flag & MHIDDEN) ||
723 (f != MDELETED && (mp->m_flag & MDELETED) != 0))
724 n_err(_("%d: inappropriate message\n"), mno);
725 else
726 mno = 0;
727 NYD2_LEAVE;
728 return (mno == 0);
731 static int
732 a_message_scan(char **sp)
734 char *cp, *cp2;
735 struct a_message_lex const *lp;
736 int rv, c, inquote, quotec;
737 NYD_ENTER;
739 rv = a_MESSAGE_T_EOL;
741 cp = *sp;
742 cp2 = a_message_lexstr.s;
743 c = *cp++;
745 /* strip away leading white space */
746 while(blankchar(c))
747 c = *cp++;
749 /* If no characters remain, we are at end of line, so report that */
750 if(c == '\0'){
751 *sp = --cp;
752 goto jleave;
755 /* Select members of a message thread */
756 if(c == '&'){
757 if(*cp == '\0' || spacechar(*cp)){
758 a_message_lexstr.s[0] = '.';
759 a_message_lexstr.s[1] = '\0';
760 *sp = cp;
761 rv = a_MESSAGE_T_DOT | INT_MIN;
762 goto jleave;
764 rv = INT_MIN;
765 c = *cp++;
768 /* If the leading character is a digit, scan the number and convert it
769 * on the fly. Return a_MESSAGE_T_NUMBER when done */
770 if(digitchar(c)){
771 a_message_lexno = 0;
773 a_message_lexno = (a_message_lexno * 10) + c - '0';
774 *cp2++ = c;
775 }while((c = *cp++, digitchar(c)));
776 *cp2 = '\0';
777 *sp = --cp;
778 rv |= a_MESSAGE_T_NUMBER;
779 goto jleave;
782 /* An IMAP SEARCH list. Note that a_MESSAGE_T_OPEN has always been included
783 * in singles[] in Mail and mailx. Thus although there is no formal
784 * definition for (LIST) lists, they do not collide with historical
785 * practice because a subject string (LIST) could never been matched
786 * this way */
787 if (c == '(') {
788 ui32_t level = 1;
789 inquote = 0;
790 *cp2++ = c;
791 do {
792 if ((c = *cp++&0377) == '\0') {
793 jmtop:
794 n_err(_("Missing )\n"));
795 rv = a_MESSAGE_T_ERROR;
796 goto jleave;
798 if (inquote && c == '\\') {
799 *cp2++ = c;
800 c = *cp++&0377;
801 if (c == '\0')
802 goto jmtop;
803 } else if (c == '"')
804 inquote = !inquote;
805 else if (inquote)
806 /*EMPTY*/;
807 else if (c == '(')
808 ++level;
809 else if (c == ')')
810 --level;
811 else if (spacechar(c)) {
812 /* Replace unquoted whitespace by single space characters, to make
813 * the string IMAP SEARCH conformant */
814 c = ' ';
815 if (cp2[-1] == ' ')
816 --cp2;
818 *cp2++ = c;
819 } while (c != ')' || level > 0);
820 *cp2 = '\0';
821 *sp = cp;
822 rv |= a_MESSAGE_T_OPEN;
823 goto jleave;
826 /* Check for single character tokens; return such if found */
827 for(lp = a_message_singles;
828 PTRCMP(lp, <, &a_message_singles[NELEM(a_message_singles)]); ++lp)
829 if(c == lp->ml_char){
830 a_message_lexstr.s[0] = c;
831 a_message_lexstr.s[1] = '\0';
832 *sp = cp;
833 rv |= lp->ml_token;
834 goto jleave;
837 /* We've got a string! Copy all the characters of the string into
838 * a_message_lexstr, until we see a null, space, or tab. If the lead
839 * character is a " or ', save it and scan until you get another */
840 quotec = 0;
841 if (c == '\'' || c == '"') {
842 quotec = c;
843 c = *cp++;
845 while (c != '\0') {
846 if (quotec == 0 && c == '\\' && *cp != '\0')
847 c = *cp++;
848 if (c == quotec) {
849 ++cp;
850 break;
852 if (quotec == 0 && blankchar(c))
853 break;
854 if (PTRCMP(cp2 - a_message_lexstr.s, <, a_message_lexstr.l))
855 *cp2++ = c;
856 c = *cp++;
858 if (quotec && c == 0) {
859 n_err(_("Missing %c\n"), quotec);
860 rv = a_MESSAGE_T_ERROR;
861 goto jleave;
863 *sp = --cp;
864 *cp2 = '\0';
865 rv |= a_MESSAGE_T_STRING;
866 jleave:
867 NYD_LEAVE;
868 return rv;
871 static bool_t
872 a_message_match_sender(struct message *mp, char const *str, bool_t allnet){
873 char const *str_base, *np_base, *np;
874 char sc, nc;
875 bool_t rv;
876 NYD2_ENTER;
878 /* Empty string doesn't match */
879 if(*(str_base = str) == '\0'){
880 rv = FAL0;
881 goto jleave;
884 /* *allnet* is POSIX and, since it explicitly mentions login and user names,
885 * most likely case-sensitive. XXX Still allow substr matching, though
886 * XXX possibly the first letter should be case-insensitive, then? */
887 if(allnet){
888 for(np_base = np = nameof(mp, 0);;){
889 if((sc = *str++) == '@')
890 sc = '\0';
891 if((nc = *np++) == '@' || nc == '\0' || sc == '\0')
892 break;
893 if(sc != nc){
894 np = ++np_base;
895 str = str_base;
898 rv = (sc == '\0');
899 }else{
900 /* TODO POSIX says ~"match any address as shown in header overview",
901 * TODO but a normalized match would be more sane i guess.
902 * TODO struct name should gain a comparison method, normalize realname
903 * TODO content (in TODO) and thus match as likewise
904 * TODO "Buddy (Today) <here>" and "(Now) Buddy <here>" */
905 char const *real_base;
906 bool_t again;
908 real_base = name1(mp, 0);
909 again = ok_blook(showname);
910 jagain:
911 np_base = np = again ? realname(real_base) : skin(real_base);
912 str = str_base;
913 for(;;){
914 sc = *str++;
915 if((nc = *np++) == '\0' || sc == '\0')
916 break;
917 sc = upperconv(sc);
918 nc = upperconv(nc);
919 if(sc != nc){
920 np = ++np_base;
921 str = str_base;
925 /* And really if i want to match 'on@' then i want it to match even if
926 * *showname* is set! */
927 if(!(rv = (sc == '\0')) && again){
928 again = FAL0;
929 goto jagain;
932 jleave:
933 NYD2_LEAVE;
934 return rv;
937 static bool_t
938 a_message_match_mid(struct message *mp, char const *id,
939 enum a_message_idfield idfield){
940 char const *cp;
941 bool_t rv;
942 NYD2_ENTER;
944 rv = FAL0;
946 if((cp = hfield1("message-id", mp)) != NULL){
947 switch(idfield){
948 case a_MESSAGE_ID_REFERENCES:
949 if(!msgidcmp(id, cp))
950 rv = TRU1;
951 break;
952 case a_MESSAGE_ID_IN_REPLY_TO:{
953 struct name *np;
955 if((np = extract(id, GREF)) != NULL)
957 if(!msgidcmp(np->n_name, cp)){
958 rv = TRU1;
959 break;
961 }while((np = np->n_flink) != NULL);
962 break;
966 NYD2_LEAVE;
967 return rv;
970 static bool_t
971 a_message_match_dash(struct message *mp, char const *str){
972 static char lastscan[128];
974 struct str in, out;
975 char *hfield, *hbody;
976 bool_t rv;
977 NYD2_ENTER;
979 rv = FAL0;
981 if(*++str == '\0')
982 str = lastscan;
983 else
984 n_strscpy(lastscan, str, sizeof lastscan); /* XXX use new n_str object! */
986 /* Now look, ignoring case, for the word in the string */
987 if(ok_blook(searchheaders) && (hfield = strchr(str, ':'))){
988 size_t l;
990 l = PTR2SIZE(hfield - str);
991 hfield = ac_alloc(l +1);
992 memcpy(hfield, str, l);
993 hfield[l] = '\0';
994 hbody = hfieldX(hfield, mp);
995 ac_free(hfield);
996 hfield = UNCONST(str + l + 1);
997 }else{
998 hfield = UNCONST(str);
999 hbody = hfield1("subject", mp);
1001 if(hbody == NULL)
1002 goto jleave;
1004 in.l = strlen(in.s = hbody);
1005 mime_fromhdr(&in, &out, TD_ICONV);
1006 rv = substr(out.s, hfield);
1007 free(out.s);
1008 jleave:
1009 NYD2_LEAVE;
1010 return rv;
1013 static bool_t
1014 a_message_match_at(struct message *mp, struct search_expr *sep){
1015 struct str in, out;
1016 char *nfield;
1017 char const *cfield;
1018 bool_t rv;
1019 NYD2_ENTER;
1021 rv = FAL0;
1022 nfield = savestr(sep->ss_where);
1024 while((cfield = n_strsep(&nfield, ',', TRU1)) != NULL){
1025 if(!asccasecmp(cfield, "body") ||
1026 (cfield[1] == '\0' && cfield[0] == '>')){
1027 rv = FAL0;
1028 jmsg:
1029 if((rv = message_match(mp, sep, rv)))
1030 break;
1031 continue;
1032 }else if(!asccasecmp(cfield, "text") ||
1033 (cfield[1] == '\0' && cfield[0] == '=')){
1034 rv = TRU1;
1035 goto jmsg;
1038 if(!asccasecmp(cfield, "header") ||
1039 (cfield[1] == '\0' && cfield[0] == '<')){
1040 if((rv = header_match(mp, sep)))
1041 break;
1042 continue;
1045 /* This is not a special name, so take care for the "skin" prefix !
1046 * and possible abbreviations */
1047 /* C99 */{
1048 struct name *np;
1049 bool_t doskin;
1051 if((doskin = (*cfield == '~')))
1052 ++cfield;
1053 if(cfield[0] != '\0' && cfield[1] == '\0'){
1054 char const x[][8] = {"from", "to", "cc", "bcc", "subject"};
1055 size_t i;
1056 char c1;
1058 c1 = lowerconv(cfield[0]);
1059 for(i = 0; i < NELEM(x); ++i){
1060 if(c1 == x[i][0]){
1061 cfield = x[i];
1062 break;
1066 if((in.s = hfieldX(cfield, mp)) == NULL)
1067 continue;
1069 /* Shall we split into address list and match the addresses only? */
1070 if(doskin){
1071 np = lextract(in.s, GSKIN);
1072 if(np == NULL)
1073 continue;
1074 out.s = np->n_name;
1075 }else{
1076 np = NULL;
1077 in.l = strlen(in.s);
1078 mime_fromhdr(&in, &out, TD_ICONV);
1081 jnext_name:
1082 #ifdef HAVE_REGEX
1083 if(sep->ss_sexpr == NULL)
1084 rv = (regexec(&sep->ss_regex, out.s, 0,NULL, 0) != REG_NOMATCH);
1085 else
1086 #endif
1087 rv = substr(out.s, sep->ss_sexpr);
1088 if(np == NULL)
1089 free(out.s);
1090 if(rv)
1091 break;
1092 if(np != NULL && (np = np->n_flink) != NULL){
1093 out.s = np->n_name;
1094 goto jnext_name;
1098 NYD2_LEAVE;
1099 return rv;
1102 static void
1103 a_message_unmark(int mesg){
1104 size_t i;
1105 NYD2_ENTER;
1107 i = (size_t)mesg;
1108 if(i < 1 || UICMP(z, i, >, msgCount))
1109 n_panic(_("Bad message number to unmark"));
1110 message[--i].m_flag &= ~MMARK;
1111 NYD2_LEAVE;
1114 static int
1115 a_message_metamess(int meta, int f)
1117 int c, m;
1118 struct message *mp;
1119 NYD2_ENTER;
1121 c = meta;
1122 switch (c) {
1123 case '^': /* First 'good' message left */
1124 mp = mb.mb_threaded ? threadroot : message;
1125 while (PTRCMP(mp, <, message + msgCount)) {
1126 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & MDELETED) == (ui32_t)f) {
1127 c = (int)PTR2SIZE(mp - message + 1);
1128 goto jleave;
1130 if (mb.mb_threaded) {
1131 mp = next_in_thread(mp);
1132 if (mp == NULL)
1133 break;
1134 } else
1135 ++mp;
1137 if (!(pstate & PS_HOOK_MASK))
1138 n_err(_("No applicable messages\n"));
1139 goto jem1;
1141 case '$': /* Last 'good message left */
1142 mp = mb.mb_threaded
1143 ? this_in_thread(threadroot, -1) : message + msgCount - 1;
1144 while (mp >= message) {
1145 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & MDELETED) == (ui32_t)f) {
1146 c = (int)PTR2SIZE(mp - message + 1);
1147 goto jleave;
1149 if (mb.mb_threaded) {
1150 mp = prev_in_thread(mp);
1151 if (mp == NULL)
1152 break;
1153 } else
1154 --mp;
1156 if (!(pstate & PS_HOOK_MASK))
1157 n_err(_("No applicable messages\n"));
1158 goto jem1;
1160 case '.':
1161 /* Current message */
1162 m = dot - message + 1;
1163 if ((dot->m_flag & MHIDDEN) || (dot->m_flag & MDELETED) != (ui32_t)f) {
1164 n_err(_("%d: inappropriate message\n"), m);
1165 goto jem1;
1167 c = m;
1168 break;
1170 case ';':
1171 /* Previously current message */
1172 if (prevdot == NULL) {
1173 n_err(_("No previously current message\n"));
1174 goto jem1;
1176 m = prevdot - message + 1;
1177 if ((prevdot->m_flag & MHIDDEN) ||
1178 (prevdot->m_flag & MDELETED) != (ui32_t)f) {
1179 n_err(_("%d: inappropriate message\n"), m);
1180 goto jem1;
1182 c = m;
1183 break;
1185 default:
1186 n_err(_("Unknown selector: %c\n"), c);
1187 goto jem1;
1189 jleave:
1190 NYD2_LEAVE;
1191 return c;
1192 jem1:
1193 c = -1;
1194 goto jleave;
1197 static void
1198 a_message__threadmark(struct message *self, int f){
1199 NYD2_ENTER;
1200 if(!(self->m_flag & MHIDDEN) &&
1201 (f == MDELETED || !(self->m_flag & MDELETED) || a_message_list_saw_d))
1202 self->m_flag |= MMARK;
1204 if((self = self->m_child) != NULL){
1205 goto jcall;
1206 while((self = self->m_younger) != NULL)
1207 if(self->m_child != NULL)
1208 jcall:
1209 a_message__threadmark(self, f);
1210 else
1211 self->m_flag |= MMARK;
1213 NYD2_LEAVE;
1216 FL FILE *
1217 setinput(struct mailbox *mp, struct message *m, enum needspec need){
1218 FILE *rv;
1219 enum okay ok;
1220 NYD_ENTER;
1222 rv = NULL;
1223 ok = STOP;
1225 switch(need){
1226 case NEED_HEADER:
1227 ok = (m->m_have & HAVE_HEADER) ? OKAY : a_message_get_header(m);
1228 break;
1229 case NEED_BODY:
1230 ok = (m->m_have & HAVE_BODY) ? OKAY : get_body(m);
1231 break;
1232 case NEED_UNSPEC:
1233 ok = OKAY;
1234 break;
1236 if(ok != OKAY)
1237 goto jleave;
1239 fflush(mp->mb_otf);
1240 if(fseek(mp->mb_itf, (long)mailx_positionof(m->m_block, m->m_offset),
1241 SEEK_SET) == -1){
1242 n_perr(_("fseek"), 0);
1243 n_panic(_("temporary file seek"));
1245 rv = mp->mb_itf;
1246 jleave:
1247 NYD_LEAVE;
1248 return rv;
1251 FL enum okay
1252 get_body(struct message *mp){
1253 enum okay rv;
1254 NYD_ENTER;
1255 UNUSED(mp);
1257 switch(mb.mb_type){
1258 case MB_FILE:
1259 case MB_MAILDIR:
1260 rv = OKAY;
1261 break;
1262 #ifdef HAVE_POP3
1263 case MB_POP3:
1264 rv = pop3_body(mp);
1265 break;
1266 #endif
1267 case MB_VOID:
1268 default:
1269 rv = STOP;
1270 break;
1272 NYD_LEAVE;
1273 return rv;
1276 FL void
1277 message_reset(void){
1278 NYD_ENTER;
1279 if(message != NULL){
1280 free(message);
1281 message = NULL;
1283 msgCount = 0;
1284 a_message_mem_space = 0;
1285 NYD_LEAVE;
1288 FL void
1289 message_append(struct message *mp){
1290 NYD_ENTER;
1291 if(UICMP(z, msgCount + 1, >=, a_message_mem_space)){
1292 /* XXX remove _mem_space magics (or use s_Vector) */
1293 a_message_mem_space = ((a_message_mem_space >= 128 &&
1294 a_message_mem_space <= 1000000)
1295 ? a_message_mem_space << 1 : a_message_mem_space + 64);
1296 message = srealloc(message, a_message_mem_space * sizeof(*message));
1298 if(msgCount > 0){
1299 if(mp != NULL)
1300 message[msgCount - 1] = *mp;
1301 else
1302 memset(&message[msgCount - 1], 0, sizeof *message);
1304 NYD_LEAVE;
1307 FL void
1308 message_append_null(void){
1309 NYD_ENTER;
1310 if(msgCount == 0)
1311 message_append(NULL);
1312 setdot(message);
1313 message[msgCount].m_size = 0;
1314 message[msgCount].m_lines = 0;
1315 NYD_LEAVE;
1318 FL bool_t
1319 message_match(struct message *mp, struct search_expr const *sep,
1320 bool_t with_headers){
1321 char **line;
1322 size_t *linesize, cnt;
1323 FILE *fp;
1324 bool_t rv;
1325 NYD_ENTER;
1327 rv = FAL0;
1329 if((fp = Ftmp(NULL, "mpmatch", OF_RDWR | OF_UNLINK | OF_REGISTER)) == NULL)
1330 goto j_leave;
1332 if(sendmp(mp, fp, NULL, NULL, SEND_TOSRCH, NULL) < 0)
1333 goto jleave;
1334 fflush_rewind(fp);
1336 cnt = fsize(fp);
1337 line = &termios_state.ts_linebuf; /* XXX line pool */
1338 linesize = &termios_state.ts_linesize; /* XXX line pool */
1340 if(!with_headers)
1341 while(fgetline(line, linesize, &cnt, NULL, fp, 0))
1342 if (**line == '\n')
1343 break;
1345 while(fgetline(line, linesize, &cnt, NULL, fp, 0)){
1346 #ifdef HAVE_REGEX
1347 if(sep->ss_sexpr == NULL){
1348 if(regexec(&sep->ss_regex, *line, 0,NULL, 0) == REG_NOMATCH)
1349 continue;
1350 }else
1351 #endif
1352 if(!substr(*line, sep->ss_sexpr))
1353 continue;
1354 rv = TRU1;
1355 break;
1358 jleave:
1359 Fclose(fp);
1360 j_leave:
1361 NYD_LEAVE;
1362 return rv;
1365 FL struct message *
1366 setdot(struct message *mp){
1367 NYD_ENTER;
1368 if(dot != mp){
1369 prevdot = dot;
1370 pstate &= ~PS_DID_PRINT_DOT;
1372 dot = mp;
1373 uncollapse1(dot, 0);
1374 NYD_LEAVE;
1375 return dot;
1378 FL void
1379 touch(struct message *mp){
1380 NYD_ENTER;
1381 mp->m_flag |= MTOUCH;
1382 if(!(mp->m_flag & MREAD))
1383 mp->m_flag |= MREAD | MSTATUS;
1384 NYD_LEAVE;
1387 FL int
1388 getmsglist(char *buf, int *vector, int flags)
1390 int *ip, mc;
1391 struct message *mp;
1392 NYD_ENTER;
1394 pstate &= ~PS_ARGLIST_MASK;
1395 a_message_list_last_saw_d = a_message_list_saw_d;
1396 a_message_list_saw_d = FAL0;
1398 if(msgCount == 0){
1399 *vector = 0;
1400 mc = 0;
1401 goto jleave;
1404 pstate |= PS_MSGLIST_DIRECT;
1406 if(a_message_markall(buf, flags) < 0){
1407 mc = -1;
1408 goto jleave;
1411 ip = vector;
1412 if(pstate & PS_HOOK_NEWMAIL){
1413 mc = 0;
1414 for(mp = message; mp < &message[msgCount]; ++mp)
1415 if(mp->m_flag & MMARK){
1416 if(!(mp->m_flag & MNEWEST))
1417 a_message_unmark((int)PTR2SIZE(mp - message + 1));
1418 else
1419 ++mc;
1421 if(mc == 0){
1422 mc = -1;
1423 goto jleave;
1427 if(mb.mb_threaded == 0){
1428 for(mp = message; mp < &message[msgCount]; ++mp)
1429 if(mp->m_flag & MMARK)
1430 *ip++ = (int)PTR2SIZE(mp - message + 1);
1431 }else{
1432 for(mp = threadroot; mp != NULL; mp = next_in_thread(mp))
1433 if(mp->m_flag & MMARK)
1434 *ip++ = (int)PTR2SIZE(mp - message + 1);
1436 *ip = 0;
1437 mc = (int)PTR2SIZE(ip - vector);
1438 if(mc != 1)
1439 pstate &= ~PS_MSGLIST_DIRECT;
1440 jleave:
1441 NYD_LEAVE;
1442 return mc;
1445 FL int
1446 first(int f, int m)
1448 struct message *mp;
1449 int rv;
1450 NYD_ENTER;
1452 if (msgCount == 0) {
1453 rv = 0;
1454 goto jleave;
1457 f &= MDELETED;
1458 m &= MDELETED;
1459 for (mp = dot;
1460 mb.mb_threaded ? (mp != NULL) : PTRCMP(mp, <, message + msgCount);
1461 mb.mb_threaded ? (mp = next_in_thread(mp)) : ++mp) {
1462 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & m) == (ui32_t)f) {
1463 rv = (int)PTR2SIZE(mp - message + 1);
1464 goto jleave;
1468 if (dot > message) {
1469 for (mp = dot - 1; (mb.mb_threaded ? (mp != NULL) : (mp >= message));
1470 mb.mb_threaded ? (mp = prev_in_thread(mp)) : --mp) {
1471 if (!(mp->m_flag & MHIDDEN) && (mp->m_flag & m) == (ui32_t)f) {
1472 rv = (int)PTR2SIZE(mp - message + 1);
1473 goto jleave;
1477 rv = 0;
1478 jleave:
1479 NYD_LEAVE;
1480 return rv;
1483 FL void
1484 mark(int mno, int f){
1485 struct message *mp;
1486 int i;
1487 NYD_ENTER;
1489 i = mno;
1490 if(i < 1 || i > msgCount)
1491 n_panic(_("Bad message number to mark"));
1492 mp = &message[--i];
1494 if(mb.mb_threaded == 1 && a_message_threadflag)
1495 a_message__threadmark(mp, f);
1496 else{
1497 assert(!(mp->m_flag & MHIDDEN));
1498 mp->m_flag |= MMARK;
1500 NYD_LEAVE;
1503 /* s-it-mode */