Tweak previous, it added a bad memory access
[s-mailx.git] / cmd-message.c
blobdf080e38db58e48fa98f4ec40bb8efb470a8453c
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Iterating over, and over such housekeeping message user commands.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2017 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 cmd_message
38 #ifndef HAVE_AMALGAMATION
39 # include "nail.h"
40 #endif
42 /* Prepare and print "[Message: xy]:" intro */
43 static bool_t a_cmsg_show_overview(FILE *obuf, struct message *mp, int msg_no);
45 /* Show the requested messages */
46 static int _type1(int *msgvec, bool_t doign, bool_t dopage, bool_t dopipe,
47 bool_t donotdecode, char *cmd, ui64_t *tstats);
49 /* Pipe the requested messages */
50 static int _pipe1(char *str, int doign);
52 /* `top' / `Top' */
53 static int a_cmsg_top(void *vp, struct n_ignore const *itp);
55 /* Delete the indicated messages. Set dot to some nice place afterwards */
56 static int delm(int *msgvec);
58 static bool_t
59 a_cmsg_show_overview(FILE *obuf, struct message *mp, int msg_no){
60 bool_t rv;
61 char const *cpre, *csuf;
62 NYD2_ENTER;
64 cpre = csuf = n_empty;
65 #ifdef HAVE_COLOUR
66 if(n_COLOUR_IS_ACTIVE()){
67 struct n_colour_pen *cpen;
69 if((cpen = n_colour_pen_create(n_COLOUR_ID_VIEW_MSGINFO, NULL)) != NULL){
70 struct str const *sp;
72 if((sp = n_colour_pen_to_str(cpen)) != NULL)
73 cpre = sp->s;
74 if((sp = n_colour_reset_to_str()) != NULL)
75 csuf = sp->s;
78 #endif
79 /* XXX Message info uses wire format for line count */
80 rv = (fprintf(obuf, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
81 cpre, msg_no, (ul_i)mp->m_lines, (ul_i)mp->m_size, csuf) > 0);
82 NYD2_LEAVE;
83 return rv;
86 static int
87 _type1(int *msgvec, bool_t doign, bool_t dopage, bool_t dopipe,
88 bool_t donotdecode, char *cmd, ui64_t *tstats)
90 ui64_t mstats[1];
91 int *ip;
92 struct message *mp;
93 char const *cp;
94 enum sendaction action;
95 bool_t volatile formfeed;
96 FILE * volatile obuf;
97 int volatile rv;
98 NYD_ENTER;
100 rv = 1;
101 obuf = n_stdout;
102 formfeed = (dopipe && ok_blook(page));
103 action = ((dopipe && ok_blook(piperaw))
104 ? SEND_MBOX : donotdecode
105 ? SEND_SHOW : doign
106 ? SEND_TODISP : SEND_TODISP_ALL);
108 if (dopipe) {
109 if ((obuf = Popen(cmd, "w", ok_vlook(SHELL), NULL, 1)) == NULL) {
110 n_perr(cmd, 0);
111 obuf = n_stdout;
113 } else if ((n_psonce & n_PSO_TTYOUT) && (dopage ||
114 ((n_psonce & n_PSO_INTERACTIVE) && (cp = ok_vlook(crt)) != NULL))) {
115 uiz_t nlines, lib;
117 nlines = 0;
119 if (!dopage) {
120 for (ip = msgvec; *ip && PTRCMP(ip - msgvec, <, msgCount); ++ip) {
121 mp = message + *ip - 1;
122 if (!(mp->m_content_info & CI_HAVE_BODY))
123 if (get_body(mp) != OKAY)
124 goto jleave;
125 nlines += mp->m_lines + 1; /* TODO BUT wire format, not display! */
129 /* >= not <: we return to the prompt */
130 if(dopage || nlines >= (*cp != '\0'
131 ? (n_idec_uiz_cp(&lib, cp, 0, NULL), lib)
132 : (uiz_t)n_realscreenheight)){
133 if((obuf = n_pager_open()) == NULL)
134 obuf = n_stdout;
136 n_COLOUR(
137 if(action == SEND_TODISP || action == SEND_TODISP_ALL)
138 n_colour_env_create(n_COLOUR_CTX_VIEW, obuf, obuf != n_stdout);
141 n_COLOUR(
142 else if(action == SEND_TODISP || action == SEND_TODISP_ALL)
143 n_colour_env_create(n_COLOUR_CTX_VIEW, n_stdout, FAL0);
146 rv = 0;
147 srelax_hold();
148 for (ip = msgvec; *ip && PTRCMP(ip - msgvec, <, msgCount); ++ip) {
149 mp = message + *ip - 1;
150 touch(mp);
151 setdot(mp);
152 n_pstate |= n_PS_DID_PRINT_DOT;
153 uncollapse1(mp, 1);
154 if(!dopipe && ip != msgvec && fprintf(obuf, "\n") < 0){
155 rv = 1;
156 break;
158 if(action != SEND_MBOX && !a_cmsg_show_overview(obuf, mp, *ip)){
159 rv = 1;
160 break;
162 if(sendmp(mp, obuf, (doign ? n_IGNORE_TYPE : NULL), NULL, action, mstats
163 ) < 0){
164 rv = 1;
165 break;
167 srelax();
168 if(formfeed){ /* TODO a nicer way to separate piped messages! */
169 if(putc('\f', obuf) == EOF){
170 rv = 1;
171 break;
174 if (tstats != NULL)
175 tstats[0] += mstats[0];
177 srelax_rele();
178 n_COLOUR(
179 if(!dopipe && (action == SEND_TODISP || action == SEND_TODISP_ALL))
180 n_colour_env_gut();
182 jleave:
183 if (obuf != n_stdout)
184 n_pager_close(obuf);
185 NYD_LEAVE;
186 return rv;
189 static int
190 _pipe1(char *str, int doign)
192 ui64_t stats[1];
193 char const *cmd, *cmdq;
194 int *msgvec, rv = 1;
195 bool_t needs_list;
196 NYD_ENTER;
198 if ((cmd = laststring(str, &needs_list, TRU1)) == NULL) {
199 cmd = ok_vlook(cmd);
200 if (cmd == NULL || *cmd == '\0') {
201 n_err(_("Variable *cmd* not set\n"));
202 goto jleave;
206 msgvec = salloc((msgCount + 2) * sizeof *msgvec);
208 if (!needs_list) {
209 *msgvec = first(0, MMNORM);
210 if (*msgvec == 0) {
211 if (n_pstate & (n_PS_ROBOT | n_PS_HOOK_MASK)) {
212 rv = 0;
213 goto jleave;
215 fputs(_("No messages to pipe.\n"), n_stdout);
216 goto jleave;
218 msgvec[1] = 0;
219 } else if (getmsglist(str, msgvec, 0) < 0)
220 goto jleave;
221 if (*msgvec == 0) {
222 if (n_pstate & (n_PS_ROBOT | n_PS_HOOK_MASK)) {
223 rv = 0;
224 goto jleave;
226 fprintf(n_stdout, "No applicable messages.\n");
227 goto jleave;
230 cmdq = n_shexp_quote_cp(cmd, FAL0);
231 fprintf(n_stdout, _("Pipe to: %s\n"), cmdq);
232 stats[0] = 0;
233 if ((rv = _type1(msgvec, doign, FAL0, TRU1, FAL0, n_UNCONST(cmd), stats)
234 ) == 0)
235 fprintf(n_stdout, "%s %" PRIu64 " bytes\n", cmdq, stats[0]);
236 jleave:
237 NYD_LEAVE;
238 return rv;
241 static int
242 a_cmsg_top(void *vp, struct n_ignore const *itp){
243 struct n_string s;
244 int *msgvec, *ip;
245 enum{a_NONE, a_SQUEEZE = 1u<<0,
246 a_EMPTY = 1u<<8, a_STOP = 1u<<9, a_WORKMASK = 0xFF00u} f;
247 size_t tmax, plines;
248 FILE *iobuf, *pbuf;
249 NYD2_ENTER;
251 if((iobuf = Ftmp(NULL, "topio", OF_RDWR | OF_UNLINK | OF_REGISTER)) == NULL){
252 n_perr(_("`top': I/O temporary file"), 0);
253 vp = NULL;
254 goto jleave;
256 if((pbuf = Ftmp(NULL, "toppag", OF_RDWR | OF_UNLINK | OF_REGISTER)) == NULL){
257 n_perr(_("`top': temporary pager file"), 0);
258 vp = NULL;
259 goto jleave1;
262 /* TODO In v15 we should query the m_message object, and directly send only
263 * TODO those parts, optionally over empty-line-squeeze and quote-strip
264 * TODO filters, in which we are interested in: only text content!
265 * TODO And: with *topsqueeze*, header/content separating empty line.. */
266 n_pstate &= ~n_PS_MSGLIST_DIRECT; /* TODO NO ATTACHMENTS */
267 plines = 0;
269 n_COLOUR( n_colour_env_create(n_COLOUR_CTX_VIEW, iobuf, FAL0); )
270 n_string_creat_auto(&s);
271 /* C99 */{
272 siz_t l;
274 if((n_idec_siz_cp(&l, ok_vlook(toplines), 0, NULL
275 ) & (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED)
276 ) != n_IDEC_STATE_CONSUMED)
277 l = 0;
278 if(l <= 0){
279 tmax = n_screensize();
280 if(l < 0){
281 l = n_ABS(l);
282 tmax >>= l;
284 }else
285 tmax = (size_t)l;
287 f = ok_blook(topsqueeze) ? a_SQUEEZE : a_NONE;
289 for(ip = msgvec = vp;
290 *ip != 0 && UICMP(z, PTR2SIZE(ip - msgvec), <, msgCount); ++ip){
291 struct message *mp;
293 mp = &message[*ip - 1];
294 touch(mp);
295 setdot(mp);
296 n_pstate |= n_PS_DID_PRINT_DOT;
297 uncollapse1(mp, 1);
299 rewind(iobuf);
300 if(ftruncate(fileno(iobuf), 0)){
301 n_perr(_("`top': ftruncate(2)"), 0);
302 vp = NULL;
303 break;
306 if(!a_cmsg_show_overview(iobuf, mp, *ip) ||
307 sendmp(mp, iobuf, itp, NULL, SEND_TODISP_ALL, NULL) < 0){
308 n_err(_("`top': failed to prepare message %d\n"), *ip);
309 vp = NULL;
310 break;
312 fflush_rewind(iobuf);
314 /* TODO Skip over the _msg_overview line -- this is a hack to make
315 * TODO colours work: colour contexts should be objects */
316 for(;;){
317 int c;
319 if((c = getc(iobuf)) == EOF || putc(c, pbuf) == EOF){
320 vp = NULL;
321 break;
322 }else if(c == '\n')
323 break;
325 if(vp == NULL)
326 break;
327 ++plines;
329 /* C99 */{
330 size_t l;
332 n_string_trunc(&s, 0);
333 for(l = 0, f &= ~a_WORKMASK; !(f & a_STOP);){
334 int c;
336 if((c = getc(iobuf)) == EOF){
337 f |= a_STOP;
338 c = '\n';
341 if(c != '\n')
342 n_string_push_c(&s, c);
343 else if((f & a_SQUEEZE) && s.s_len == 0){
344 if(!(f & a_STOP) && ((f & a_EMPTY) || tmax - 1 <= l))
345 continue;
346 if(putc('\n', pbuf) == EOF){
347 vp = NULL;
348 break;
350 f |= a_EMPTY;
351 ++l;
352 }else{
353 char const *cp, *xcp;
355 cp = n_string_cp_const(&s);
356 /* TODO Brute simple skip part overviews; see above.. */
357 if(!(f & a_SQUEEZE))
358 c = '\1';
359 else if(s.s_len > 8 &&
360 (xcp = strstr(cp, "[-- ")) != NULL &&
361 strstr(&xcp[1], " --]") != NULL)
362 c = '\0';
363 else for(; (c = *cp) != '\0'; ++cp){
364 if(!asciichar(c))
365 break;
366 if(!blankspacechar(c)){
367 if(!ISQUOTE(c))
368 break;
369 c = '\0';
370 break;
374 if(c != '\0'){
375 if(fputs(n_string_cp_const(&s), pbuf) == EOF ||
376 putc('\n', pbuf) == EOF){
377 vp = NULL;
378 break;
380 if(++l >= tmax)
381 break;
382 f &= ~a_EMPTY;
383 }else
384 f |= a_EMPTY;
385 n_string_trunc(&s, 0);
388 if(vp == NULL)
389 break;
390 if(l > 0)
391 plines += l;
392 else{
393 if(!(f & a_EMPTY) && putc('\n', pbuf) == EOF){
394 vp = NULL;
395 break;
397 ++plines;
402 n_string_gut(&s);
403 n_COLOUR( n_colour_env_gut(); )
405 fflush(pbuf);
406 page_or_print(pbuf, plines);
408 Fclose(pbuf);
409 jleave1:
410 Fclose(iobuf);
411 jleave:
412 NYD2_LEAVE;
413 return (vp != NULL);
416 static int
417 delm(int *msgvec)
419 struct message *mp;
420 int rv = -1, *ip, last;
421 NYD_ENTER;
423 last = 0;
424 for (ip = msgvec; *ip != 0; ++ip) {
425 mp = message + *ip - 1;
426 touch(mp);
427 mp->m_flag |= MDELETED | MTOUCH;
428 mp->m_flag &= ~(MPRESERVE | MSAVED | MBOX);
429 last = *ip;
431 if (last != 0) {
432 setdot(message + last - 1);
433 last = first(0, MDELETED);
434 if (last != 0) {
435 setdot(message + last - 1);
436 rv = 0;
437 } else {
438 setdot(message);
441 NYD_LEAVE;
442 return rv;
445 FL int
446 c_more(void *v)
448 int *msgvec = v, rv;
449 NYD_ENTER;
451 rv = _type1(msgvec, TRU1, TRU1, FAL0, FAL0, NULL, NULL);
452 NYD_LEAVE;
453 return rv;
456 FL int
457 c_More(void *v)
459 int *msgvec = v, rv;
460 NYD_ENTER;
462 rv = _type1(msgvec, FAL0, TRU1, FAL0, FAL0, NULL, NULL);
463 NYD_LEAVE;
464 return rv;
467 FL int
468 c_type(void *v)
470 int *msgvec = v, rv;
471 NYD_ENTER;
473 rv = _type1(msgvec, TRU1, FAL0, FAL0, FAL0, NULL, NULL);
474 NYD_LEAVE;
475 return rv;
478 FL int
479 c_Type(void *v)
481 int *msgvec = v, rv;
482 NYD_ENTER;
484 rv = _type1(msgvec, FAL0, FAL0, FAL0, FAL0, NULL, NULL);
485 NYD_LEAVE;
486 return rv;
489 FL int
490 c_show(void *v)
492 int *msgvec = v, rv;
493 NYD_ENTER;
495 rv = _type1(msgvec, FAL0, FAL0, FAL0, TRU1, NULL, NULL);
496 NYD_LEAVE;
497 return rv;
500 FL int
501 c_pipe(void *v)
503 char *str = v;
504 int rv;
505 NYD_ENTER;
507 rv = _pipe1(str, 1);
508 NYD_LEAVE;
509 return rv;
512 FL int
513 c_Pipe(void *v)
515 char *str = v;
516 int rv;
517 NYD_ENTER;
519 rv = _pipe1(str, 0);
520 NYD_LEAVE;
521 return rv;
524 FL int
525 c_top(void *v){
526 struct n_ignore *itp;
527 int rv;
528 NYD_ENTER;
530 if(n_ignore_is_any(n_IGNORE_TOP))
531 itp = n_IGNORE_TOP;
532 else{
533 itp = n_ignore_new(TRU1);
534 n_ignore_insert(itp, TRU1, "from", sizeof("from") -1);
535 n_ignore_insert(itp, TRU1, "to", sizeof("to") -1);
536 n_ignore_insert(itp, TRU1, "cc", sizeof("cc") -1);
537 n_ignore_insert(itp, TRU1, "subject", sizeof("subject") -1);
540 rv = !a_cmsg_top(v, itp);
541 NYD_LEAVE;
542 return rv;
545 FL int
546 c_Top(void *v){
547 int rv;
548 NYD_ENTER;
550 rv = !a_cmsg_top(v, n_IGNORE_TYPE);
551 NYD_LEAVE;
552 return rv;
555 FL int
556 c_next(void *v)
558 int list[2], *ip, *ip2, mdot, *msgvec = v, rv = 1;
559 struct message *mp;
560 NYD_ENTER;
562 if (*msgvec != 0) {
563 /* If some messages were supplied, find the first applicable one
564 * following dot using wrap around */
565 mdot = (int)PTR2SIZE(dot - message + 1);
567 /* Find first message in supplied message list which follows dot */
568 for (ip = msgvec; *ip != 0; ++ip) {
569 if ((mb.mb_threaded ? message[*ip - 1].m_threadpos > dot->m_threadpos
570 : *ip > mdot))
571 break;
573 if (*ip == 0)
574 ip = msgvec;
575 ip2 = ip;
576 do {
577 mp = message + *ip2 - 1;
578 if (!(mp->m_flag & MMNDEL)) {
579 setdot(mp);
580 goto jhitit;
582 if (*ip2 != 0)
583 ++ip2;
584 if (*ip2 == 0)
585 ip2 = msgvec;
586 } while (ip2 != ip);
587 fprintf(n_stdout, _("No messages applicable\n"));
588 goto jleave;
591 /* If this is the first command, select message 1. Note that this must
592 * exist for us to get here at all */
593 if (!(n_pstate & n_PS_SAW_COMMAND)) {
594 if (msgCount == 0)
595 goto jateof;
596 goto jhitit;
599 /* Just find the next good message after dot, no wraparound */
600 if (mb.mb_threaded == 0) {
601 for (mp = dot + !!(n_pstate & n_PS_DID_PRINT_DOT);
602 PTRCMP(mp, <, message + msgCount); ++mp)
603 if (!(mp->m_flag & MMNORM))
604 break;
605 } else {
606 /* TODO The threading code had some bugs that caused crashes.
607 * TODO The last thing (before the deep look) happens here,
608 * TODO so let's not trust n_PS_DID_PRINT_DOT but check & hope it fixes */
609 if ((mp = dot) != NULL && (n_pstate & n_PS_DID_PRINT_DOT))
610 mp = next_in_thread(mp);
611 while (mp != NULL && (mp->m_flag & MMNORM))
612 mp = next_in_thread(mp);
614 if (mp == NULL || PTRCMP(mp, >=, message + msgCount)) {
615 jateof:
616 fprintf(n_stdout, _("At EOF\n"));
617 rv = 0;
618 goto jleave;
620 setdot(mp);
622 /* Print dot */
623 jhitit:
624 list[0] = (int)PTR2SIZE(dot - message + 1);
625 list[1] = 0;
626 rv = c_type(list);
627 jleave:
628 NYD_LEAVE;
629 return rv;
632 FL int
633 c_pdot(void *vp)
635 NYD_ENTER;
636 n_UNUSED(vp);
637 fprintf(n_stdout, "%d\n", (int)PTR2SIZE(dot - message + 1));
638 NYD_LEAVE;
639 return 0;
642 FL int
643 c_messize(void *v)
645 int *msgvec = v, *ip, mesg;
646 struct message *mp;
647 NYD_ENTER;
649 for (ip = msgvec; *ip != 0; ++ip) {
650 mesg = *ip;
651 mp = message + mesg - 1;
652 fprintf(n_stdout, "%d: ", mesg);
653 if (mp->m_xlines > 0)
654 fprintf(n_stdout, "%ld", mp->m_xlines);
655 else
656 putc(' ', n_stdout);
657 fprintf(n_stdout, "/%lu\n", (ul_i)mp->m_xsize);
659 NYD_LEAVE;
660 return 0;
663 FL int
664 c_delete(void *v)
666 int *msgvec = v;
667 NYD_ENTER;
669 delm(msgvec);
670 NYD_LEAVE;
671 return 0;
674 FL int
675 c_deltype(void *v)
677 int list[2], rv = 0, *msgvec = v, lastdot;
678 NYD_ENTER;
680 lastdot = (int)PTR2SIZE(dot - message + 1);
681 if (delm(msgvec) >= 0) {
682 list[0] = (int)PTR2SIZE(dot - message + 1);
683 if (list[0] > lastdot) {
684 touch(dot);
685 list[1] = 0;
686 rv = c_type(list);
687 goto jleave;
689 fprintf(n_stdout, _("At EOF\n"));
690 } else
691 fprintf(n_stdout, _("No more messages\n"));
692 jleave:
693 NYD_LEAVE;
694 return rv;
697 FL int
698 c_undelete(void *v)
700 int *msgvec = v, *ip;
701 struct message *mp;
702 NYD_ENTER;
704 for (ip = msgvec; *ip != 0 && UICMP(z, PTR2SIZE(ip - msgvec), <, msgCount);
705 ++ip) {
706 mp = message + *ip - 1;
707 touch(mp);
708 setdot(mp);
709 if (mp->m_flag & (MDELETED | MSAVED))
710 mp->m_flag &= ~(MDELETED | MSAVED);
711 else
712 mp->m_flag &= ~MDELETED;
714 NYD_LEAVE;
715 return 0;
718 FL int
719 c_stouch(void *v)
721 int *msgvec = v, *ip;
722 NYD_ENTER;
724 for (ip = msgvec; *ip != 0; ++ip) {
725 setdot(message + *ip - 1);
726 dot->m_flag |= MTOUCH;
727 dot->m_flag &= ~MPRESERVE;
728 n_pstate |= n_PS_DID_PRINT_DOT;
730 NYD_LEAVE;
731 return 0;
734 FL int
735 c_mboxit(void *v)
737 int *msgvec = v, *ip;
738 NYD_ENTER;
740 if (n_pstate & n_PS_EDIT) {
741 n_err(_("`mbox' can only be used in a system mailbox\n")); /* TODO */
742 goto jleave;
745 for (ip = msgvec; *ip != 0; ++ip) {
746 setdot(message + *ip - 1);
747 dot->m_flag |= MTOUCH | MBOX;
748 dot->m_flag &= ~MPRESERVE;
749 n_pstate |= n_PS_DID_PRINT_DOT;
751 jleave:
752 NYD_LEAVE;
753 return 0;
756 FL int
757 c_preserve(void *v)
759 int *msgvec = v, *ip, mesg, rv = 1;
760 struct message *mp;
761 NYD_ENTER;
763 if (n_pstate & n_PS_EDIT) {
764 fprintf(n_stdout, _("Cannot `preserve' in a system mailbox\n"));
765 goto jleave;
768 for (ip = msgvec; *ip != 0; ++ip) {
769 mesg = *ip;
770 mp = message + mesg - 1;
771 mp->m_flag |= MPRESERVE;
772 mp->m_flag &= ~MBOX;
773 setdot(mp);
774 n_pstate |= n_PS_DID_PRINT_DOT;
776 rv = 0;
777 jleave:
778 NYD_LEAVE;
779 return rv;
782 FL int
783 c_unread(void *v)
785 int *msgvec = v, *ip;
786 NYD_ENTER;
788 for (ip = msgvec; *ip != 0; ++ip) {
789 setdot(message + *ip - 1);
790 dot->m_flag &= ~(MREAD | MTOUCH);
791 dot->m_flag |= MSTATUS;
792 n_pstate |= n_PS_DID_PRINT_DOT;
794 NYD_LEAVE;
795 return 0;
798 FL int
799 c_seen(void *v)
801 int *msgvec = v, *ip;
802 NYD_ENTER;
804 for (ip = msgvec; *ip != 0; ++ip) {
805 struct message *mp = message + *ip - 1;
806 setdot(mp);
807 touch(mp);
809 NYD_LEAVE;
810 return 0;
813 FL int
814 c_flag(void *v)
816 struct message *m;
817 int *msgvec = v, *ip;
818 NYD_ENTER;
820 for (ip = msgvec; *ip != 0; ++ip) {
821 m = message + *ip - 1;
822 setdot(m);
823 if (!(m->m_flag & (MFLAG | MFLAGGED)))
824 m->m_flag |= MFLAG | MFLAGGED;
826 NYD_LEAVE;
827 return 0;
830 FL int
831 c_unflag(void *v)
833 struct message *m;
834 int *msgvec = v, *ip;
835 NYD_ENTER;
837 for (ip = msgvec; *ip != 0; ++ip) {
838 m = message + *ip - 1;
839 setdot(m);
840 if (m->m_flag & (MFLAG | MFLAGGED)) {
841 m->m_flag &= ~(MFLAG | MFLAGGED);
842 m->m_flag |= MUNFLAG;
845 NYD_LEAVE;
846 return 0;
849 FL int
850 c_answered(void *v)
852 struct message *m;
853 int *msgvec = v, *ip;
854 NYD_ENTER;
856 for (ip = msgvec; *ip != 0; ++ip) {
857 m = message + *ip - 1;
858 setdot(m);
859 if (!(m->m_flag & (MANSWER | MANSWERED)))
860 m->m_flag |= MANSWER | MANSWERED;
862 NYD_LEAVE;
863 return 0;
866 FL int
867 c_unanswered(void *v)
869 struct message *m;
870 int *msgvec = v, *ip;
871 NYD_ENTER;
873 for (ip = msgvec; *ip != 0; ++ip) {
874 m = message + *ip - 1;
875 setdot(m);
876 if (m->m_flag & (MANSWER | MANSWERED)) {
877 m->m_flag &= ~(MANSWER | MANSWERED);
878 m->m_flag |= MUNANSWER;
881 NYD_LEAVE;
882 return 0;
885 FL int
886 c_draft(void *v)
888 struct message *m;
889 int *msgvec = v, *ip;
890 NYD_ENTER;
892 for (ip = msgvec; *ip != 0; ++ip) {
893 m = message + *ip - 1;
894 setdot(m);
895 if (!(m->m_flag & (MDRAFT | MDRAFTED)))
896 m->m_flag |= MDRAFT | MDRAFTED;
898 NYD_LEAVE;
899 return 0;
902 FL int
903 c_undraft(void *v)
905 struct message *m;
906 int *msgvec = v, *ip;
907 NYD_ENTER;
909 for (ip = msgvec; *ip != 0; ++ip) {
910 m = message + *ip - 1;
911 setdot(m);
912 if (m->m_flag & (MDRAFT | MDRAFTED)) {
913 m->m_flag &= ~(MDRAFT | MDRAFTED);
914 m->m_flag |= MUNDRAFT;
917 NYD_LEAVE;
918 return 0;
921 /* s-it-mode */