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 - 2013 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 * Print the current active headings.
46 * Don't change dot if invoker didn't give an argument.
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
, int msgno
, FILE *f
,
63 static void __hprf(size_t yetprinted
, const char *fmt
, int mesg
, FILE *f
,
64 bool_t threaded
, const char *attrlist
);
65 static char * __subject(struct message
*mp
, bool_t threaded
,
67 static char * __subject_trim(char *s
);
68 static int __putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
70 static void _cmd1_onpipe(int signo
);
71 static int _dispc(struct message
*mp
, const char *a
);
72 static int scroll1(char *arg
, int onlynew
);
74 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
75 bool_t dodecode
, char *cmd
, off_t
*tstats
);
76 static int pipe1(char *str
, int doign
);
79 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
81 char const *cpre
= "", *csuf
= "";
84 if (colour_table
!= NULL
) {
87 if ((sp
= colour_get(COLOURSPEC_MSGINFO
)) != NULL
)
89 csuf
= colour_get(COLOURSPEC_RESET
)->s
;
93 "%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
94 cpre
, msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
, csuf
);
98 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
])
105 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
106 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
107 (void)extract_date_from_from_(hline
, hlen
, date
);
113 _print_head(size_t yetprinted
, int msgno
, FILE *f
, bool_t threaded
)
115 char attrlist
[30], *cp
;
118 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
119 size_t i
= strlen(cp
);
120 if (UICMP(32, i
, >, sizeof attrlist
- 1))
121 i
= (int)sizeof attrlist
- 1;
122 memcpy(attrlist
, cp
, i
);
123 } else if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) ||
124 getenv("SYSV3") != NULL
) {
125 char const bsdattr
[] = "NU *HMFAT+-$";
126 memcpy(attrlist
, bsdattr
, sizeof bsdattr
- 1);
128 char const pattr
[] = "NUROSPMFAT+-$";
129 memcpy(attrlist
, pattr
, sizeof pattr
- 1);
132 if ((fmt
= ok_vlook(headline
)) == NULL
) {
133 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
134 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
135 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
138 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
142 __hprf(size_t yetprinted
, char const *fmt
, int msgno
, FILE *f
, bool_t threaded
,
143 char const *attrlist
)
145 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
146 char const *datefmt
, *date
, *name
, *fp
;
147 int B
, c
, i
, n
, s
, wleft
, subjlen
, isto
= 0, isaddr
= 0;
148 struct message
*mp
= &message
[msgno
- 1];
149 time_t datet
= mp
->m_time
;
152 if ((datefmt
= ok_vlook(datefield
)) != NULL
) {
153 fp
= hfield1("date", mp
);/* TODO use m_date field! */
159 date
= fakedate(datet
);
160 fp
= ok_vlook(datefield_markout_older
);
161 i
= (*datefmt
!= '\0');
163 i
|= (*fp
!= '\0') ? 2 | 4 : 2;
164 /* May we strftime(3)? */
166 memcpy(&time_current
.tc_local
, localtime(&datet
),
167 sizeof time_current
.tc_local
);
169 /* TODO *datefield-markout-older* we accept
170 * TODO one day in the future, should be UTC
171 * TODO offset only? and Stephen Isard had
172 * TODO one week once he proposed the patch! */
173 (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
174 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
175 (datet
+ _6M
< time_current
.tc_time
))) {
177 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
178 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
179 memcpy(datebuf
+ 4, date
+ 4, 7);
180 datebuf
[4 + 7] = ' ';
181 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
182 datebuf
[4 + 7 + 1 + 4] = '\0';
185 } else if ((i
& 1) == 0)
187 } else if (datet
== (time_t)0 && (mp
->m_flag
& MNOFROM
) == 0) {
188 /* TODO eliminate this path, query the FROM_ date in setptr(),
189 * TODO all other codepaths do so by themselves ALREADY ?????
190 * TODO assert(mp->m_time != 0);, then
191 * TODO ALSO changes behaviour of markout-non-current */
192 _parse_from_(mp
, datebuf
);
196 date
= fakedate(datet
);
201 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
202 if ((cp
= hfield1("to", mp
)) != NULL
) {
212 if (ok_blook(showname
))
213 name
= realname(name
);
215 name
= prstr(skin(name
));
221 /* Detect the width of the non-format characters in *headline*;
222 * like that we can simply use putc() in the next loop, since we have
223 * already calculated their column widths (TODO it's sick) */
227 for (fp
= fmt
; *fp
; ++fp
) {
231 } else if (*fp
== '+')
233 if (digitchar(*fp
)) {
236 n
= 10*n
+ *fp
- '0';
237 while (++fp
, digitchar(*fp
));
245 if (mb_cur_max
> 1) {
247 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) < 0)
249 else if ((n
= wcwidth(wc
)) < 0)
261 /* Walk *headline*, producing output */
262 for (fp
= fmt
; *fp
; ++fp
) {
263 if ((c
= *fp
& 0xFF) == '%') {
270 } else if (*fp
== '+')
272 if (digitchar(*fp
)) {
274 n
= 10*n
+ *fp
- '0';
275 while (++fp
, digitchar(*fp
));
281 switch ((c
= *fp
& 0xFF)) {
290 c
= _dispc(mp
, attrlist
);
292 if (UICMP(32, ABS(n
), >, wleft
))
293 n
= (n
< 0) ? -wleft
: wleft
;
294 n
= fprintf(f
, "%*c", n
, c
);
295 wleft
= (n
>= 0) ? wleft
- n
: 0;
301 for (i
=msgCount
; i
>999; i
/=10)
304 if (UICMP(32, ABS(n
), >, wleft
))
305 n
= (n
< 0) ? -wleft
: wleft
;
306 n
= fprintf(f
, "%*d", n
, msgno
);
307 wleft
= (n
>= 0) ? wleft
- n
: 0;
318 n
= (n
< 0) ? -wleft
: wleft
;
320 if (isto
) /* XXX tr()! */
322 n
= fprintf(f
, "%s%s", (isto
? "To " : ""),
323 colalign(name
, i
, n
, &wleft
));
330 if (datefmt
!= NULL
) {
331 i
= strftime(datebuf
, sizeof datebuf
,
333 &time_current
.tc_local
);
337 fprintf(stderr
, tr(174,
338 "Ignored date format, "
342 (ul_it
)sizeof datebuf
);
347 if (UICMP(32, ABS(n
), >, wleft
))
348 n
= (n
< 0) ? -wleft
: wleft
;
349 n
= fprintf(f
, "%*.*s", n
, n
, date
);
350 wleft
= (n
>= 0) ? wleft
- n
: 0;
355 if (UICMP(32, ABS(n
), >, wleft
))
356 n
= (n
< 0) ? -wleft
: wleft
;
358 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
359 wleft
= (n
>= 0) ? wleft
- n
: 0;
370 if (UICMP(32, ABS(n
), >, wleft
))
371 n
= (n
< 0) ? -wleft
: wleft
;
372 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
373 wleft
= (n
>= 0) ? wleft
- n
: 0;
377 n
= __putindent(f
, mp
, MIN(wleft
,
379 wleft
= (n
>= 0) ? wleft
- n
: 0;
392 if (UICMP(32, ABS(n
), >, subjlen
))
393 n
= (n
< 0) ? -subjlen
: subjlen
;
395 n
-= (n
< 0) ? -2 : 2;
398 if (subjline
== NULL
)
399 subjline
= __subject(mp
, threaded
,
401 if (subjline
== (char*)-1) {
402 n
= fprintf(f
, "%*s", n
, "");
403 wleft
= (n
>= 0) ? wleft
-n
: 0;
405 n
= fprintf(f
, (B
? "\"%s\"" : "%s"),
406 colalign(subjline
, ABS(n
), n
,
416 if (UICMP(32, ABS(n
), >, wleft
))
417 n
= (n
< 0) ? -wleft
: wleft
;
418 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
419 wleft
= (n
>= 0) ? wleft
- n
: 0;
428 if (UICMP(32, ABS(n
), >, wleft
))
429 n
= (n
< 0) ? -wleft
: wleft
;
430 n
= fprintf(f
, "%*u", n
,
431 threaded
== 1 ? mp
->m_level
: 0);
432 wleft
= (n
>= 0) ? wleft
- n
: 0;
438 for (i
=msgCount
; i
>999; i
/=10)
441 if (UICMP(32, ABS(n
), >, wleft
))
442 n
= (n
< 0) ? -wleft
: wleft
;
443 n
= fprintf(f
, "%*ld", n
,
444 threaded
? mp
->m_threadpos
: msgno
);
445 wleft
= (n
>= 0) ? wleft
- n
: 0;
451 if (UICMP(32, ABS(n
), >, wleft
))
452 n
= (n
< 0) ? -wleft
: wleft
;
454 snprintf(buf
, sizeof buf
, "%u.%u",
455 (mp
->m_spamscore
>> 8),
456 (mp
->m_spamscore
& 0xFF));
457 n
= fprintf(f
, "%*s", n
, buf
);
458 wleft
= (n
>= 0) ? wleft
- n
: 0;
473 if (subjline
!= NULL
&& subjline
!= (char*)-1)
478 __subject_trim(char *s
)
483 } const *pp
, ignored
[] = { /* TODO make ignore list configurable */
484 { 3, "re:" }, { 4, "fwd:" },
485 { 3, "aw:" }, { 5, "antw:" },
490 while (spacechar(*s
))
492 /* TODO While it is maybe ok not to MIME decode these, we
493 * TODO should skip =?..?= at the beginning? */
494 for (pp
= ignored
; pp
->len
> 0; ++pp
)
495 if (is_asccaseprefix(pp
->dat
, s
)) {
505 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
507 /* XXX NOTE: because of efficiency reasons we simply ignore any encoded
508 * XXX parts and use ASCII case-insensitive comparison */
511 char *rv
= (char*)-1, *ms
, *mso
, *os
;
513 if ((ms
= hfield1("subject", mp
)) == NULL
)
516 if (!threaded
|| mp
->m_level
== 0)
519 /* In a display thread - check wether this message uses the same
520 * Subject: as it's parent or elder neighbour, suppress printing it if
521 * this is the case. To extend this a bit, ignore any leading Re: or
522 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
523 mso
= __subject_trim(ms
);
524 for (xmp
= mp
; (xmp
= prev_in_thread(xmp
)) != NULL
&& yetprinted
-- > 0;)
525 if (visible(xmp
) && (os
= hfield1("subject", xmp
)) != NULL
&&
526 asccasecmp(mso
, __subject_trim(os
)) == 0)
531 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
538 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
541 int *us
, indlvl
, indw
, i
, important
= MNEW
|MFLAGGED
;
544 if (mp
->m_level
== 0 || maxwidth
== 0)
546 cs
= ac_alloc(mp
->m_level
);
547 us
= ac_alloc(mp
->m_level
* sizeof *us
);
550 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
551 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
552 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
554 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
557 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
558 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
560 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
565 for (i
= mp
->m_level
- 2; i
>= 0; i
--) {
567 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
573 mq
->m_parent
->m_flag
&important
)
586 for (indlvl
= indw
= 0; (uc_it
)indlvl
< mp
->m_level
&&
587 indw
< maxwidth
; ++indlvl
) {
588 if (indw
< maxwidth
- 1)
589 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0377, fp
);
591 indw
+= (int)putuc(0x21B8, '^', fp
);
593 indw
+= /*putuc(0x261E, fp)*/putc('>', fp
) != EOF
;
601 ccmdnotsupp(void *v
) /* TODO -> lex.c */
604 fprintf(stderr
, tr(10, "The requested feature is not compiled in\n"));
612 int *msgvec
= v
, g
, k
, n
, mesg
, size
, lastg
= 1;
613 struct message
*mp
, *mq
, *lastmq
= NULL
;
614 enum mflag fl
= MNEW
|MFLAGGED
;
616 time_current_update(&time_current
, FAL0
);
620 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
629 if (mb
.mb_threaded
== 0) {
632 for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
640 if ((n
> 0 && mp
== &message
[n
-1]) ||
641 (n
== 0 && g
== k
) ||
642 (n
== -2 && g
== k
+ size
&&
645 (mp
->m_flag
& fl
) != 0))
649 if (lastmq
&& (n
==-2 || (n
==-1 && mp
== &message
[msgCount
]))) {
655 mesg
= mp
- &message
[0];
656 if (dot
!= &message
[n
-1]) {
657 for (mq
= mp
; mq
< &message
[msgCount
]; mq
++)
664 if (mb
.mb_type
== MB_IMAP
)
665 imap_getheaders(mesg
+1, mesg
+ size
);
668 for (; mp
< &message
[msgCount
]; mp
++) {
672 if (UICMP(32, flag
++, >=, size
))
674 _print_head(0, mesg
, stdout
, 0);
678 } else { /* threaded */
681 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
682 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
683 mp
== &message
[n
-1])) {
690 if ((n
> 0 && mp
== &message
[n
-1]) ||
691 (n
== 0 && g
== k
) ||
692 (n
== -2 && g
== k
+ size
&&
695 (mp
->m_flag
& fl
) != 0))
699 if (lastmq
&& (n
==-2 || (n
==-1 && mp
==&message
[msgCount
]))) {
705 if (dot
!= &message
[n
-1]) {
706 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
707 if (visible(mq
) && mq
->m_collapsed
<= 0) {
714 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
715 mp
== &message
[n
-1])) {
716 if (UICMP(32, flag
++, >=, size
))
718 _print_head(flag
- 1, mp
- &message
[0] + 1,
719 stdout
, mb
.mb_threaded
);
722 mp
= next_in_thread(mp
);
727 printf(tr(6, "No more mail.\n"));
732 * Scroll to the next/previous screen
737 return scroll1(v
, 0);
743 return scroll1(v
, 1);
747 scroll1(char *arg
, int onlynew
)
752 cur
[0] = onlynew
? -1 : 0;
755 case '1': case '2': case '3': case '4': case '5':
756 case '6': case '7': case '8': case '9': case '0':
763 screen
= msgCount
/ size
;
769 screen
+= atoi(arg
+ 1);
771 if (screen
* size
> msgCount
) {
772 screen
= msgCount
/ size
;
773 printf(tr(7, "On last screenful of messages\n"));
781 screen
-= atoi(arg
+ 1);
784 printf(tr(8, "On first screenful of messages\n"));
791 printf(tr(9, "Unrecognized scrolling command \"%s\"\n"), arg
);
794 return(headers(cur
));
798 * Compute screen size.
806 if ((cp
= ok_vlook(screen
)) != NULL
&& (s
= atoi(cp
)) > 0)
808 return scrnheight
- 4;
811 static sigjmp_buf _cmd1_pipejmp
;
815 _cmd1_onpipe(int signo
)
818 siglongjmp(_cmd1_pipejmp
, 1);
822 * Print out the headlines for each message
823 * in the passed message list.
828 int *msgvec
= v
, *ip
, n
;
830 FILE *volatile obuf
= stdout
;
832 time_current_update(&time_current
, FAL0
);
834 /* TODO unfixable memory leaks still */
835 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
836 for (n
= 0, ip
= msgvec
; *ip
; ip
++)
838 if (n
> (*cp
== '\0' ? screensize() : atoi((char*)cp
)) + 3) {
840 if (sigsetjmp(_cmd1_pipejmp
, 1))
843 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
848 safe_signal(SIGPIPE
, _cmd1_onpipe
);
851 for (n
= 0, ip
= msgvec
; *ip
!= 0; ip
++)
852 _print_head((size_t)n
++, *ip
, obuf
, mb
.mb_threaded
);
854 setdot(&message
[*ip
- 1]);
856 if (obuf
!= stdout
) {
857 safe_signal(SIGPIPE
, SIG_IGN
);
859 safe_signal(SIGPIPE
, dflpipe
);
865 _dispc(struct message
*mp
, const char *a
)
872 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MREAD
)
874 if ((mp
->m_flag
& (MREAD
|MNEW
)) == (MREAD
|MNEW
))
876 if (mp
->m_flag
& MANSWERED
)
878 if (mp
->m_flag
& MDRAFTED
)
880 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
882 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
884 if (mp
->m_flag
& MSPAM
)
886 if (mp
->m_flag
& MSAVED
)
888 if (mp
->m_flag
& MPRESERVE
)
890 if (mp
->m_flag
& (MBOX
|MBOXED
))
892 if (mp
->m_flag
& MFLAGGED
)
894 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
896 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
902 print_headers(size_t bottom
, size_t topx
)
907 if (mb
.mb_type
== MB_IMAP
)
908 imap_getheaders(bottom
, topx
);
910 time_current_update(&time_current
, FAL0
);
912 for (printed
= 0; bottom
<= topx
; ++bottom
)
913 if (visible(&message
[bottom
- 1]))
914 _print_head(printed
++, bottom
, stdout
, 0);
918 * Print out the value of dot.
925 printf("%d\n", (int)(dot
- &message
[0] + 1));
930 * Type out the messages requested.
932 static sigjmp_buf pipestop
;
939 siglongjmp(pipestop
, 1);
943 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
944 bool_t dodecode
, char *cmd
, off_t
*tstats
)
946 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
947 ? SEND_MBOX
: dodecode
949 ? SEND_TODISP
: SEND_TODISP_ALL
);
950 bool_t
const formfeed
= (dopipe
&& ok_blook(page
));
955 FILE * volatile obuf
;
958 if (sigsetjmp(pipestop
, 1))
961 if ((cp
= ok_vlook(SHELL
)) == NULL
)
963 if ((obuf
= Popen(cmd
, "w", cp
, 1)) == NULL
) {
967 safe_signal(SIGPIPE
, brokpipe
);
968 } else if ((options
& OPT_TTYOUT
) &&
969 (dopage
|| (cp
= ok_vlook(crt
)) != NULL
)) {
970 char const *pager
= NULL
;
973 for (ip
= msgvec
; *ip
&&
974 PTRCMP(ip
- msgvec
, <, msgCount
);
976 if (!(message
[*ip
- 1].m_have
& HAVE_BODY
)) {
977 if ((get_body(&message
[*ip
- 1])) !=
981 nlines
+= message
[*ip
- 1].m_lines
;
984 if (dopage
|| UICMP(z
, nlines
, >,
985 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
988 if ((cp
= getenv("LESS")) == NULL
) /* XXX not here! */
989 setenv("LESS", "FRXi", 0); /* XXX add env. */
991 obuf
= Popen(pager
, "w", NULL
, 1);
994 unsetenv("LESS"); /* XXX to Popen() etc.?!! */
1001 safe_signal(SIGPIPE
, brokpipe
);
1004 if (action
!= SEND_MBOX
)
1005 colour_table_create(pager
); /* (salloc()s!) */
1009 else if ((options
& OPT_TTYOUT
) && action
!= SEND_MBOX
)
1010 colour_table_create(NULL
); /* (salloc()s!) */
1013 /* This may jump, in which case srelax_rele() wouldn't be called, but
1014 * it shouldn't matter, because we -- then -- directly reenter the
1015 * lex.c:commands() loop, which sreset()s */
1017 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
1018 mp
= &message
[*ip
- 1];
1024 fprintf(obuf
, "\n");
1025 if (action
!= SEND_MBOX
)
1026 _show_msg_overview(obuf
, mp
, *ip
);
1028 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
1033 tstats
[0] += mstats
[0];
1034 tstats
[1] += mstats
[1];
1039 if (obuf
!= stdout
) {
1040 /* Ignore SIGPIPE so it can't cause a duplicate close */
1041 safe_signal(SIGPIPE
, SIG_IGN
);
1042 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
1044 safe_signal(SIGPIPE
, dflpipe
);
1050 * Pipe the messages requested.
1053 pipe1(char *str
, int doign
)
1061 msgvec
= (int *)salloc((msgCount
+ 2) * sizeof *msgvec
);
1062 if ((cmd
= laststring(str
, &f
, 1)) == NULL
) {
1063 cmd
= ok_vlook(cmd
);
1064 if (cmd
== NULL
|| *cmd
== '\0') {
1065 fputs(tr(16, "variable cmd not set\n"), stderr
);
1070 *msgvec
= first(0, MMNORM
);
1074 puts(tr(18, "No messages to pipe."));
1078 } else if (getmsglist(str
, msgvec
, 0) < 0)
1083 printf("No applicable messages.\n");
1086 printf(tr(268, "Pipe to: \"%s\"\n"), cmd
);
1087 stats
[0] = stats
[1] = 0;
1088 if ((ret
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
1089 printf("\"%s\" ", cmd
);
1091 printf("%lu", (long)stats
[0]);
1093 printf(tr(27, "binary"));
1094 printf("/%lu\n", (long)stats
[1]);
1100 * Paginate messages, honor ignored fields.
1107 return _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1111 * Paginate messages, even printing ignored fields.
1118 return _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1122 * Type out messages, honor ignored fields.
1129 return _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1133 * Type out messages, even printing ignored fields.
1140 return _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1144 * Show MIME-encoded message text, including all fields.
1151 return _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1155 * Pipe messages, honor ignored fields.
1161 return(pipe1(str
, 1));
1164 * Pipe messages, not respecting ignored fields.
1170 return(pipe1(str
, 0));
1174 * Print the top so many lines of each desired message.
1175 * The number of lines is taken from the variable "toplines"
1176 * and defaults to 5.
1181 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1183 char *cp
, *linebuf
= NULL
;
1184 size_t linesize
= 0;
1188 cp
= ok_vlook(toplines
);
1191 if (topl
< 0 || topl
> 10000)
1196 if (options
& OPT_TTYOUT
)
1197 colour_table_create(NULL
); /* (salloc()s) */
1200 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
1201 mp
= &message
[*ip
- 1];
1204 did_print_dot
= TRU1
;
1207 _show_msg_overview(stdout
, mp
, *ip
);
1208 if (mp
->m_flag
& MNOFROM
)
1209 /* XXX top(): coloured output? */
1210 printf("From %s %s\n", fakefrom(mp
),
1211 fakedate(mp
->m_time
));
1212 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1217 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
);
1219 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1223 for (cp
= linebuf
; *cp
&& blankchar(*cp
); ++cp
)
1225 empty_last
= (*cp
== '\0');
1229 if (linebuf
!= NULL
)
1235 * Touch all the given messages so that they will
1244 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1245 setdot(&message
[*ip
-1]);
1246 dot
->m_flag
|= MTOUCH
;
1247 dot
->m_flag
&= ~MPRESERVE
;
1249 * POSIX interpretation necessary.
1251 did_print_dot
= TRU1
;
1257 * Make sure all passed messages get mboxed.
1265 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1266 setdot(&message
[*ip
-1]);
1267 dot
->m_flag
|= MTOUCH
|MBOX
;
1268 dot
->m_flag
&= ~MPRESERVE
;
1270 * POSIX interpretation necessary.
1272 did_print_dot
= TRU1
;
1278 * List the folders the user currently has.
1283 char dirname
[MAXPATHLEN
], *name
, **argv
= v
;
1287 name
= expand(*argv
);
1290 } else if (! getfold(dirname
, sizeof dirname
)) {
1291 fprintf(stderr
, tr(20, "No value set for \"folder\"\n"));
1296 if (which_protocol(name
) == PROTO_IMAP
) {
1298 imap_folders(name
, *argv
== NULL
);
1300 return ccmdnotsupp(NULL
);
1303 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1305 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);