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
43 static sigjmp_buf _cmd1_pipestop
;
44 static sigjmp_buf _cmd1_pipejmp
;
46 static void _cmd1_onpipe(int signo
);
47 static void _cmd1_brokpipe(int signo
);
49 /* Prepare and print "[Message: xy]:" intro */
50 static void _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
);
52 /* ... And place the extracted date in `date' */
53 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
55 /* Print out the header of a specific message
56 * __hprf: handle *headline*
57 * __subject: return -1 if Subject: yet seen, otherwise smalloc()d Subject:
58 * __putindent: print out the indenting in threaded display */
59 static void _print_head(size_t yetprinted
, size_t msgno
, FILE *f
,
61 static void __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
,
62 FILE *f
, bool_t threaded
, char const *attrlist
);
63 static char * __subject(struct message
*mp
, bool_t threaded
,
65 static int __putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
67 static int _dispc(struct message
*mp
, char const *a
);
69 /* Shared `z' implementation */
70 static int a_cmd_scroll(char const *arg
, bool_t onlynew
);
72 /* Shared `headers' implementation */
73 static int _headers(int msgspec
);
75 /* Show the requested messages */
76 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
77 bool_t dodecode
, char *cmd
, ui64_t
*tstats
);
79 /* Pipe the requested messages */
80 static int _pipe1(char *str
, int doign
);
83 _cmd1_onpipe(int signo
)
85 NYD_X
; /* Signal handler */
87 siglongjmp(_cmd1_pipejmp
, 1);
91 _cmd1_brokpipe(int signo
)
93 NYD_X
; /* Signal handler */
95 siglongjmp(_cmd1_pipestop
, 1);
99 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
101 char const *cpre
= "", *csuf
= "";
105 if (colour_table
!= NULL
) {
106 struct str
const *sp
;
108 if ((sp
= colour_get(COLOURSPEC_MSGINFO
)) != NULL
)
110 csuf
= colour_get(COLOURSPEC_RESET
)->s
;
113 fprintf(obuf
, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
114 cpre
, msg_no
, (ul_i
)mp
->m_lines
, (ul_i
)mp
->m_size
, csuf
);
119 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]) /* TODO line pool */
127 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
128 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
129 extract_date_from_from_(hline
, hlen
, date
);
136 _print_head(size_t yetprinted
, size_t msgno
, FILE *f
, bool_t threaded
)
139 char attrlist
[attrlen
+1], *cp
;
143 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
144 if (strlen(cp
) == attrlen
) {
145 memcpy(attrlist
, cp
, attrlen
+1);
148 n_err(_("*attrlist* is not of the correct length, using builtin\n"));
151 if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) || env_blook("SYSV3", FAL0
)) {
152 char const bsdattr
[attrlen
+1] = "NU *HMFAT+-$~";
153 memcpy(attrlist
, bsdattr
, sizeof bsdattr
);
155 char const pattr
[attrlen
+1] = "NUROSPMFAT+-$~";
156 memcpy(attrlist
, pattr
, sizeof pattr
);
160 if ((fmt
= ok_vlook(headline
)) == NULL
) {
161 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
162 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
163 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
166 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
171 __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
, FILE *f
,
172 bool_t threaded
, char const *attrlist
)
174 char buf
[16], datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
175 char const *datefmt
, *date
, *name
, *fp
;
176 int i
, n
, s
, wleft
, subjlen
;
184 _LOOP_MASK
= (1<<3) - 1,
190 mp
= message
+ msgno
- 1;
194 datefmt
= ok_vlook(datefield
);
196 if (datefmt
!= NULL
) {
197 fp
= hfield1("date", mp
);/* TODO use m_date field! */
203 date
= fakedate(datet
);
204 fp
= ok_vlook(datefield_markout_older
);
205 i
= (*datefmt
!= '\0');
207 i
|= (*fp
!= '\0') ? 2 | 4 : 2; /* XXX no magics */
209 /* May we strftime(3)? */
211 memcpy(&time_current
.tc_local
, localtime(&datet
),
212 sizeof time_current
.tc_local
);
214 if ((i
& 2) && (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
215 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
216 (datet
+ _6M
< time_current
.tc_time
))) {
218 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
219 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
220 memcpy(datebuf
+ 4, date
+ 4, 7);
221 datebuf
[4 + 7] = ' ';
222 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
223 datebuf
[4 + 7 + 1 + 4] = '\0';
226 } else if ((i
& 1) == 0)
228 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
229 /* TODO eliminate this path, query the FROM_ date in setptr(),
230 * TODO all other codepaths do so by themselves ALREADY ?????
231 * TODO assert(mp->m_time != 0);, then
232 * TODO ALSO changes behaviour of datefield_markout_older */
233 _parse_from_(mp
, datebuf
);
236 date
= fakedate(datet
);
240 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
241 if ((cp
= hfield1("to", mp
)) != NULL
) {
251 name
= ok_blook(showname
) ? realname(name
) : prstr(skin(name
));
255 /* Detect the width of the non-format characters in *headline*;
256 * like that we can simply use putc() in the next loop, since we have
257 * already calculated their column widths (TODO it's sick) */
258 wleft
= subjlen
= scrnwidth
;
260 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
266 if (digitchar(*fp
)) {
269 n
= 10*n
+ *fp
- '0';
270 while (++fp
, digitchar(*fp
));
280 if (mb_cur_max
> 1) {
282 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) == -1)
284 else if ((n
= wcwidth(wc
)) == -1)
296 /* Walk *headline*, producing output TODO not (really) MB safe */
297 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
299 if ((c
= *fp
& 0xFF) != '%')
308 } else if (*fp
== '+')
310 if (digitchar(*fp
)) {
312 n
= 10*n
+ *fp
- '0';
313 while (++fp
, digitchar(*fp
));
319 switch ((c
= *fp
& 0xFF)) {
331 if (UICMP(32, ABS(n
), >, wleft
))
332 n
= (n
< 0) ? -wleft
: wleft
;
333 snprintf(buf
, sizeof buf
, "%u.%02u",
334 (mp
->m_spamscore
>> 8), (mp
->m_spamscore
& 0xFF));
335 n
= fprintf(f
, "%*s", n
, buf
);
336 wleft
= (n
>= 0) ? wleft
- n
: 0;
343 c
= _dispc(mp
, attrlist
);
345 if (UICMP(32, ABS(n
), >, wleft
))
346 n
= (n
< 0) ? -wleft
: wleft
;
347 n
= fprintf(f
, "%*c", n
, c
);
348 wleft
= (n
>= 0) ? wleft
- n
: 0;
351 if (datefmt
!= NULL
) {
352 i
= strftime(datebuf
, sizeof datebuf
, datefmt
,
353 &time_current
.tc_local
);
357 n_err(_("Ignored date format, it excesses the target "
358 "buffer (%lu bytes)\n"), (ul_i
)sizeof(datebuf
));
363 if (UICMP(32, ABS(n
), >, wleft
))
364 n
= (n
< 0) ? -wleft
: wleft
;
365 n
= fprintf(f
, "%*.*s", n
, n
, date
);
366 wleft
= (n
>= 0) ? wleft
- n
: 0;
371 if (UICMP(32, ABS(n
), >, wleft
))
372 n
= (n
< 0) ? -wleft
: wleft
;
373 n
= fprintf(f
, "%*u", n
, (threaded
== 1 ? mp
->m_level
: 0));
374 wleft
= (n
>= 0) ? wleft
- n
: 0;
385 n
= (n
< 0) ? -wleft
: wleft
;
387 if (flags
& _ISTO
) /* XXX tr()! */
389 n
= fprintf(f
, "%s%s", ((flags
& _ISTO
) ? "To " : ""),
390 colalign(name
, i
, n
, &wleft
));
393 else if (flags
& _ISTO
)
398 n
= __putindent(f
, mp
, MIN(wleft
, scrnwidth
- 60));
399 wleft
= (n
>= 0) ? wleft
- n
: 0;
405 if (UICMP(32, ABS(n
), >, wleft
))
406 n
= (n
< 0) ? -wleft
: wleft
;
408 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
409 wleft
= (n
>= 0) ? wleft
- n
: 0;
421 for (i
= msgCount
; i
> 999; i
/= 10)
424 if (UICMP(32, ABS(n
), >, wleft
))
425 n
= (n
< 0) ? -wleft
: wleft
;
426 n
= fprintf(f
, "%*lu", n
, (ul_i
)msgno
);
427 wleft
= (n
>= 0) ? wleft
- n
: 0;
432 if (UICMP(32, ABS(n
), >, wleft
))
433 n
= (n
< 0) ? -wleft
: wleft
;
434 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
435 wleft
= (n
>= 0) ? wleft
- n
: 0;
447 if (UICMP(32, ABS(n
), >, subjlen
))
448 n
= (n
< 0) ? -subjlen
: subjlen
;
450 n
-= (n
< 0) ? -2 : 2;
453 if (subjline
== NULL
)
454 subjline
= __subject(mp
, (threaded
&& (flags
& _IFMT
)),
456 if (subjline
== (char*)-1) {
457 n
= fprintf(f
, "%*s", n
, "");
458 wleft
= (n
>= 0) ? wleft
- n
: 0;
460 n
= fprintf(f
, ((flags
& _SFMT
) ? "\"%s\"" : "%s"),
461 colalign(subjline
, ABS(n
), n
, &wleft
));
466 case 'T': { /* Message recipient flags */
467 /* We never can reuse "name" since it's the full name */
468 struct name
const *np
= lextract(hfield1("to", mp
), GTO
| GSKIN
);
472 for (; np
!= NULL
; np
= np
->n_flink
) {
473 switch (is_mlist(np
->n_name
, FAL0
)) {
474 case MLIST_SUBSCRIBED
: c
= 'S'; goto jputc
;
475 case MLIST_KNOWN
: c
= 'L'; goto jputc
;
483 np
= lextract(hfield1("cc", mp
), GCC
| GSKIN
);
490 for (i
= msgCount
; i
> 999; i
/= 10)
493 if (UICMP(32, ABS(n
), >, wleft
))
494 n
= (n
< 0) ? -wleft
: wleft
;
495 n
= fprintf(f
, "%*lu", n
,
496 (threaded
? (ul_i
)mp
->m_threadpos
: (ul_i
)msgno
));
497 wleft
= (n
>= 0) ? wleft
- n
: 0;
503 if (UICMP(32, ABS(n
), >, wleft
))
504 n
= (n
< 0) ? -wleft
: wleft
;
505 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
506 wleft
= (n
>= 0) ? wleft
- n
: 0;
513 if (options
& OPT_D_V
)
514 n_err(_("Unkown *headline* format: \"%%%c\"\n"), c
);
525 if (subjline
!= NULL
&& subjline
!= (char*)-1)
531 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
534 char *rv
= (char*)-1, *ms
;
537 if ((ms
= hfield1("subject", mp
)) == NULL
)
540 in
.l
= strlen(in
.s
= ms
);
541 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
544 if (!threaded
|| mp
->m_level
== 0)
547 /* In a display thread - check wether this message uses the same
548 * Subject: as it's parent or elder neighbour, suppress printing it if
549 * this is the case. To extend this a bit, ignore any leading Re: or
550 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
551 ms
= subject_re_trim(ms
);
553 for (; (mp
= prev_in_thread(mp
)) != NULL
&& yetprinted
-- > 0;) {
556 if (visible(mp
) && (os
= hfield1("subject", mp
)) != NULL
) {
560 in
.l
= strlen(in
.s
= os
);
561 mime_fromhdr(&in
, &oout
, TD_ICONV
| TD_ISPR
);
562 x
= asccasecmp(ms
, subject_re_trim(oout
.s
));
578 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
581 int *us
, indlvl
, indw
, i
, important
= MNEW
| MFLAGGED
;
585 if (mp
->m_level
== 0 || maxwidth
== 0) {
590 cs
= ac_alloc(mp
->m_level
);
591 us
= ac_alloc(mp
->m_level
* sizeof *us
);
594 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
595 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
596 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
598 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
601 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
602 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
604 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
609 for (i
= mp
->m_level
- 2; i
>= 0; --i
) {
611 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
616 if (mq
->m_parent
&& (mq
->m_parent
->m_flag
& important
))
629 for (indlvl
= indw
= 0; (ui8_t
)indlvl
< mp
->m_level
&& indw
< maxwidth
;
631 if (indw
< maxwidth
- 1)
632 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0xFF, fp
);
634 indw
+= (int)putuc(0x21B8, '^', fp
);
636 indw
+= putuc(0x25B8, '>', fp
);
646 _dispc(struct message
*mp
, char const *a
)
651 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MREAD
)
653 if ((mp
->m_flag
& (MREAD
| MNEW
)) == (MREAD
| MNEW
))
655 if (mp
->m_flag
& MANSWERED
)
657 if (mp
->m_flag
& MDRAFTED
)
659 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MNEW
)
661 if (!(mp
->m_flag
& (MREAD
| MNEW
)))
663 if (mp
->m_flag
& MSPAM
)
665 if (mp
->m_flag
& MSPAMUNSURE
)
667 if (mp
->m_flag
& MSAVED
)
669 if (mp
->m_flag
& MPRESERVE
)
671 if (mp
->m_flag
& (MBOX
| MBOXED
))
673 if (mp
->m_flag
& MFLAGGED
)
675 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
677 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
684 a_cmd_scroll(char const *arg
, bool_t onlynew
){
688 int msgspec
, size
, maxs
;
691 /* TODO scroll problem: we do not know whether + and $ have already reached
692 * TODO the last screen in threaded mode */
693 msgspec
= onlynew
? -1 : 0;
695 if((maxs
= msgCount
/ size
) > 0 && msgCount
% size
== 0)
724 case '1': case '2': case '3': case '4': case '5':
725 case '6': case '7': case '8': case '9': case '0':
728 l
= strtol(arg
, &eptr
, 10);
731 if(l
> maxs
- (isabs
? 0 : _screen
))
733 _screen
= isabs
? (int)l
: _screen
+ l
;
739 printf(_("On last screenful of messages\n"));
748 l
= strtol(arg
, &eptr
, 10);
758 printf(_("On first screenful of messages\n"));
765 n_err(_("Unrecognized scrolling command \"%s\"\n"), arg
);
770 size
= _headers(msgspec
);
777 _headers(int msgspec
) /* FIXME rework v14.8; also: Neitzel mail, 2014-08-21 */
780 int g
, k
, mesg
, size
, lastg
= 1;
781 struct message
*mp
, *mq
, *lastmq
= NULL
;
782 enum mflag fl
= MNEW
| MFLAGGED
;
785 time_current_update(&time_current
, FAL0
);
791 #if 0 /* FIXME original code path */
804 if (mb
.mb_threaded
== 0) {
807 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
811 if (mp
->m_flag
& fl
) {
815 if ((msgspec
> 0 && PTRCMP(mp
, ==, message
+ msgspec
- 1)) ||
816 (msgspec
== 0 && g
== k
) ||
817 (msgspec
== -2 && g
== k
+ size
&& lastmq
) ||
818 (msgspec
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
822 if (lastmq
&& (msgspec
== -2 ||
823 (msgspec
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
829 mesg
= (int)PTR2SIZE(mp
- message
);
830 if (PTRCMP(dot
, !=, message
+ msgspec
- 1)) { /* TODO really?? */
831 for (mq
= mp
; PTRCMP(mq
, <, message
+ msgCount
); ++mq
)
838 if (mb
.mb_type
== MB_IMAP
)
839 imap_getheaders(mesg
+ 1, mesg
+ size
);
842 for (; PTRCMP(mp
, <, message
+ msgCount
); ++mp
) {
846 if (UICMP(32, flag
++, >=, size
))
848 _print_head(0, mesg
, stdout
, 0);
852 } else { /* threaded */
855 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
857 (mp
->m_collapsed
<= 0 ||
858 PTRCMP(mp
, ==, message
+ msgspec
- 1))) {
861 if (mp
->m_flag
& fl
) {
865 if ((msgspec
> 0 && PTRCMP(mp
, ==, message
+ msgspec
- 1)) ||
866 (msgspec
== 0 && g
== k
) ||
867 (msgspec
== -2 && g
== k
+ size
&& lastmq
) ||
868 (msgspec
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
872 if (lastmq
&& (msgspec
== -2 ||
873 (msgspec
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
879 if (PTRCMP(dot
, !=, message
+ msgspec
- 1)) { /* TODO really?? */
880 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
881 if (visible(mq
) && mq
->m_collapsed
<= 0) {
889 (mp
->m_collapsed
<= 0 ||
890 PTRCMP(mp
, ==, message
+ msgspec
- 1))) {
891 if (UICMP(32, flag
++, >=, size
))
893 _print_head(flag
- 1, PTR2SIZE(mp
- message
+ 1), stdout
,
897 mp
= next_in_thread(mp
);
903 printf(_("No more mail.\n"));
909 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
910 bool_t dodecode
, char *cmd
, ui64_t
*tstats
)
916 FILE * volatile obuf
;
917 bool_t
volatile hadsig
= FAL0
, isrelax
= FAL0
;
920 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
921 ? SEND_MBOX
: dodecode
923 ? SEND_TODISP
: SEND_TODISP_ALL
);
924 bool_t
const volatile formfeed
= (dopipe
&& ok_blook(page
));
927 if (sigsetjmp(_cmd1_pipestop
, 1)) {
933 if ((cp
= ok_vlook(SHELL
)) == NULL
)
935 if ((obuf
= Popen(cmd
, "w", cp
, NULL
, 1)) == NULL
) {
939 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
940 } else if ((options
& OPT_TTYOUT
) && (dopage
||
941 ((options
& OPT_INTERACTIVE
) && (cp
= ok_vlook(crt
)) != NULL
))) {
942 char const *pager
= NULL
;
946 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
947 mp
= message
+ *ip
- 1;
948 if (!(mp
->m_have
& HAVE_BODY
))
949 if (get_body(mp
) != OKAY
) {
953 nlines
+= mp
->m_lines
+ 1; /* Message info XXX and PARTS... */
957 /* >= not <: we return to the prompt */
958 if (dopage
|| UICMP(z
, nlines
, >=,
959 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
960 char const *env_add
[2];
961 pager
= get_pager(env_add
+ 0);
963 obuf
= Popen(pager
, "w", NULL
, env_add
, 1);
969 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
972 if (IS_TTY_SESSION() && action
!= SEND_MBOX
)
973 colour_table_create(pager
!= NULL
); /* (salloc()s!) */
977 else if (IS_TTY_SESSION() && action
!= SEND_MBOX
)
978 colour_table_create(FAL0
); /* (salloc()s!) */
981 /*TODO unless we have our signal manager special care must be taken */
984 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
985 mp
= message
+ *ip
- 1;
989 if (!dopipe
&& ip
!= msgvec
)
991 if (action
!= SEND_MBOX
)
992 _show_msg_overview(obuf
, mp
, *ip
);
993 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
995 if (formfeed
) /* TODO a nicer way to separate piped messages! */
998 tstats
[0] += mstats
[0];
1004 if (obuf
!= stdout
) {
1005 /* Ignore SIGPIPE so it can't cause a duplicate close */
1006 safe_signal(SIGPIPE
, SIG_IGN
);
1007 if (hadsig
&& isrelax
)
1009 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
1011 safe_signal(SIGPIPE
, dflpipe
);
1021 _pipe1(char *str
, int doign
)
1025 int *msgvec
, rv
= 1;
1029 if ((cmd
= laststring(str
, &needs_list
, TRU1
)) == NULL
) {
1030 cmd
= ok_vlook(cmd
);
1031 if (cmd
== NULL
|| *cmd
== '\0') {
1032 n_err(_("Variable *cmd* not set\n"));
1037 msgvec
= salloc((msgCount
+ 2) * sizeof *msgvec
);
1040 *msgvec
= first(0, MMNORM
);
1042 if (pstate
& PS_HOOK_MASK
) {
1046 puts(_("No messages to pipe."));
1050 } else if (getmsglist(str
, msgvec
, 0) < 0)
1053 if (pstate
& PS_HOOK_MASK
) {
1057 printf("No applicable messages.\n");
1061 printf(_("Pipe to: \"%s\"\n"), cmd
);
1063 if ((rv
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0)
1064 printf("\"%s\" %" PRIu64
" bytes\n", cmd
, stats
[0]);
1071 c_cmdnotsupp(void *v
) /* TODO -> lex.c */
1075 n_err(_("The requested feature is not compiled in\n"));
1086 rv
= print_header_group((int*)v
);
1092 print_header_group(int *vector
)
1097 assert(vector
!= NULL
&& vector
!= (void*)-1);
1098 rv
= _headers(vector
[0]);
1109 rv
= a_cmd_scroll(v
, FAL0
);
1120 rv
= a_cmd_scroll(v
, TRU1
);
1128 int *msgvec
= v
, *ip
, n
;
1130 FILE * volatile obuf
;
1133 time_current_update(&time_current
, FAL0
);
1136 /* TODO unfixable memory leaks still */
1137 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
1138 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
)
1140 if (n
> (*cp
== '\0' ? screensize() : atoi(cp
)) + 3) {
1142 if (sigsetjmp(_cmd1_pipejmp
, 1))
1144 p
= get_pager(NULL
);
1145 if ((obuf
= Popen(p
, "w", NULL
, NULL
, 1)) == NULL
) {
1150 safe_signal(SIGPIPE
, &_cmd1_onpipe
);
1155 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
) { /* TODO join into _print_head() */
1156 _print_head((size_t)n
++, (size_t)*ip
, obuf
, mb
.mb_threaded
);
1162 setdot(message
+ *ip
- 1);
1165 if (obuf
!= stdout
) {
1166 safe_signal(SIGPIPE
, SIG_IGN
);
1168 safe_signal(SIGPIPE
, dflpipe
);
1175 print_headers(size_t bottom
, size_t topx
, bool_t only_marked
)
1181 if (mb
.mb_type
== MB_IMAP
)
1182 imap_getheaders(bottom
, topx
);
1184 time_current_update(&time_current
, FAL0
);
1187 for (printed
= 0; bottom
<= topx
; ++bottom
) {
1188 struct message
*mp
= message
+ bottom
- 1;
1190 if (!(mp
->m_flag
& MMARK
))
1192 } else if (!visible(mp
))
1194 _print_head(printed
++, bottom
, stdout
, FAL0
);
1206 printf("%d\n", (int)PTR2SIZE(dot
- message
+ 1));
1214 int *msgvec
= v
, rv
;
1217 rv
= _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1225 int *msgvec
= v
, rv
;
1228 rv
= _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1236 int *msgvec
= v
, rv
;
1239 rv
= _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1247 int *msgvec
= v
, rv
;
1250 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1258 int *msgvec
= v
, rv
;
1261 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1273 rv
= _pipe1(str
, 1);
1285 rv
= _pipe1(str
, 0);
1293 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1295 char *cp
, *linebuf
= NULL
;
1296 size_t linesize
= 0;
1301 cp
= ok_vlook(toplines
);
1304 if (topl
< 0 || topl
> 10000)
1309 if (IS_TTY_SESSION())
1310 colour_table_create(FAL0
); /* (salloc()s) */
1313 for (ip
= msgvec
; *ip
!= 0 && UICMP(z
, PTR2SIZE(ip
- msgvec
), <, msgCount
);
1315 mp
= message
+ *ip
- 1;
1318 pstate
|= PS_DID_PRINT_DOT
;
1321 _show_msg_overview(stdout
, mp
, *ip
);
1322 if (mp
->m_flag
& MNOFROM
)
1323 /* XXX c_top(): coloured output? */
1324 printf("From %s %s\n", fakefrom(mp
), fakedate(mp
->m_time
));
1325 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1330 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
); ++lines
) {
1331 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1335 for (cp
= linebuf
; *cp
!= '\0' && blankchar(*cp
); ++cp
)
1337 empty_last
= (*cp
== '\0');
1341 if (linebuf
!= NULL
)
1350 int *msgvec
= v
, *ip
;
1353 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1354 setdot(message
+ *ip
- 1);
1355 dot
->m_flag
|= MTOUCH
;
1356 dot
->m_flag
&= ~MPRESERVE
;
1357 pstate
|= PS_DID_PRINT_DOT
;
1366 int *msgvec
= v
, *ip
;
1369 if (pstate
& PS_EDIT
) {
1370 n_err(_("`mbox' can only be used in a system mailbox\n")); /* TODO */
1374 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1375 setdot(message
+ *ip
- 1);
1376 dot
->m_flag
|= MTOUCH
| MBOX
;
1377 dot
->m_flag
&= ~MPRESERVE
;
1378 pstate
|= PS_DID_PRINT_DOT
;
1388 char dirname
[PATH_MAX
], *name
, **argv
= v
;
1394 name
= expand(*argv
);
1397 } else if (!getfold(dirname
, sizeof dirname
)) {
1398 n_err(_("No value set for \"folder\"\n"));
1403 if (which_protocol(name
) == PROTO_IMAP
) {
1405 imap_folders(name
, *argv
== NULL
);
1407 rv
= c_cmdnotsupp(NULL
);
1410 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1412 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);