1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
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
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
38 #ifndef HAVE_AMALGAMATION
44 /* Prepare and print "[Message: xy]:" intro */
45 static void _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
);
47 /* ... And place the extracted date in `date' */
48 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
50 /* Print out the header of a specific message
51 * __hprf: handle *headline*
52 * __subject: return -1 if Subject: yet seen, otherwise smalloc()d Subject:
53 * __putindent: print out the indenting in threaded display */
54 static void _print_head(size_t yetprinted
, size_t msgno
, FILE *f
,
56 static void __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
,
57 FILE *f
, bool_t threaded
, char const *attrlist
);
58 static char * __subject(struct message
*mp
, bool_t threaded
,
60 static int __putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
62 static int _dispc(struct message
*mp
, char const *a
);
64 /* Shared `z' implementation */
65 static int a_cmd_scroll(char const *arg
, bool_t onlynew
);
67 /* Shared `headers' implementation */
68 static int _headers(int msgspec
);
70 /* Show the requested messages */
71 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
72 bool_t dodecode
, char *cmd
, ui64_t
*tstats
);
74 /* Pipe the requested messages */
75 static int _pipe1(char *str
, int doign
);
78 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
80 char const *cpre
= "", *csuf
= "";
84 if (pstate
& PS_COLOUR_ACTIVE
) {
85 struct n_colour_pen
*cpen
;
87 if ((cpen
= n_colour_pen_create(n_COLOUR_ID_VIEW_MSGINFO
, NULL
)) != NULL
){
90 if ((sp
= n_colour_pen_to_str(cpen
)) != NULL
)
92 if ((sp
= n_colour_reset_to_str()) != NULL
)
97 fprintf(obuf
, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
98 cpre
, msg_no
, (ul_i
)mp
->m_lines
, (ul_i
)mp
->m_size
, csuf
);
103 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]) /* TODO line pool */
111 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
112 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
113 extract_date_from_from_(hline
, hlen
, date
);
120 _print_head(size_t yetprinted
, size_t msgno
, FILE *f
, bool_t threaded
)
123 char attrlist
[attrlen
+1], *cp
;
127 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
128 if (strlen(cp
) == attrlen
) {
129 memcpy(attrlist
, cp
, attrlen
+1);
132 n_err(_("*attrlist* is not of the correct length, using builtin\n"));
135 if (ok_blook(bsdcompat
) || ok_blook(bsdflags
)) {
136 char const bsdattr
[attrlen
+1] = "NU *HMFAT+-$~";
137 memcpy(attrlist
, bsdattr
, sizeof bsdattr
);
138 } else if (env_blook("SYSV3", FAL0
)) {
139 char const bsdattr
[attrlen
+1] = "NU *HMFAT+-$~";
140 memcpy(attrlist
, bsdattr
, sizeof bsdattr
);
141 OBSOLETE(_("*SYSV3*: please use *bsdcompat* or *bsdflags*, "
142 "or set *attrlist*"));
144 char const pattr
[attrlen
+1] = "NUROSPMFAT+-$~";
145 memcpy(attrlist
, pattr
, sizeof pattr
);
149 if ((fmt
= ok_vlook(headline
)) == NULL
) {
150 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
151 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
152 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
155 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
160 __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
, FILE *f
,
161 bool_t threaded
, char const *attrlist
)
163 char buf
[16], datebuf
[FROM_DATEBUF
], cbuf
[8], *cp
, *subjline
;
164 char const *datefmt
, *date
, *name
, *fp
n_COLOUR( COMMA
*colo_tag
);
165 int i
, n
, s
, wleft
, subjlen
;
168 n_COLOUR( struct n_colour_pen
*cpen_new COMMA
*cpen_cur COMMA
*cpen_bas
; )
175 _LOOP_MASK
= (1<<4) - 1,
181 if ((mp
= message
+ msgno
- 1) == dot
)
185 n_COLOUR( colo_tag
= NULL
; )
187 datefmt
= ok_vlook(datefield
);
189 if (datefmt
!= NULL
) {
190 fp
= hfield1("date", mp
);/* TODO use m_date field! */
196 date
= fakedate(datet
);
197 fp
= ok_vlook(datefield_markout_older
);
198 i
= (*datefmt
!= '\0');
200 i
|= (*fp
!= '\0') ? 2 | 4 : 2; /* XXX no magics */
202 /* May we strftime(3)? */
204 memcpy(&time_current
.tc_local
, localtime(&datet
),
205 sizeof time_current
.tc_local
);
207 if ((i
& 2) && (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
208 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
209 (datet
+ _6M
< time_current
.tc_time
))) {
211 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
212 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
213 memcpy(datebuf
+ 4, date
+ 4, 7);
214 datebuf
[4 + 7] = ' ';
215 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
216 datebuf
[4 + 7 + 1 + 4] = '\0';
219 n_COLOUR( colo_tag
= n_COLOUR_TAG_SUM_OLDER
; )
220 } else if ((i
& 1) == 0)
222 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
223 /* TODO eliminate this path, query the FROM_ date in setptr(),
224 * TODO all other codepaths do so by themselves ALREADY ?????
225 * TODO assert(mp->m_time != 0);, then
226 * TODO ALSO changes behaviour of datefield_markout_older */
227 _parse_from_(mp
, datebuf
);
230 date
= fakedate(datet
);
234 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
235 if ((cp
= hfield1("to", mp
)) != NULL
) {
245 name
= ok_blook(showname
) ? realname(name
) : prstr(skin(name
));
249 /* Detect the width of the non-format characters in *headline*;
250 * like that we can simply use putc() in the next loop, since we have
251 * already calculated their column widths (TODO it's sick) */
252 wleft
= subjlen
= scrnwidth
;
254 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
260 if (digitchar(*fp
)) {
263 n
= 10*n
+ *fp
- '0';
264 while (++fp
, digitchar(*fp
));
274 if (mb_cur_max
> 1) {
276 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) == -1)
278 else if ((n
= wcwidth(wc
)) == -1)
290 /* Walk *headline*, producing output TODO not (really) MB safe */
293 colo_tag
= n_COLOUR_TAG_SUM_DOT
;
294 cpen_bas
= n_colour_pen_create(n_COLOUR_ID_SUM_HEADER
, colo_tag
);
295 n_colour_pen_put(cpen_new
= cpen_cur
= cpen_bas
, f
);
298 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
301 if ((c
= *fp
& 0xFF) != '%') {
303 if ((cpen_new
= cpen_bas
) != cpen_cur
)
304 n_colour_pen_put(cpen_cur
= cpen_new
, f
);
313 if ((c
= *++fp
) == '-') {
318 if (digitchar(*fp
)) {
320 n
= 10*n
+ *fp
- '0';
321 while (++fp
, digitchar(*fp
));
324 if ((c
= *fp
& 0xFF) == '\0')
334 if (flags
& _ISDOT
) {
335 n_COLOUR( cpen_new
= n_colour_pen_create(n_COLOUR_ID_SUM_DOTMARK
,
337 if (options
& OPT_UNICODE
) {
339 /* 25B8;BLACK RIGHT-POINTING SMALL TRIANGLE: â–¸ */
340 cbuf
[1] = (char)0x96, cbuf
[2] = (char)0xB8;
342 /* 25C2;BLACK LEFT-POINTING SMALL TRIANGLE: â—‚ */
343 cbuf
[1] = (char)0x97, cbuf
[2] = (char)0x82;
354 if (UICMP(32, ABS(n
), >, wleft
))
355 n
= (n
< 0) ? -wleft
: wleft
;
356 snprintf(buf
, sizeof buf
, "%u.%02u",
357 (mp
->m_spamscore
>> 8), (mp
->m_spamscore
& 0xFF));
358 n
= fprintf(f
, "%*s", n
, buf
);
359 wleft
= (n
>= 0) ? wleft
- n
: 0;
366 c
= _dispc(mp
, attrlist
);
369 if (cpen_new
== cpen_cur
)
371 if (cpen_new
!= cpen_cur
)
372 n_colour_pen_put(cpen_cur
= cpen_new
, f
);
374 if (UICMP(32, ABS(n
), >, wleft
))
375 n
= (n
< 0) ? -wleft
: wleft
;
377 n
= fprintf(f
, "%*s", n
, cbuf
);
378 wleft
= (n
>= 0) ? wleft
- n
: 0;
380 if ((cpen_new
= cpen_bas
) != cpen_cur
)
381 n_colour_pen_put(cpen_cur
= cpen_new
, f
);
385 if (datefmt
!= NULL
) {
386 i
= strftime(datebuf
, sizeof datebuf
, datefmt
,
387 &time_current
.tc_local
);
391 n_err(_("Ignored date format, it excesses the target "
392 "buffer (%lu bytes)\n"), (ul_i
)sizeof(datebuf
));
397 if (UICMP(32, ABS(n
), >, wleft
))
398 n
= (n
< 0) ? -wleft
: wleft
;
399 n
= fprintf(f
, "%*.*s", n
, n
, date
);
400 wleft
= (n
>= 0) ? wleft
- n
: 0;
405 if (UICMP(32, ABS(n
), >, wleft
))
406 n
= (n
< 0) ? -wleft
: wleft
;
407 n
= fprintf(f
, "%*u", n
, (threaded
== 1 ? mp
->m_level
: 0));
408 wleft
= (n
>= 0) ? wleft
- n
: 0;
419 n
= (n
< 0) ? -wleft
: wleft
;
421 if (flags
& _ISTO
) /* XXX tr()! */
423 n
= fprintf(f
, "%s%s", ((flags
& _ISTO
) ? "To " : ""),
424 colalign(name
, i
, n
, &wleft
));
427 else if (flags
& _ISTO
)
433 cpen_new
= n_colour_pen_create(n_COLOUR_ID_SUM_THREAD
, colo_tag
);
434 if (cpen_new
!= cpen_cur
)
435 n_colour_pen_put(cpen_cur
= cpen_new
, f
);
437 n
= __putindent(f
, mp
, MIN(wleft
, scrnwidth
- 60));
438 wleft
= (n
>= 0) ? wleft
- n
: 0;
440 if ((cpen_new
= cpen_bas
) != cpen_cur
)
441 n_colour_pen_put(cpen_cur
= cpen_new
, f
);
448 if (UICMP(32, ABS(n
), >, wleft
))
449 n
= (n
< 0) ? -wleft
: wleft
;
451 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
452 wleft
= (n
>= 0) ? wleft
- n
: 0;
464 for (i
= msgCount
; i
> 999; i
/= 10)
467 if (UICMP(32, ABS(n
), >, wleft
))
468 n
= (n
< 0) ? -wleft
: wleft
;
469 n
= fprintf(f
, "%*lu", n
, (ul_i
)msgno
);
470 wleft
= (n
>= 0) ? wleft
- n
: 0;
475 if (UICMP(32, ABS(n
), >, wleft
))
476 n
= (n
< 0) ? -wleft
: wleft
;
477 n
= fprintf(f
, "%*lu", n
, (ul_i
)mp
->m_xsize
);
478 wleft
= (n
>= 0) ? wleft
- n
: 0;
490 if (UICMP(32, ABS(n
), >, subjlen
))
491 n
= (n
< 0) ? -subjlen
: subjlen
;
493 n
-= (n
< 0) ? -2 : 2;
496 if (subjline
== NULL
)
497 subjline
= __subject(mp
, (threaded
&& (flags
& _IFMT
)), yetprinted
);
498 if (subjline
== (char*)-1) {
499 n
= fprintf(f
, "%*s", n
, "");
500 wleft
= (n
>= 0) ? wleft
- n
: 0;
502 n
= fprintf(f
, ((flags
& _SFMT
) ? "\"%s\"" : "%s"),
503 colalign(subjline
, ABS(n
), n
, &wleft
));
508 case 'T': { /* Message recipient flags */
509 /* We never can reuse "name" since it's the full name */
510 struct name
const *np
= lextract(hfield1("to", mp
), GTO
| GSKIN
);
514 for (; np
!= NULL
; np
= np
->n_flink
) {
515 switch (is_mlist(np
->n_name
, FAL0
)) {
516 case MLIST_SUBSCRIBED
: c
= 'S'; goto jputcb
;
517 case MLIST_KNOWN
: c
= 'L'; goto jputcb
;
525 np
= lextract(hfield1("cc", mp
), GCC
| GSKIN
);
532 for (i
= msgCount
; i
> 999; i
/= 10)
535 if (UICMP(32, ABS(n
), >, wleft
))
536 n
= (n
< 0) ? -wleft
: wleft
;
537 n
= fprintf(f
, "%*lu",
538 n
, (threaded
? (ul_i
)mp
->m_threadpos
: (ul_i
)msgno
));
539 wleft
= (n
>= 0) ? wleft
- n
: 0;
542 if (options
& OPT_D_V
)
543 n_err(_("Unkown *headline* format: \"%%%c\"\n"), c
);
557 if (subjline
!= NULL
&& subjline
!= (char*)-1)
563 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
566 char *rv
= (char*)-1, *ms
;
569 if ((ms
= hfield1("subject", mp
)) == NULL
)
572 in
.l
= strlen(in
.s
= ms
);
573 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
576 if (!threaded
|| mp
->m_level
== 0)
579 /* In a display thread - check wether this message uses the same
580 * Subject: as it's parent or elder neighbour, suppress printing it if
581 * this is the case. To extend this a bit, ignore any leading Re: or
582 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
583 ms
= subject_re_trim(ms
);
585 for (; (mp
= prev_in_thread(mp
)) != NULL
&& yetprinted
-- > 0;) {
588 if (visible(mp
) && (os
= hfield1("subject", mp
)) != NULL
) {
592 in
.l
= strlen(in
.s
= os
);
593 mime_fromhdr(&in
, &oout
, TD_ICONV
| TD_ISPR
);
594 x
= asccasecmp(ms
, subject_re_trim(oout
.s
));
610 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
613 int *us
, indlvl
, indw
, i
, important
= MNEW
| MFLAGGED
;
617 if (mp
->m_level
== 0 || maxwidth
== 0) {
622 cs
= ac_alloc(mp
->m_level
);
623 us
= ac_alloc(mp
->m_level
* sizeof *us
);
626 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
627 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
628 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
630 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
633 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
634 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
636 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
641 for (i
= mp
->m_level
- 2; i
>= 0; --i
) {
643 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
648 if (mq
->m_parent
&& (mq
->m_parent
->m_flag
& important
))
661 for (indlvl
= indw
= 0; (ui8_t
)indlvl
< mp
->m_level
&& indw
< maxwidth
;
663 if (indw
< maxwidth
- 1)
664 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0xFF, fp
);
666 indw
+= (int)putuc(0x21B8, '^', fp
);
668 indw
+= putuc(0x25B8, '>', fp
);
678 _dispc(struct message
*mp
, char const *a
)
683 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MREAD
)
685 if ((mp
->m_flag
& (MREAD
| MNEW
)) == (MREAD
| MNEW
))
687 if (mp
->m_flag
& MANSWERED
)
689 if (mp
->m_flag
& MDRAFTED
)
691 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MNEW
)
693 if (!(mp
->m_flag
& (MREAD
| MNEW
)))
695 if (mp
->m_flag
& MSPAM
)
697 if (mp
->m_flag
& MSPAMUNSURE
)
699 if (mp
->m_flag
& MSAVED
)
701 if (mp
->m_flag
& MPRESERVE
)
703 if (mp
->m_flag
& (MBOX
| MBOXED
))
705 if (mp
->m_flag
& MFLAGGED
)
707 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
709 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
716 a_cmd_scroll(char const *arg
, bool_t onlynew
){
720 int msgspec
, size
, maxs
;
723 msgspec
= onlynew
? -1 : 0;
725 maxs
= msgCount
/ size
;
746 case '1': case '2': case '3': case '4': case '5':
747 case '6': case '7': case '8': case '9': case '0':
750 l
= strtol(arg
, &eptr
, 10);
753 if(l
> maxs
- (isabs
? 0 : _screen
))
755 _screen
= isabs
? (int)l
: _screen
+ l
;
761 printf(_("On last screenful of messages\n"));
770 l
= strtol(arg
, &eptr
, 10);
780 printf(_("On first screenful of messages\n"));
787 n_err(_("Unrecognized scrolling command \"%s\"\n"), arg
);
792 size
= _headers(msgspec
);
799 _headers(int msgspec
) /* TODO rework v15 */
802 bool_t
volatile isrelax
;
803 ui32_t
volatile flag
;
804 int g
, k
, mesg
, size
, lastg
= 1;
805 struct message
*mp
, *mq
, *lastmq
= NULL
;
806 enum mflag fl
= MNEW
| MFLAGGED
;
809 time_current_update(&time_current
, FAL0
);
813 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
) {
821 if (options
& OPT_INTERACTIVE
)
822 n_colour_env_create(n_COLOUR_CTX_SUM
, FAL0
);
828 #if 0 /* FIXME original code path */
841 if (mb
.mb_threaded
== 0) {
844 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
848 if (mp
->m_flag
& fl
) {
852 if ((msgspec
> 0 && PTRCMP(mp
, ==, message
+ msgspec
- 1)) ||
853 (msgspec
== 0 && g
== k
) ||
854 (msgspec
== -2 && g
== k
+ size
&& lastmq
) ||
855 (msgspec
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
859 if (lastmq
&& (msgspec
== -2 ||
860 (msgspec
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
867 mesg
= (int)PTR2SIZE(mp
- message
);
868 if (PTRCMP(dot
, !=, message
+ msgspec
- 1)) { /* TODO really?? */
869 for (mq
= mp
; PTRCMP(mq
, <, message
+ msgCount
); ++mq
)
878 for (; PTRCMP(mp
, <, message
+ msgCount
); ++mp
) {
882 if (UICMP(32, flag
++, >=, size
))
884 _print_head(0, mesg
, stdout
, 0);
889 } else { /* threaded */
892 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
894 (mp
->m_collapsed
<= 0 ||
895 PTRCMP(mp
, ==, message
+ msgspec
- 1))) {
898 if (mp
->m_flag
& fl
) {
902 if ((msgspec
> 0 && PTRCMP(mp
, ==, message
+ msgspec
- 1)) ||
903 (msgspec
== 0 && g
== k
) ||
904 (msgspec
== -2 && g
== k
+ size
&& lastmq
) ||
905 (msgspec
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
909 if (lastmq
&& (msgspec
== -2 ||
910 (msgspec
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
916 if (PTRCMP(dot
, !=, message
+ msgspec
- 1)) { /* TODO really?? */
917 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
918 if (visible(mq
) && mq
->m_collapsed
<= 0) {
928 (mp
->m_collapsed
<= 0 ||
929 PTRCMP(mp
, ==, message
+ msgspec
- 1))) {
930 if (UICMP(32, flag
++, >=, size
))
932 _print_head(flag
- 1, PTR2SIZE(mp
- message
+ 1), stdout
,
936 mp
= next_in_thread(mp
);
943 printf(_("No more mail.\n"));
944 if (pstate
& (PS_HOOK_MASK
| PS_ROBOT
))
948 n_sigman_cleanup_ping(&sm
);
952 n_COLOUR( n_colour_env_gut((sm
.sm_signo
!= SIGPIPE
) ? stdout
: NULL
); )
954 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
959 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
960 bool_t dodecode
, char *cmd
, ui64_t
*tstats
)
967 FILE * volatile obuf
;
968 bool_t
volatile isrelax
= FAL0
;
971 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
972 ? SEND_MBOX
: dodecode
974 ? SEND_TODISP
: SEND_TODISP_ALL
);
975 bool_t
const volatile formfeed
= (dopipe
&& ok_blook(page
));
978 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
) {
986 if ((cp
= ok_vlook(SHELL
)) == NULL
)
988 if ((obuf
= Popen(cmd
, "w", cp
, NULL
, 1)) == NULL
) {
992 } else if ((options
& OPT_TTYOUT
) && (dopage
||
993 ((options
& OPT_INTERACTIVE
) && (cp
= ok_vlook(crt
)) != NULL
))) {
997 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
998 mp
= message
+ *ip
- 1;
999 if (!(mp
->m_have
& HAVE_BODY
))
1000 if (get_body(mp
) != OKAY
)
1001 goto jcleanup_leave
;
1002 nlines
+= mp
->m_lines
+ 1; /* Message info XXX and PARTS... */
1006 /* >= not <: we return to the prompt */
1007 if (dopage
|| UICMP(z
, nlines
, >=,
1008 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
1009 if ((obuf
= n_pager_open()) == NULL
)
1013 if ((options
& OPT_INTERACTIVE
) &&
1014 (action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
1015 action
== SEND_SHOW
))
1016 n_colour_env_create(n_COLOUR_CTX_VIEW
, obuf
!= stdout
);
1020 else if ((options
& OPT_INTERACTIVE
) &&
1021 (action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
))
1022 n_colour_env_create(n_COLOUR_CTX_VIEW
, FAL0
);
1025 /*TODO unless we have our signal manager special care must be taken */
1028 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
1029 mp
= message
+ *ip
- 1;
1033 if (!dopipe
&& ip
!= msgvec
)
1034 fprintf(obuf
, "\n");
1035 if (action
!= SEND_MBOX
)
1036 _show_msg_overview(obuf
, mp
, *ip
);
1037 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
1039 if (formfeed
) /* TODO a nicer way to separate piped messages! */
1042 tstats
[0] += mstats
[0];
1049 n_sigman_cleanup_ping(&sm
);
1053 n_COLOUR( n_colour_env_gut((sm
.sm_signo
!= SIGPIPE
) ? obuf
: NULL
); )
1055 n_pager_close(obuf
);
1058 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
1063 _pipe1(char *str
, int doign
)
1067 int *msgvec
, rv
= 1;
1071 if ((cmd
= laststring(str
, &needs_list
, TRU1
)) == NULL
) {
1072 cmd
= ok_vlook(cmd
);
1073 if (cmd
== NULL
|| *cmd
== '\0') {
1074 n_err(_("Variable *cmd* not set\n"));
1079 msgvec
= salloc((msgCount
+ 2) * sizeof *msgvec
);
1082 *msgvec
= first(0, MMNORM
);
1084 if (pstate
& (PS_HOOK_MASK
| PS_ROBOT
)) {
1088 puts(_("No messages to pipe."));
1092 } else if (getmsglist(str
, msgvec
, 0) < 0)
1095 if (pstate
& (PS_HOOK_MASK
| PS_ROBOT
)) {
1099 printf("No applicable messages.\n");
1103 printf(_("Pipe to: \"%s\"\n"), cmd
);
1105 if ((rv
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0)
1106 printf("\"%s\" %" PRIu64
" bytes\n", cmd
, stats
[0]);
1113 c_cmdnotsupp(void *v
) /* TODO -> lex.c */
1117 n_err(_("The requested feature is not compiled in\n"));
1128 rv
= print_header_group((int*)v
);
1134 print_header_group(int *vector
)
1139 assert(vector
!= NULL
&& vector
!= (void*)-1);
1140 rv
= _headers(vector
[0]);
1151 rv
= a_cmd_scroll(v
, FAL0
);
1162 rv
= a_cmd_scroll(v
, TRU1
);
1171 int *msgvec
= v
, *ip
, n
;
1173 FILE * volatile obuf
;
1174 bool_t
volatile isrelax
;
1177 time_current_update(&time_current
, FAL0
);
1181 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
) {
1188 if (options
& OPT_INTERACTIVE
) {
1189 if ((cp
= ok_vlook(crt
)) != NULL
) {
1190 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
)
1192 if (n
> (*cp
== '\0' ? screensize() : atoi(cp
)) + 3 &&
1193 (obuf
= n_pager_open()) == NULL
)
1196 n_COLOUR( n_colour_env_create(n_COLOUR_CTX_SUM
, obuf
!= stdout
); )
1199 /* Update dot before display so that the dotmark etc. are correct */
1200 for (ip
= msgvec
; *ip
!= 0; ++ip
)
1203 setdot(message
+ *ip
- 1);
1207 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
) { /* TODO join into _print_head() */
1208 _print_head((size_t)n
++, (size_t)*ip
, obuf
, mb
.mb_threaded
);
1214 n_sigman_cleanup_ping(&sm
);
1218 n_COLOUR( n_colour_env_gut((sm
.sm_signo
!= SIGPIPE
) ? obuf
: NULL
); )
1220 n_pager_close(obuf
);
1222 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
1227 print_headers(size_t bottom
, size_t topx
, bool_t only_marked
)
1230 bool_t
volatile isrelax
;
1234 time_current_update(&time_current
, FAL0
);
1237 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
) {
1245 if (options
& OPT_INTERACTIVE
)
1246 n_colour_env_create(n_COLOUR_CTX_SUM
, FAL0
);
1251 for (printed
= 0; bottom
<= topx
; ++bottom
) {
1252 struct message
*mp
= message
+ bottom
- 1;
1254 if (!(mp
->m_flag
& MMARK
))
1256 } else if (!visible(mp
))
1258 _print_head(printed
++, bottom
, stdout
, FAL0
);
1264 n_sigman_cleanup_ping(&sm
);
1268 n_COLOUR( n_colour_env_gut((sm
.sm_signo
!= SIGPIPE
) ? stdout
: NULL
); )
1270 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
1278 printf("%d\n", (int)PTR2SIZE(dot
- message
+ 1));
1286 int *msgvec
= v
, rv
;
1289 rv
= _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1297 int *msgvec
= v
, rv
;
1300 rv
= _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1308 int *msgvec
= v
, rv
;
1311 rv
= _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1319 int *msgvec
= v
, rv
;
1322 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1330 int *msgvec
= v
, rv
;
1333 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1345 rv
= _pipe1(str
, 1);
1357 rv
= _pipe1(str
, 0);
1365 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1367 char *cp
, *linebuf
= NULL
;
1368 size_t linesize
= 0;
1373 cp
= ok_vlook(toplines
);
1376 if (topl
< 0 || topl
> 10000)
1380 /* XXX Colours of `top' only for message and part info lines */
1382 if (options
& OPT_INTERACTIVE
)
1383 n_colour_env_create(n_COLOUR_CTX_VIEW
, FAL0
);
1386 for (ip
= msgvec
; *ip
!= 0 && UICMP(z
, PTR2SIZE(ip
- msgvec
), <, msgCount
);
1388 mp
= message
+ *ip
- 1;
1391 pstate
|= PS_DID_PRINT_DOT
;
1394 _show_msg_overview(stdout
, mp
, *ip
);
1395 if (mp
->m_flag
& MNOFROM
)
1396 /* XXX c_top(): coloured output? */
1397 printf("From %s %s\n", fakefrom(mp
), fakedate(mp
->m_time
));
1398 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX use TOP */
1403 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
); ++lines
) {
1404 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1408 for (cp
= linebuf
; *cp
!= '\0' && blankchar(*cp
); ++cp
)
1410 empty_last
= (*cp
== '\0');
1414 n_COLOUR( n_colour_env_gut(stdout
); )
1415 if (linebuf
!= NULL
)
1424 int *msgvec
= v
, *ip
;
1427 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1428 setdot(message
+ *ip
- 1);
1429 dot
->m_flag
|= MTOUCH
;
1430 dot
->m_flag
&= ~MPRESERVE
;
1431 pstate
|= PS_DID_PRINT_DOT
;
1440 int *msgvec
= v
, *ip
;
1443 if (pstate
& PS_EDIT
) {
1444 n_err(_("`mbox' can only be used in a system mailbox\n")); /* TODO */
1448 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1449 setdot(message
+ *ip
- 1);
1450 dot
->m_flag
|= MTOUCH
| MBOX
;
1451 dot
->m_flag
&= ~MPRESERVE
;
1452 pstate
|= PS_DID_PRINT_DOT
;
1462 char dirname
[PATH_MAX
], *name
, **argv
= v
;
1468 name
= expand(*argv
);
1471 } else if (!getfold(dirname
, sizeof dirname
)) {
1472 n_err(_("No value set for \"folder\"\n"));
1477 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1479 run_command(cmd
, 0, COMMAND_FD_PASS
, COMMAND_FD_PASS
, name
, NULL
, NULL
,