n_getdeadletter(): CID 1376996 !
[s-mailx.git] / cmd-message.c
blob36e7e47a6cb267c1d8e17a24a607b9aa072c7c7d
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(!n_QUOTE_IS_A(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_mimeview(void *vp){ /* TODO direct addressable parts, multiple such */
502 struct message *mp;
503 int rv, *msgvec;
504 NYD_ENTER;
506 if((msgvec = vp)[1] != 0){
507 n_err(_("`mimeview': can yet only take one message, sorry!\n"));/* TODO */
508 n_pstate_err_no = n_ERR_NOTSUP;
509 rv = 1;
510 goto jleave;
513 mp = &message[*msgvec - 1];
514 touch(mp);
515 setdot(mp);
516 n_pstate |= n_PS_DID_PRINT_DOT;
517 uncollapse1(mp, 1);
519 n_COLOUR(
520 n_colour_env_create(n_COLOUR_CTX_VIEW, n_stdout, FAL0);
523 if(!a_cmsg_show_overview(n_stdout, mp, *msgvec))
524 n_pstate_err_no = n_ERR_IO;
525 else if(sendmp(mp, n_stdout, n_IGNORE_TYPE, NULL, SEND_TODISP_PARTS,
526 NULL) < 0)
527 n_pstate_err_no = n_ERR_IO;
528 else
529 n_pstate_err_no = n_ERR_NONE;
531 n_COLOUR(
532 n_colour_env_gut();
535 rv = (n_pstate_err_no != n_ERR_NONE);
536 jleave:
537 NYD_LEAVE;
538 return rv;
541 FL int
542 c_pipe(void *v)
544 char *str = v;
545 int rv;
546 NYD_ENTER;
548 rv = _pipe1(str, 1);
549 NYD_LEAVE;
550 return rv;
553 FL int
554 c_Pipe(void *v)
556 char *str = v;
557 int rv;
558 NYD_ENTER;
560 rv = _pipe1(str, 0);
561 NYD_LEAVE;
562 return rv;
565 FL int
566 c_top(void *v){
567 struct n_ignore *itp;
568 int rv;
569 NYD_ENTER;
571 if(n_ignore_is_any(n_IGNORE_TOP))
572 itp = n_IGNORE_TOP;
573 else{
574 itp = n_ignore_new(TRU1);
575 n_ignore_insert(itp, TRU1, "from", sizeof("from") -1);
576 n_ignore_insert(itp, TRU1, "to", sizeof("to") -1);
577 n_ignore_insert(itp, TRU1, "cc", sizeof("cc") -1);
578 n_ignore_insert(itp, TRU1, "subject", sizeof("subject") -1);
581 rv = !a_cmsg_top(v, itp);
582 NYD_LEAVE;
583 return rv;
586 FL int
587 c_Top(void *v){
588 int rv;
589 NYD_ENTER;
591 rv = !a_cmsg_top(v, n_IGNORE_TYPE);
592 NYD_LEAVE;
593 return rv;
596 FL int
597 c_next(void *v)
599 int list[2], *ip, *ip2, mdot, *msgvec = v, rv = 1;
600 struct message *mp;
601 NYD_ENTER;
603 if (*msgvec != 0) {
604 /* If some messages were supplied, find the first applicable one
605 * following dot using wrap around */
606 mdot = (int)PTR2SIZE(dot - message + 1);
608 /* Find first message in supplied message list which follows dot */
609 for (ip = msgvec; *ip != 0; ++ip) {
610 if ((mb.mb_threaded ? message[*ip - 1].m_threadpos > dot->m_threadpos
611 : *ip > mdot))
612 break;
614 if (*ip == 0)
615 ip = msgvec;
616 ip2 = ip;
617 do {
618 mp = message + *ip2 - 1;
619 if (!(mp->m_flag & MMNDEL)) {
620 setdot(mp);
621 goto jhitit;
623 if (*ip2 != 0)
624 ++ip2;
625 if (*ip2 == 0)
626 ip2 = msgvec;
627 } while (ip2 != ip);
628 fprintf(n_stdout, _("No messages applicable\n"));
629 goto jleave;
632 /* If this is the first command, select message 1. Note that this must
633 * exist for us to get here at all */
634 if (!(n_pstate & n_PS_SAW_COMMAND)) {
635 if (msgCount == 0)
636 goto jateof;
637 goto jhitit;
640 /* Just find the next good message after dot, no wraparound */
641 if (mb.mb_threaded == 0) {
642 for (mp = dot + !!(n_pstate & n_PS_DID_PRINT_DOT);
643 PTRCMP(mp, <, message + msgCount); ++mp)
644 if (!(mp->m_flag & MMNORM))
645 break;
646 } else {
647 /* TODO The threading code had some bugs that caused crashes.
648 * TODO The last thing (before the deep look) happens here,
649 * TODO so let's not trust n_PS_DID_PRINT_DOT but check & hope it fixes */
650 if ((mp = dot) != NULL && (n_pstate & n_PS_DID_PRINT_DOT))
651 mp = next_in_thread(mp);
652 while (mp != NULL && (mp->m_flag & MMNORM))
653 mp = next_in_thread(mp);
655 if (mp == NULL || PTRCMP(mp, >=, message + msgCount)) {
656 jateof:
657 fprintf(n_stdout, _("At EOF\n"));
658 rv = 0;
659 goto jleave;
661 setdot(mp);
663 /* Print dot */
664 jhitit:
665 list[0] = (int)PTR2SIZE(dot - message + 1);
666 list[1] = 0;
667 rv = c_type(list);
668 jleave:
669 NYD_LEAVE;
670 return rv;
673 FL int
674 c_pdot(void *vp)
676 NYD_ENTER;
677 n_UNUSED(vp);
678 fprintf(n_stdout, "%d\n", (int)PTR2SIZE(dot - message + 1));
679 NYD_LEAVE;
680 return 0;
683 FL int
684 c_messize(void *v)
686 int *msgvec = v, *ip, mesg;
687 struct message *mp;
688 NYD_ENTER;
690 for (ip = msgvec; *ip != 0; ++ip) {
691 mesg = *ip;
692 mp = message + mesg - 1;
693 fprintf(n_stdout, "%d: ", mesg);
694 if (mp->m_xlines > 0)
695 fprintf(n_stdout, "%ld", mp->m_xlines);
696 else
697 putc(' ', n_stdout);
698 fprintf(n_stdout, "/%lu\n", (ul_i)mp->m_xsize);
700 NYD_LEAVE;
701 return 0;
704 FL int
705 c_delete(void *v)
707 int *msgvec = v;
708 NYD_ENTER;
710 delm(msgvec);
711 NYD_LEAVE;
712 return 0;
715 FL int
716 c_deltype(void *v)
718 int list[2], rv = 0, *msgvec = v, lastdot;
719 NYD_ENTER;
721 lastdot = (int)PTR2SIZE(dot - message + 1);
722 if (delm(msgvec) >= 0) {
723 list[0] = (int)PTR2SIZE(dot - message + 1);
724 if (list[0] > lastdot) {
725 touch(dot);
726 list[1] = 0;
727 rv = c_type(list);
728 goto jleave;
730 fprintf(n_stdout, _("At EOF\n"));
731 } else
732 fprintf(n_stdout, _("No more messages\n"));
733 jleave:
734 NYD_LEAVE;
735 return rv;
738 FL int
739 c_undelete(void *v)
741 int *msgvec = v, *ip;
742 struct message *mp;
743 NYD_ENTER;
745 for (ip = msgvec; *ip != 0 && UICMP(z, PTR2SIZE(ip - msgvec), <, msgCount);
746 ++ip) {
747 mp = &message[*ip - 1];
748 touch(mp);
749 setdot(mp);
750 if (mp->m_flag & (MDELETED | MSAVED))
751 mp->m_flag &= ~(MDELETED | MSAVED);
752 else
753 mp->m_flag &= ~MDELETED;
754 #ifdef HAVE_IMAP
755 if (mb.mb_type == MB_IMAP || mb.mb_type == MB_CACHE)
756 imap_undelete(mp, *ip);
757 #endif
759 NYD_LEAVE;
760 return 0;
763 FL int
764 c_stouch(void *v)
766 int *msgvec = v, *ip;
767 NYD_ENTER;
769 for (ip = msgvec; *ip != 0; ++ip) {
770 setdot(message + *ip - 1);
771 dot->m_flag |= MTOUCH;
772 dot->m_flag &= ~MPRESERVE;
773 n_pstate |= n_PS_DID_PRINT_DOT;
775 NYD_LEAVE;
776 return 0;
779 FL int
780 c_mboxit(void *v)
782 int *msgvec = v, *ip;
783 NYD_ENTER;
785 if (n_pstate & n_PS_EDIT) {
786 n_err(_("`mbox' can only be used in a system mailbox\n")); /* TODO */
787 goto jleave;
790 for (ip = msgvec; *ip != 0; ++ip) {
791 setdot(message + *ip - 1);
792 dot->m_flag |= MTOUCH | MBOX;
793 dot->m_flag &= ~MPRESERVE;
794 n_pstate |= n_PS_DID_PRINT_DOT;
796 jleave:
797 NYD_LEAVE;
798 return 0;
801 FL int
802 c_preserve(void *v)
804 int *msgvec = v, *ip, mesg, rv = 1;
805 struct message *mp;
806 NYD_ENTER;
808 if (n_pstate & n_PS_EDIT) {
809 fprintf(n_stdout, _("Cannot `preserve' in a system mailbox\n"));
810 goto jleave;
813 for (ip = msgvec; *ip != 0; ++ip) {
814 mesg = *ip;
815 mp = message + mesg - 1;
816 mp->m_flag |= MPRESERVE;
817 mp->m_flag &= ~MBOX;
818 setdot(mp);
819 n_pstate |= n_PS_DID_PRINT_DOT;
821 rv = 0;
822 jleave:
823 NYD_LEAVE;
824 return rv;
827 FL int
828 c_unread(void *v)
830 struct message *mp;
831 int *msgvec = v, *ip;
832 NYD_ENTER;
834 for (ip = msgvec; *ip != 0; ++ip) {
835 mp = &message[*ip - 1];
836 setdot(mp);
837 dot->m_flag &= ~(MREAD | MTOUCH);
838 dot->m_flag |= MSTATUS;
839 #ifdef HAVE_IMAP
840 if (mb.mb_type == MB_IMAP || mb.mb_type == MB_CACHE)
841 imap_unread(mp, *ip); /* TODO return? */
842 #endif
843 n_pstate |= n_PS_DID_PRINT_DOT;
845 NYD_LEAVE;
846 return 0;
849 FL int
850 c_seen(void *v)
852 int *msgvec = v, *ip;
853 NYD_ENTER;
855 for (ip = msgvec; *ip != 0; ++ip) {
856 struct message *mp = message + *ip - 1;
857 setdot(mp);
858 touch(mp);
860 NYD_LEAVE;
861 return 0;
864 FL int
865 c_flag(void *v)
867 struct message *m;
868 int *msgvec = v, *ip;
869 NYD_ENTER;
871 for (ip = msgvec; *ip != 0; ++ip) {
872 m = message + *ip - 1;
873 setdot(m);
874 if (!(m->m_flag & (MFLAG | MFLAGGED)))
875 m->m_flag |= MFLAG | MFLAGGED;
877 NYD_LEAVE;
878 return 0;
881 FL int
882 c_unflag(void *v)
884 struct message *m;
885 int *msgvec = v, *ip;
886 NYD_ENTER;
888 for (ip = msgvec; *ip != 0; ++ip) {
889 m = message + *ip - 1;
890 setdot(m);
891 if (m->m_flag & (MFLAG | MFLAGGED)) {
892 m->m_flag &= ~(MFLAG | MFLAGGED);
893 m->m_flag |= MUNFLAG;
896 NYD_LEAVE;
897 return 0;
900 FL int
901 c_answered(void *v)
903 struct message *m;
904 int *msgvec = v, *ip;
905 NYD_ENTER;
907 for (ip = msgvec; *ip != 0; ++ip) {
908 m = message + *ip - 1;
909 setdot(m);
910 if (!(m->m_flag & (MANSWER | MANSWERED)))
911 m->m_flag |= MANSWER | MANSWERED;
913 NYD_LEAVE;
914 return 0;
917 FL int
918 c_unanswered(void *v)
920 struct message *m;
921 int *msgvec = v, *ip;
922 NYD_ENTER;
924 for (ip = msgvec; *ip != 0; ++ip) {
925 m = message + *ip - 1;
926 setdot(m);
927 if (m->m_flag & (MANSWER | MANSWERED)) {
928 m->m_flag &= ~(MANSWER | MANSWERED);
929 m->m_flag |= MUNANSWER;
932 NYD_LEAVE;
933 return 0;
936 FL int
937 c_draft(void *v)
939 struct message *m;
940 int *msgvec = v, *ip;
941 NYD_ENTER;
943 for (ip = msgvec; *ip != 0; ++ip) {
944 m = message + *ip - 1;
945 setdot(m);
946 if (!(m->m_flag & (MDRAFT | MDRAFTED)))
947 m->m_flag |= MDRAFT | MDRAFTED;
949 NYD_LEAVE;
950 return 0;
953 FL int
954 c_undraft(void *v)
956 struct message *m;
957 int *msgvec = v, *ip;
958 NYD_ENTER;
960 for (ip = msgvec; *ip != 0; ++ip) {
961 m = message + *ip - 1;
962 setdot(m);
963 if (m->m_flag & (MDRAFT | MDRAFTED)) {
964 m->m_flag &= ~(MDRAFT | MDRAFTED);
965 m->m_flag |= MUNDRAFT;
968 NYD_LEAVE;
969 return 0;
972 /* s-it-mode */