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 - 2014 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. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #ifndef HAVE_AMALGAMATION
45 static sigjmp_buf _cmd1_pipestop
;
46 static sigjmp_buf _cmd1_pipejmp
;
48 static void _cmd1_onpipe(int signo
);
49 static void _cmd1_brokpipe(int signo
);
51 /* Prepare and print "[Message: xy]:" intro */
52 static void _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
);
54 /* ... And place the extracted date in `date' */
55 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
57 /* Print out the header of a specific message
58 * __hprf: handle *headline*
59 * __subject: Subject:, but return NULL if threaded and Subject: yet seen
60 * __putindent: print out the indenting in threaded display */
61 static void _print_head(size_t yetprinted
, size_t msgno
, FILE *f
,
63 static void __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
,
64 FILE *f
, bool_t threaded
, char const *attrlist
);
65 static char * __subject(struct message
*mp
, bool_t threaded
,
67 static int __putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
69 static int _dispc(struct message
*mp
, char const *a
);
71 /* Shared `z' implementation */
72 static int _scroll1(char *arg
, int onlynew
);
74 /* Shared `headers' implementation */
75 static int _headers(int msgspec
);
77 /* Show the requested messages */
78 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
79 bool_t dodecode
, char *cmd
, off_t
*tstats
);
81 /* Pipe the requested messages */
82 static int _pipe1(char *str
, int doign
);
85 _cmd1_onpipe(int signo
)
87 NYD_X
; /* Signal handler */
89 siglongjmp(_cmd1_pipejmp
, 1);
93 _cmd1_brokpipe(int signo
)
95 NYD_X
; /* Signal handler */
97 siglongjmp(_cmd1_pipestop
, 1);
101 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
103 char const *cpre
= "", *csuf
= "";
107 if (colour_table
!= NULL
) {
108 struct str
const *sp
;
110 if ((sp
= colour_get(COLOURSPEC_MSGINFO
)) != NULL
)
112 csuf
= colour_get(COLOURSPEC_RESET
)->s
;
115 fprintf(obuf
, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
116 cpre
, msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
, csuf
);
121 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]) /* TODO line pool */
129 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
130 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
131 extract_date_from_from_(hline
, hlen
, date
);
138 _print_head(size_t yetprinted
, size_t msgno
, FILE *f
, bool_t threaded
)
141 char attrlist
[attrlen
+1], *cp
;
145 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
146 if (strlen(cp
) == attrlen
) {
147 memcpy(attrlist
, cp
, attrlen
+1);
151 "The value of *attrlist* is not of the correct length\n"));
153 if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) ||
154 getenv("SYSV3") != NULL
) {
155 char const bsdattr
[attrlen
+1] = "NU *HMFAT+-$";
156 memcpy(attrlist
, bsdattr
, sizeof bsdattr
);
158 char const pattr
[attrlen
+1] = "NUROSPMFAT+-$";
159 memcpy(attrlist
, pattr
, sizeof pattr
);
162 if ((fmt
= ok_vlook(headline
)) == NULL
) {
163 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
164 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
165 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
168 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
173 __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
, FILE *f
,
174 bool_t threaded
, char const *attrlist
)
176 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
177 char const *datefmt
, *date
, *name
, *fp
;
178 int i
, n
, s
, wleft
, subjlen
;
186 _LOOP_MASK
= (1<<3) - 1,
191 mp
= message
+ msgno
- 1;
195 datefmt
= ok_vlook(datefield
);
197 if (datefmt
!= NULL
) {
198 fp
= hfield1("date", mp
);/* TODO use m_date field! */
204 date
= fakedate(datet
);
205 fp
= ok_vlook(datefield_markout_older
);
206 i
= (*datefmt
!= '\0');
208 i
|= (*fp
!= '\0') ? 2 | 4 : 2; /* XXX no magics */
210 /* May we strftime(3)? */
212 memcpy(&time_current
.tc_local
, localtime(&datet
),
213 sizeof time_current
.tc_local
);
215 if ((i
& 2) && (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
216 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
217 (datet
+ _6M
< time_current
.tc_time
))) {
219 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
220 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
221 memcpy(datebuf
+ 4, date
+ 4, 7);
222 datebuf
[4 + 7] = ' ';
223 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
224 datebuf
[4 + 7 + 1 + 4] = '\0';
227 } else if ((i
& 1) == 0)
229 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
230 /* TODO eliminate this path, query the FROM_ date in setptr(),
231 * TODO all other codepaths do so by themselves ALREADY ?????
232 * TODO assert(mp->m_time != 0);, then
233 * TODO ALSO changes behaviour of datefield_markout_older */
234 _parse_from_(mp
, datebuf
);
237 date
= fakedate(datet
);
241 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
242 if ((cp
= hfield1("to", mp
)) != NULL
) {
252 name
= ok_blook(showname
) ? realname(name
) : prstr(skin(name
));
256 /* Detect the width of the non-format characters in *headline*;
257 * like that we can simply use putc() in the next loop, since we have
258 * already calculated their column widths (TODO it's sick) */
259 wleft
= subjlen
= scrnwidth
;
261 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
267 if (digitchar(*fp
)) {
270 n
= 10*n
+ *fp
- '0';
271 while (++fp
, digitchar(*fp
));
281 if (mb_cur_max
> 1) {
283 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) == -1)
285 else if ((n
= wcwidth(wc
)) == -1)
297 /* Walk *headline*, producing output TODO not (really) MB safe */
298 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
300 if ((c
= *fp
& 0xFF) != '%')
309 } else if (*fp
== '+')
311 if (digitchar(*fp
)) {
313 n
= 10*n
+ *fp
- '0';
314 while (++fp
, digitchar(*fp
));
320 switch ((c
= *fp
& 0xFF)) {
332 if (UICMP(32, ABS(n
), >, wleft
))
333 n
= (n
< 0) ? -wleft
: wleft
;
335 snprintf(buf
, sizeof buf
, "%u.%u",
336 (mp
->m_spamscore
>> 8), (mp
->m_spamscore
& 0xFF));
337 n
= fprintf(f
, "%*s", n
, buf
);
338 wleft
= (n
>= 0) ? wleft
- n
: 0;
345 c
= _dispc(mp
, attrlist
);
347 if (UICMP(32, ABS(n
), >, wleft
))
348 n
= (n
< 0) ? -wleft
: wleft
;
349 n
= fprintf(f
, "%*c", n
, c
);
350 wleft
= (n
>= 0) ? wleft
- n
: 0;
353 if (datefmt
!= NULL
) {
354 i
= strftime(datebuf
, sizeof datebuf
, datefmt
,
355 &time_current
.tc_local
);
360 "Ignored date format, it excesses the target buffer "
361 "(%lu bytes)\n"), (ul_it
)sizeof datebuf
);
366 if (UICMP(32, ABS(n
), >, wleft
))
367 n
= (n
< 0) ? -wleft
: wleft
;
368 n
= fprintf(f
, "%*.*s", n
, n
, date
);
369 wleft
= (n
>= 0) ? wleft
- n
: 0;
374 if (UICMP(32, ABS(n
), >, wleft
))
375 n
= (n
< 0) ? -wleft
: wleft
;
376 n
= fprintf(f
, "%*u", n
, (threaded
== 1 ? mp
->m_level
: 0));
377 wleft
= (n
>= 0) ? wleft
- n
: 0;
388 n
= (n
< 0) ? -wleft
: wleft
;
390 if (flags
& _ISTO
) /* XXX tr()! */
392 n
= fprintf(f
, "%s%s", ((flags
& _ISTO
) ? "To " : ""),
393 colalign(name
, i
, n
, &wleft
));
396 else if (flags
& _ISTO
)
401 n
= __putindent(f
, mp
, MIN(wleft
, scrnwidth
- 60));
402 wleft
= (n
>= 0) ? wleft
- n
: 0;
408 if (UICMP(32, ABS(n
), >, wleft
))
409 n
= (n
< 0) ? -wleft
: wleft
;
411 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
412 wleft
= (n
>= 0) ? wleft
- n
: 0;
424 for (i
= msgCount
; i
> 999; i
/= 10)
427 if (UICMP(32, ABS(n
), >, wleft
))
428 n
= (n
< 0) ? -wleft
: wleft
;
429 n
= fprintf(f
, "%*lu", n
, (ul_it
)msgno
);
430 wleft
= (n
>= 0) ? wleft
- n
: 0;
435 if (UICMP(32, ABS(n
), >, wleft
))
436 n
= (n
< 0) ? -wleft
: wleft
;
437 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
438 wleft
= (n
>= 0) ? wleft
- n
: 0;
450 if (UICMP(32, ABS(n
), >, subjlen
))
451 n
= (n
< 0) ? -subjlen
: subjlen
;
453 n
-= (n
< 0) ? -2 : 2;
456 if (subjline
== NULL
)
457 subjline
= __subject(mp
, (threaded
&& (flags
& _IFMT
)),
459 if (subjline
== (char*)-1) {
460 n
= fprintf(f
, "%*s", n
, "");
461 wleft
= (n
>= 0) ? wleft
- n
: 0;
463 n
= fprintf(f
, ((flags
& _SFMT
) ? "\"%s\"" : "%s"),
464 colalign(subjline
, ABS(n
), n
, &wleft
));
473 for (i
= msgCount
; i
> 999; i
/= 10)
476 if (UICMP(32, ABS(n
), >, wleft
))
477 n
= (n
< 0) ? -wleft
: wleft
;
478 n
= fprintf(f
, "%*lu", n
,
479 (threaded
? (ul_it
)mp
->m_threadpos
: (ul_it
)msgno
));
480 wleft
= (n
>= 0) ? wleft
- n
: 0;
486 if (UICMP(32, ABS(n
), >, wleft
))
487 n
= (n
< 0) ? -wleft
: wleft
;
488 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
489 wleft
= (n
>= 0) ? wleft
- n
: 0;
503 if (subjline
!= NULL
&& subjline
!= (char*)-1)
509 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
511 /* XXX NOTE: because of efficiency reasons we simply ignore any encoded
512 * XXX parts and use ASCII case-insensitive comparison */
515 char *rv
= (char*)-1, *ms
, *mso
, *os
;
518 if ((ms
= hfield1("subject", mp
)) == NULL
)
521 if (!threaded
|| mp
->m_level
== 0)
524 /* In a display thread - check wether this message uses the same
525 * Subject: as it's parent or elder neighbour, suppress printing it if
526 * this is the case. To extend this a bit, ignore any leading Re: or
527 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
528 mso
= subject_re_trim(ms
);
529 for (xmp
= mp
; (xmp
= prev_in_thread(xmp
)) != NULL
&& yetprinted
-- > 0;)
530 if (visible(xmp
) && (os
= hfield1("subject", xmp
)) != NULL
&&
531 !asccasecmp(mso
, subject_re_trim(os
)))
536 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
544 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
547 int *us
, indlvl
, indw
, i
, important
= MNEW
| MFLAGGED
;
551 if (mp
->m_level
== 0 || maxwidth
== 0) {
556 cs
= ac_alloc(mp
->m_level
);
557 us
= ac_alloc(mp
->m_level
* sizeof *us
);
560 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
561 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
562 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
564 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
567 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
568 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
570 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
575 for (i
= mp
->m_level
- 2; i
>= 0; --i
) {
577 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
582 if (mq
->m_parent
&& (mq
->m_parent
->m_flag
& important
))
595 for (indlvl
= indw
= 0; (ui8_t
)indlvl
< mp
->m_level
&& indw
< maxwidth
;
597 if (indw
< maxwidth
- 1)
598 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0xFF, fp
);
600 indw
+= (int)putuc(0x21B8, '^', fp
);
602 indw
+= (/*putuc(0x261E, fp)*/putc('>', fp
) != EOF
);
612 _dispc(struct message
*mp
, char const *a
)
617 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MREAD
)
619 if ((mp
->m_flag
& (MREAD
| MNEW
)) == (MREAD
| MNEW
))
621 if (mp
->m_flag
& MANSWERED
)
623 if (mp
->m_flag
& MDRAFTED
)
625 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MNEW
)
627 if (!(mp
->m_flag
& (MREAD
| MNEW
)))
629 if (mp
->m_flag
& MSPAM
)
631 if (mp
->m_flag
& MSAVED
)
633 if (mp
->m_flag
& MPRESERVE
)
635 if (mp
->m_flag
& (MBOX
| MBOXED
))
637 if (mp
->m_flag
& MFLAGGED
)
639 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
641 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
648 _scroll1(char *arg
, int onlynew
)
653 msgspec
= onlynew
? -1 : 0;
656 if (arg
[0] != '\0' && arg
[1] != '\0')
659 case '1': case '2': case '3': case '4': case '5':
660 case '6': case '7': case '8': case '9': case '0':
662 goto jscroll_forward
;
665 goto jscroll_forward
;
667 _screen
= msgCount
/ size
;
668 goto jscroll_forward
;
673 _screen
+= atoi(arg
+ 1);
675 if (_screen
* size
> msgCount
) {
676 _screen
= msgCount
/ size
;
677 printf(_("On last screenful of messages\n"));
684 _screen
-= atoi(arg
+ 1);
687 printf(_("On first screenful of messages\n"));
694 fprintf(stderr
, _("Unrecognized scrolling command \"%s\"\n"), arg
);
699 size
= _headers(msgspec
);
706 _headers(int msgspec
) /* FIXME rework v14.8; also: Neitzel mail, 2014-08-21 */
709 int g
, k
, mesg
, size
, lastg
= 1;
710 struct message
*mp
, *mq
, *lastmq
= NULL
;
711 enum mflag fl
= MNEW
| MFLAGGED
;
714 time_current_update(&time_current
, FAL0
);
720 #if 0 /* FIXME original code path */
733 if (mb
.mb_threaded
== 0) {
736 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
740 if (mp
->m_flag
& fl
) {
744 if ((msgspec
> 0 && PTRCMP(mp
, ==, message
+ msgspec
- 1)) ||
745 (msgspec
== 0 && g
== k
) ||
746 (msgspec
== -2 && g
== k
+ size
&& lastmq
) ||
747 (msgspec
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
751 if (lastmq
&& (msgspec
== -2 ||
752 (msgspec
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
758 mesg
= (int)PTR2SIZE(mp
- message
);
759 if (PTRCMP(dot
, !=, message
+ msgspec
- 1)) { /* TODO really?? */
760 for (mq
= mp
; PTRCMP(mq
, <, message
+ msgCount
); ++mq
)
767 if (mb
.mb_type
== MB_IMAP
)
768 imap_getheaders(mesg
+ 1, mesg
+ size
);
771 for (; PTRCMP(mp
, <, message
+ msgCount
); ++mp
) {
775 if (UICMP(32, flag
++, >=, size
))
777 _print_head(0, mesg
, stdout
, 0);
781 } else { /* threaded */
784 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
786 (mp
->m_collapsed
<= 0 ||
787 PTRCMP(mp
, ==, message
+ msgspec
- 1))) {
790 if (mp
->m_flag
& fl
) {
794 if ((msgspec
> 0 && PTRCMP(mp
, ==, message
+ msgspec
- 1)) ||
795 (msgspec
== 0 && g
== k
) ||
796 (msgspec
== -2 && g
== k
+ size
&& lastmq
) ||
797 (msgspec
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
801 if (lastmq
&& (msgspec
== -2 ||
802 (msgspec
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
808 if (PTRCMP(dot
, !=, message
+ msgspec
- 1)) { /* TODO really?? */
809 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
810 if (visible(mq
) && mq
->m_collapsed
<= 0) {
818 (mp
->m_collapsed
<= 0 ||
819 PTRCMP(mp
, ==, message
+ msgspec
- 1))) {
820 if (UICMP(32, flag
++, >=, size
))
822 _print_head(flag
- 1, PTR2SIZE(mp
- message
+ 1), stdout
,
826 mp
= next_in_thread(mp
);
832 printf(_("No more mail.\n"));
838 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
839 bool_t dodecode
, char *cmd
, off_t
*tstats
)
845 FILE * volatile obuf
;
846 bool_t
volatile hadsig
= FAL0
, isrelax
= FAL0
;
849 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
850 ? SEND_MBOX
: dodecode
852 ? SEND_TODISP
: SEND_TODISP_ALL
);
853 bool_t
const volatile formfeed
= (dopipe
&& ok_blook(page
));
856 if (sigsetjmp(_cmd1_pipestop
, 1)) {
862 if ((cp
= ok_vlook(SHELL
)) == NULL
)
864 if ((obuf
= Popen(cmd
, "w", cp
, NULL
, 1)) == NULL
) {
868 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
869 } else if ((options
& OPT_TTYOUT
) &&
870 (dopage
|| (cp
= ok_vlook(crt
)) != NULL
)) {
871 char const *pager
= NULL
;
875 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
876 mp
= message
+ *ip
- 1;
877 if (!(mp
->m_have
& HAVE_BODY
))
878 if (get_body(mp
) != OKAY
) {
882 nlines
+= mp
->m_lines
+ 1; /* Message info XXX and PARTS... */
886 /* `>=' not `<': we return to the prompt */
887 if (dopage
|| UICMP(z
, nlines
, >=,
888 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
889 char const *env_add
[2];
890 pager
= get_pager(env_add
+ 0);
892 obuf
= Popen(pager
, "w", NULL
, env_add
, 1);
898 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
901 if (action
!= SEND_MBOX
)
902 colour_table_create(pager
!= NULL
); /* (salloc()s!) */
906 else if ((options
& OPT_TTYOUT
) && action
!= SEND_MBOX
)
907 colour_table_create(FAL0
); /* (salloc()s!) */
910 /*TODO unless we have our signal manager special care must be taken */
913 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
914 mp
= message
+ *ip
- 1;
921 if (action
!= SEND_MBOX
)
922 _show_msg_overview(obuf
, mp
, *ip
);
924 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
926 if (formfeed
) /* TODO a nicer way to separate piped messages! */
929 tstats
[0] += mstats
[0];
930 tstats
[1] += mstats
[1];
937 if (obuf
!= stdout
) {
938 /* Ignore SIGPIPE so it can't cause a duplicate close */
939 safe_signal(SIGPIPE
, SIG_IGN
);
940 if (hadsig
&& isrelax
)
942 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
944 safe_signal(SIGPIPE
, dflpipe
);
954 _pipe1(char *str
, int doign
)
962 if ((cmd
= laststring(str
, &needs_list
, TRU1
)) == NULL
) {
964 if (cmd
== NULL
|| *cmd
== '\0') {
965 fputs(_("variable cmd not set\n"), stderr
);
970 msgvec
= salloc((msgCount
+ 2) * sizeof *msgvec
);
973 *msgvec
= first(0, MMNORM
);
979 puts(_("No messages to pipe."));
983 } else if (getmsglist(str
, msgvec
, 0) < 0)
990 printf("No applicable messages.\n");
994 printf(_("Pipe to: \"%s\"\n"), cmd
);
995 stats
[0] = stats
[1] = 0;
996 if ((rv
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
997 printf("\"%s\" ", cmd
);
999 printf("%lu", (long)stats
[0]);
1001 printf(_("binary"));
1002 printf("/%lu\n", (long)stats
[1]);
1010 c_cmdnotsupp(void *v
) /* TODO -> lex.c */
1014 fprintf(stderr
, _("The requested feature is not compiled in\n"));
1025 rv
= print_header_group((int*)v
);
1031 print_header_group(int *vector
)
1036 assert(vector
!= NULL
&& vector
!= (void*)-1);
1037 rv
= _headers(vector
[0]);
1048 rv
= _scroll1(v
, 0);
1059 rv
= _scroll1(v
, 1);
1067 int *msgvec
= v
, *ip
, n
;
1069 FILE * volatile obuf
;
1072 time_current_update(&time_current
, FAL0
);
1075 /* TODO unfixable memory leaks still */
1076 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
1077 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
)
1079 if (n
> (*cp
== '\0' ? screensize() : atoi(cp
)) + 3) {
1081 if (sigsetjmp(_cmd1_pipejmp
, 1))
1083 p
= get_pager(NULL
);
1084 if ((obuf
= Popen(p
, "w", NULL
, NULL
, 1)) == NULL
) {
1089 safe_signal(SIGPIPE
, &_cmd1_onpipe
);
1093 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
) /* TODO join into _print_head() */
1094 _print_head((size_t)n
++, (size_t)*ip
, obuf
, mb
.mb_threaded
);
1096 setdot(message
+ *ip
- 1);
1099 if (obuf
!= stdout
) {
1100 safe_signal(SIGPIPE
, SIG_IGN
);
1102 safe_signal(SIGPIPE
, dflpipe
);
1109 print_headers(size_t bottom
, size_t topx
, bool_t only_marked
)
1115 if (mb
.mb_type
== MB_IMAP
)
1116 imap_getheaders(bottom
, topx
);
1118 time_current_update(&time_current
, FAL0
);
1120 for (printed
= 0; bottom
<= topx
; ++bottom
) {
1121 struct message
*mp
= message
+ bottom
- 1;
1123 if (!(mp
->m_flag
& MMARK
))
1125 } else if (!visible(mp
))
1127 _print_head(printed
++, bottom
, stdout
, FAL0
);
1137 printf("%d\n", (int)PTR2SIZE(dot
- message
+ 1));
1145 int *msgvec
= v
, rv
;
1148 rv
= _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1156 int *msgvec
= v
, rv
;
1159 rv
= _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1167 int *msgvec
= v
, rv
;
1170 rv
= _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1178 int *msgvec
= v
, rv
;
1181 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1189 int *msgvec
= v
, rv
;
1192 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1204 rv
= _pipe1(str
, 1);
1216 rv
= _pipe1(str
, 0);
1224 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1226 char *cp
, *linebuf
= NULL
;
1227 size_t linesize
= 0;
1232 cp
= ok_vlook(toplines
);
1235 if (topl
< 0 || topl
> 10000)
1240 if (options
& OPT_TTYOUT
)
1241 colour_table_create(FAL0
); /* (salloc()s) */
1244 for (ip
= msgvec
; *ip
!= 0 && UICMP(z
, PTR2SIZE(ip
- msgvec
), <, msgCount
);
1246 mp
= message
+ *ip
- 1;
1249 did_print_dot
= TRU1
;
1252 _show_msg_overview(stdout
, mp
, *ip
);
1253 if (mp
->m_flag
& MNOFROM
)
1254 /* XXX c_top(): coloured output? */
1255 printf("From %s %s\n", fakefrom(mp
), fakedate(mp
->m_time
));
1256 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1261 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
); ++lines
) {
1262 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1266 for (cp
= linebuf
; *cp
!= '\0' && blankchar(*cp
); ++cp
)
1268 empty_last
= (*cp
== '\0');
1272 if (linebuf
!= NULL
)
1281 int *msgvec
= v
, *ip
;
1284 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1285 setdot(message
+ *ip
- 1);
1286 dot
->m_flag
|= MTOUCH
;
1287 dot
->m_flag
&= ~MPRESERVE
;
1288 did_print_dot
= TRU1
;
1297 int *msgvec
= v
, *ip
;
1300 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1301 setdot(message
+ *ip
- 1);
1302 dot
->m_flag
|= MTOUCH
| MBOX
;
1303 dot
->m_flag
&= ~MPRESERVE
;
1304 did_print_dot
= TRU1
;
1313 char dirname
[PATH_MAX
], *name
, **argv
= v
;
1319 name
= expand(*argv
);
1322 } else if (!getfold(dirname
, sizeof dirname
)) {
1323 fprintf(stderr
, _("No value set for \"folder\"\n"));
1328 if (which_protocol(name
) == PROTO_IMAP
) {
1330 imap_folders(name
, *argv
== NULL
);
1332 rv
= c_cmdnotsupp(NULL
);
1335 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1337 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);